Magento 1.7以块形式显示了来自两个类别的产品


Magento 1.7 show products from 2 categories in block

我想创建一个块来显示来自2个(或更多)类别的产品。我试过几种方法,但都不起作用。

我是如何尝试的:

/app/code/local/Mage/Catalog/Block/Product/Fulllist.php(与List.php相同,但更改了_getProductCollection()函数:)

protected function _getProductCollection()
{
$_productCollection = Mage::getModel('catalog/product')
    ->getCollection()
    ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('category_id', array(
        array('finset' => '30'),
        array('finset' => '32'))
    )
        ->addAttributeToSort('created_at', 'desc');
        return $_productCollection;
}

然后,在我尝试使用的一个CMS页面上:

{{block type="catalog/product_fulllist" template="catalog/product/list.phtml"}}

但这似乎不起作用,佩奇很清楚。我缺了什么零件吗?或者有更简单的方法吗?

问候!

你好,检查下面的代码

$collection = Mage::getModel('catalog/product')->getCollection(); 
$collection->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left');
$collection->addAttributeToFilter('category_id', array('in' => array('finset'=>'30,31')));
$collection->addAttributeToSort('created_at', 'desc');
$collection->addAttributeToSelect('*');
return $collection;