Magento – Fix ‘Load by Attribute SKU’ Not Working Sometimes

modelproductsku

For Loading product by sku i'm using following function.
For some skus its working fine where as for some sku's not working.And these sku products existed in back end.

$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

Can you help anyone?

Best Answer

If neither of the following are working.

  1. Mage::getModel('catalog/product')->load($sku, 'sku');
  2. Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

Then you could always use the resource model, Mage_Catalog_Model_Resource_Product, to get the product id via the function getIdBySku and then simply do a normal load.

Related Topic