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!
Hello check below code
$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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.