Home » Magento20 August 2013

Magento: Load multiple products at once

Suppose, you have ID of some products and you want to load them at once in Magento, then here is a solution:-

Suppose, you have 5 products ID: 5, 22, 45, 75, 88

You can store them in one array:

Then, you can use MySQL’s IN() clause for loading multiple product ids:

Here is the complete code:-

Similarly, if you have product SKU instead of product ID, then also you can use the same code for loading the products.

Here is the code:-

Hope it helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Aman

    Nice…keep posting….

  • navin

    hii friends i need your help pls instructs me how do i implement this code step by step like in which folder i have to put this code

  • navin

    hii friends i need your help pls instructs me how do i implement this code step by step like in which folder i have to put this code

    $productIds = array(5, 22, 45, 75, 88);
    $attributes = Mage::getSingleton(‘catalog/config’)->getProductAttributes();
    $collection = Mage::getModel(‘catalog/product’)
    ->getCollection()
    ->addAttributeToFilter(‘entity_id’, array(‘in’ => $productIds))
    ->addAttributeToSelect($attributes);

  • PHP Guru

    The more I get into Magento, the more often your blog appears in my search results ;-) Keep it up! Very helpful.