I want to load a set of products, given as an array:

$productSkus = array('sku-1','sku-2');

foreach($productSkus as $productSku) :
    $productId = Mage::getModel("catalog/product")->getIdBySku($productSku);
    $_product = Mage::getModel('catalog/product')->load($productId);
    $productName = $_product->getName();
    echo $productName;

As I am a rookie I'm wondering if this set is not a lot of database requests. Is there a way to do the loading before the loop at once?

2 Answers 2


Use addAttributeToFilter

$productSkus = array('sku-1','sku-2');
       ->addAttributeToFilter('sku', array('in' => $productSkus))
foreach($productCollection as $_product)
     echo $_product->getName();
  • I get a Parse error: syntax error, unexpected '*' in Jun 17, 2015 at 10:09
  • that was a type-error. i missed the single quotes. check the updated answer Jun 17, 2015 at 10:12

In this case you can use product collection and filter them by sku using in clause.

      -->addAttributeToFilter('sku', array(
        'in' => $productSkus,
     ->addAttributeToSelect('name') // for get Name;

foreach($Collection as $eachproduct) :
echo $eachproduct>getName();

For getting more details on filter see here


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.