【问题标题】:about display messages in magento 1.7.0.2关于 magento 1.7.0.2 中的显示消息
【发布时间】:2013-05-25 07:06:44
【问题描述】:

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

app/design/frontend/default/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();
    }
}

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

【问题讨论】:

    标签: magento magento-1.7


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多