关于在magento 1.7.0.2中显示消息

时间:2013-05-25 07:06:45

标签: magento magento-1.7

我在magento 1.7.0.2中添加了新模块,一切正常。点击添加到购物车无法显示成功消息,但我的购物车中的产品还可以。当我点击另一个页面时,会显示消息。< / p>

应用程序/设计/前端/默认/ F001 /布局/ printer.xml

<?xml version="1.0"?>
<layout>
    <default> 
        <reference name="right"> 
            <block type="printer/finder" name="product.finder" before="-" template="printer/finder.phtml" /> 
        </reference> 
    </default> 
    <printer_finder_result>
        <reference name="content">
            <block type="printer/finder_result" name="product.finder.result" template="printer/finder/result.phtml"/>
        </reference>
        <reference name="left">
            <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
        </reference>
    </printer_finder_result>
</layout>

应用程序/代码/本地/ HB /打印机/盒/搜索/ Result.php

class HB_Printer_Block_Finder_Result extends Mage_Catalog_Block_Product_Abstract
{

    public function __construct()
    {
        parent::__construct();

        $storeID = Mage::app()->getStore()->getId();
        $printerID = $this->getRequest()->getParam('modelId'); 
        $collection = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');

        $collection->getSelect()
                   ->joinInner(
                       array('e2' => 'printer_applicable_product'),
                       'e2.product_id = e.entity_id'
                   )
                   ->where('e2.printer_id = ?', $printerID)
                   ;

        $this->setProductCollection($collection);
    }

    protected function _prepareLayout()
    {
        parent::_prepareLayout();
        $toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', microtime())
            ->setCollection($this->getProductCollection());

        $pager = $this->getLayout()->createBlock('page/html_pager', microtime());
        $toolbar->setChild('product_list_toolbar_pager', $pager);

        $this->setChild('toolbar', $toolbar);
        $this->getProductCollection()->load();

        return $this;
    }

    public function getPagerHtml()
    {
        return $this->getChildHtml('toolbar');
    }
}

应用程序/代码/本地/ HB /打印机/控制器/ FinderController.php

class HB_Printer_FinderController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->_title($this->__('Products Finder'));     
        $this->loadLayout();     
        $this->renderLayout();

    }

    public function resultAction()
    {
        $this->_title($this->__('Printer Applicable Products'));
        $this->loadLayout();     
        $this->renderLayout();
    }
}

为什么不在当前页面显示消息。如何解决?

1 个答案:

答案 0 :(得分:1)

您应该通过Mage_Core_Controller_Varien_Action :: _ initLayoutMessages()

初始化所需的布局消息

示例:

public function resultAction()
{
    $this->_title($this->__('Printer Applicable Products'));
    $this
        ->loadLayout()
        ->_initLayoutMessages('checkout/session')
        ->_initLayoutMessages('catalog/session')
    $this->renderLayout();
}

您需要初始化包含所需消息的会话模型。

另请注意 printer / finder / result.phtml 应包含

$this->getMessagesBlock()->getGroupedHtml()