Get Product by SKU in Magento

how to get Product by SKU in Magento.

Here is a quick and easy code to get / load product by it’s SKU in magento. normally we load product by it’s ID. we Assuming product id to be ‘170’.

$your_product_id = '170';
$get_product = Mage::getModel('catalog/product')->load($your_product_id);

But, we can also pass product by it’s attributes, like SKU. Assuming product sku to be ‘onlinecode’.

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

There is also another way to load product by SKU. Assuming product sku to be ‘onlinecode’.

$your_sku = 'onlinecode';
$product_catalog = Mage::getModel('catalog/product');
$get_product_id = $product_catalog->getIdBySku($your_sku);
$get_product = Mage::getModel('catalog/product')->load($get_product_id);

Leave a Comment

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

  +  47  =  56

We accept paid advance and paid guest Posting on our Site : Contact US