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);
$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);
$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’.
Assuming product sku
PHP
$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);
$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);
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);
$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);
$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’.
Assuming product sku
PHP
$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);
$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);
No comments:
Post a Comment