将分层导航块添加到自定义页面
-
16-10-2019 - |
题
在Magento中,分层导航块在“产品列表”页面中很好地工作。
该块如何成功复制到有自定义产品列表的自定义页面?
注意:只需将块添加到XML,然后称其为 getChildHtml('blockname')
不做任何技巧。
解决方案
基本上您要做的是 extend/overwrite
从 mage_catalog_block_product_list (List.php)
并重写 getProductCollection()
方法:
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
// Build collection and set it
$collection = "...";
$this->setProductCollection($collection);
}
return $this->_productCollection;
}
完成那完成的时候,我已经覆盖了 Mage_Catalog_Model_Layer
班级和 Mage_Catalog_Model_Category
并引入了一个新变量:
protected $_customProductCollection;
我已经覆盖了 getProductCollection()
在两个课程中,我在方法的开头中添加了此内容:
if(isset($this->_customProductCollection)){
return $this->_customProductCollection;
}
我也有一种让我设置的方法 "customProductCollection"
这两个课程内部。设置后,其余的数据 分层导航/类别 基于此集合。
查看最初的问题+答案 这里.
祝你好运 ;)