I have been given a list of about 150 SKUs in a CSV and I need to get their product names.

I currently have the following code:


 $csv = file('Product - Sheet1.csv');
 $data= array();
 foreach($csv as $line){
     $data[] = str_getcsv($line);

 $products= array();
 foreach($data as $k => $entry){
     if ($k < 1) continue; // First row contains the CSV headers
     $products[$k]['sku'] = $entry[0];
     $model == Mage::getSingleton('catalog/product')->loadByAttribute('sku',$entry[0]);
     $products[$k]['title']= $model->getName();

If I do


I get a blank page, presumably because I'm loading the catalog/product model in the foreach loop.

How do I achieve the same solution but without overloading the system? I know loading models in a foreach is bad practice but I thought I could get by because its not on a production environment.

1 Answer 1


do one thing.read the csv and try to load all your 150 product skus in an array and use the following code to get the product names

$productSku = array('sku1','sku2');
$productModel = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name')->addAttributeToFilter('sku', array('in' => $productSku));
$productNames = $productModel->getColumnValues('name');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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