【发布时间】:2011-08-09 06:32:32
【问题描述】:
我一直在为 Magento(1.8.0.0 版)开发一个自定义模块,该模块显示某个产品的相关产品列表。
为了实现这一点,我通过覆盖 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 的方法,但由于某种原因我无法让它工作。
有什么帮助吗?
基本上,我希望为自定义集合中的产品提供分层导航。
谢谢,
【问题讨论】:
标签: collections magento navigation product layered