0

I need to get a collection in magento by multiple categories but I am not getting any product when I add more categories.

$products = Mage::getModel('catalog/category')->load(7,8)
                ->getProductCollection()
                ->addAttributeToSelect('*') // add all attributes - optional
                ->addAttributeToFilter('status', 1) // enabled
                ->addAttributeToFilter('visibility', 4) //visibility in catalog,search
                ->setOrder('price', 'ASC'); //sets the order by price
         $this->setProductCollection($products);
        return $products;
1

Please try the following to retrieve products from multiple categories:

$_testproductCollection = Mage::getResourceModel('catalog/product_collection')
    ->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
    ->addAttributeToFilter('category_id', array('in' => array('your_cat1','your_cat2',....)))
    ->addAttributeToSelect('*');
$_testproductCollection->load();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.