0

I wanted to create a block that would display products from 2 (or more) categories. I've tried to do that in several ways but they don't work.

How I tried:

/app/code/local/Mage/Catalog/Block/Product/Fulllist.php (same as List.php with changed _getProductCollection() function:)

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;
}

Then, at one of CMS pages i tried to use:

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

But that doesn't seem to work, page is clear. Am I missing any part? Or is there an easier way to do that?

Greetings!

4

1 回答 1

0

你好检查下面的代码

$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;
于 2013-08-28T12:01:10.603 回答