How to Get a Product by SKU in Magento?

Get a Product by SKU in Magento.

In Magento usually we upload product by its ID

$product = Mage::getModel('catalog/product')->load($product_id);

But when need to get product by its attribute SKU. To do this, you can simply use following code and get Magento products details completely there.

$productsku = 'product_sku';
$product = Mage::getModel('catalog/product')->load($productsku, 'sku');

There is also other method of loadByAttribute() for getting products by SKU which is shown below

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

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *