0

我在 magento 1.7.0.2 中添加了新模块,一切正常。我单击添加到购物车无法显示成功消息,但产品在我的购物车中是正常的。当我单击另一个页面时,会出现消息。

应用程序/设计/前端/默认/f001/layout/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>

app/code/local/HB/Printer/Block/Finder/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');
    }
}

app/code/local/HB/Printer/controllers/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();
    }
}

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

4

1 回答 1

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()
于 2013-05-25T08:03:59.087 回答