This looks very simple but I have been pulling my hair on this for the last hour. I just want to load products data from a PHP array that looks like this:
array
0 =>
array
'sku' => string '1HC220'
'qty' => string '2'
2 =>
array
'sku' => string '4LANT'
'qty' => string '2'
The piece of code:
foreach ($products_arr as $row) :
$sku = trim($row['sku']);
$product = Mage::getModel('catalog/product')->setStore($store_id)
->getCollection()
->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id = entity_id',
'{{table}}.stock_id = 1',
'left'
)
->addFieldToFilter('sku', array('eq' => $sku))
->getFirstItem()
;
(...)
endforeach;
But the first product in the array always returns NULL. If I var_dump $products_arr
I have X products, but in the loop the first is never returned.
If I load the product individually, it is loading, but not as a first row of the array.
I know I am missing something, but can't figure out what.
$products_arr
looks? Print the result here'4LANT'
as the first in the array, this will be the one not loading. It really is the first row of the array that is 'missing'.