0

How to load more then one category id

$categoryIds = array(957);
  $collection = Mage::getModel('catalog/category')->load($categoryIds)
->getProductCollection()
->addAttributeToSelect('*');
$collection->joinField(
                        'is_in_stock',
                        'cataloginventory/stock_item',
                        'is_in_stock',
                        'product_id=entity_id',
                        '{{table}}.stock_id=1',
                        'left'
                )
                ->addAttributeToFilter('is_in_stock', array('eq' => 0));
//->addAttributeToFilter('status',array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED))
  • why you do not use Magento products collection by multiple category id concept? – Amit Bera Mar 29 '16 at 12:41
  • No actually for some reason i used particular category only – Magento 2 Mar 29 '16 at 12:42
1

I would try a different approach. Rather than loading a lot of categories, you could load the product collection and then filter by categories

$products = Mage::getModel('catalog/product')->getCollection();
$products->joinField(
    'qty',
    'cataloginventory/stock_item',
    'qty',
    'product_id=entity_id',
    '{{table}}.stock_id=1',
    'left'
);

$products->joinField('category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
);

$products->addAttributeToFilter('category_id', array('in' => array(32,5)));

foreach ($products as $product) {

}
| improve this answer | |

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.