在Magento中,分层导航块在“产品列表”页面中很好地工作。

该块如何成功复制到有自定义产品列表的自定义页面?

注意:只需将块添加到XML,然后称其为 getChildHtml('blockname') 不做任何技巧。

有帮助吗?

解决方案

基本上您要做的是 extend/overwritemage_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" 这两个课程内部。设置后,其余的数据 分层导航/类别 基于此集合。

查看最初的问题+答案 这里.

祝你好运 ;)

许可以下: CC-BY-SA归因
scroll top