我一直在为Magento(版本1.8.0.0)定制模块,该模块显示某个产品的相关产品列表。自定义产品集合上的Magento分层导航
为了达到这个目的,我创建了自己的模块,覆盖了Mage_Catalog_Block_Product_List
类。
基本上这里的工作原理是:
从控制器我赶上产品entity_id
和我的产品存储在注册表中,所以我可以用它我的自定义写入的块被称为list.php的
内下面是填充产品收集方法:
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$prod = Mage::registry('chosenproduct');
$this->_productCollection = $prod->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->addAttributeToFilter(array(array('attribute'=>'accessory_manufacturer','neq'=>false)))
->addAttributeToSort('position', 'asc')
->addStoreFilter()
->setPageSize(30)
->setCurPage(1);
;
$this->_addProductAttributesAndPrices($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_productCollection);
$this->setProductCollection($this->_productCollection);
}
return $this->_productCollection;
}
我还添加了我的自定义模块的布局.XML以下,以确保分层导航显示:
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
分层导航显示,但它似乎将所有产品作为集合,而不是我在上面添加的方法中使用的自定义集合。
我也知道,我可以用这个$layer = Mage::getSingleton('catalog/layer');
层类也有一个名为prepareProductCollection和setCollection方法,但由于某种原因,我无法得到它的工作得到了目录/层。
对此有何帮助?
基本上我想要在自定义集合中的产品的分层导航。
谢谢,
这是什么设置方法,你从哪里调用它? – easymoden00b 2015-02-17 20:54:39