我一直在爲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