I am working on product collection. I am using

$product = $productModel->load(42);

I have array of products like :

$productArray = array('1','15','25','35','42');

I want to pass this array in load but it is not working and giving error. How we can multiple entity ids into load for getting all details once.

  • Hello! Why don't you just use a foreach on $productArray and load each one of those ID's separately and get whatever information you want to get. – user41363 Sep 15 '16 at 16:12

You can get like that:

$productArray = array('1','15','25','35','42');

Try to use addAttributeToSelect in the query and check:

$product_ids = array('1','15','25','35','42');
$collection = Mage::getModel('catalog/product')
    ->addAttributeToFilter('entity_id', array('in' => $product_ids));
  • But i am not getting details of product like Name , barcode etc after print_r($collection->getData()). – Mathew Nov 4 '15 at 11:00
  • I want to load multiple products details once. – Mathew Nov 4 '15 at 11:02
  • you have to load the product to get the data – Qaisar Satti Nov 4 '15 at 11:05
  • Try : $productArray = array('1','15','25','35','42'); $collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToFilter('entity_id', array('in' => $productArray)); foreach($collection as $product) { $product = $product->load($product->getId()); } – Abdul Nov 4 '15 at 11:10
  • 1
    @Abdul i dont want to use load in foreach loop. – Mathew Nov 4 '15 at 11:15

Please try:

$filters = array(

$collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('entity_id', array('in' => $productArray));

foreach ($filters as $field) {

foreach ($collection as $product) {
    echo $product->getSku();
$collection = Mage::getModel('catalog/product')->getCollection();

// select all attributes

// using IN statement,
// i.e. selecting only those items whose ID fall in the given array
$productArray = ['1', '15', '25', '35', '42'];
$collection->addAttributeToFilter('id', ['in' => $productArray]);

foreach ($collection as $eachproduct) {
    $product = $eachproduct->load($eachproduct->getId());

If you want to get list of products of a particular products ids then you need to call product collection and filter the collection by array of ids.

Product Collection:

$collection = Mage::getModel('catalog/product')->getCollection();

For filter by array of product ids use function addIdFilter($productArray):


Then using loop get each product:

foreach ($collection as $eachproduct) {
    echo $eachproduct->getName() . '-' . $eachproduct->getId() . '<br/>';
  • I am only able to get name and price using this. I want also bar code and description also. – Mathew Nov 4 '15 at 11:27

Try to use addAttributeToSelect in the query and check:

$product_ids = array('94', '95', '96');
$collections = Mage::getModel('catalog/product')
    ->addAttributeToFilter('entity_id', array('in' => $product_ids));

foreach ($collections as $collection) {
    echo $collection->getName();
    echo '<br/>';

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.