Magento: Get Product by SKU

Here is a quick code to get product information with SKU value.

Get product information by sku


// Get product by sku
$sku = "microsoftnatural";
$product = Mage::getModel('catalog/product')
			->loadByAttribute('sku', $sku);
// print product data
echo "<pre>"; print_r($product->getData()); echo "</pre>";

Get product id by sku


$productIdBySku = Mage::getModel('catalog/product')
					->getIdBySku('microsoftnatural');
					
echo $productIdBySku;

Hope it helps. Thanks.