Magento:将产品从特定类别加载到产品页面

时间:2015-04-28 13:47:17

标签: magento magento-1.7

我有一个自定义菜单,其中包含特定类别的产品(类别ID = 3)。在我的菜单中有一个块:

{{block type="catalog/product_list" name="product_list" mode="grid" template="catalog/product/category_list_1.phtml"}}

我通常可以在主站点和类别内看到产品,但在产品页面上,getBlockTemplateProcessor()不会返回任何数据。

文件中的代码与list.phtml相同,我只做了一些html修改,位于: \目录\产品\ list.phtml

为什么我的代码无法呈现?问题是文件无法从产品网站找到吗? 为什么一个类别网站和产品网站都不好?

1 个答案:

答案 0 :(得分:0)

我建议您使用自己的块扩展产品列表块,以便您可以正确设置产品集合,例如:

class YourNamespace_YourModule_Block_List extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) {
            $collection = Mage::getResourceModel('catalog/product_collection');
            Mage::getModel('catalog/layer')->prepareProductCollection($collection);

            $prodIdArray = array(1,2,3,4,5);

            $collection->addAttributeToFilter('entity_id', $prodIdArray);
            $collection->addStoreFilter();
            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }
}

您可以过滤以添加或删除列表中的任何产品。

相关问题