In this tutorial I will show you how to get product stock information in Magento. It will help you to get stock information of any product like quantity (qty), minimum quantity (min_qty), stock availability (is_in_stock), minimum and maximum sale quantity (min_sale_qty and max_sale_qty), etc.
To get stock data first you need to load the product. Following are two different ways to load any product in Magento.
By Product ID:
$_productId = '123'; $_product = Mage::getModel('catalog/product')->load($_productId);
By Product SKU:
$sku = "ADFM002"; $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
Now get stock information of the loaded product as below:
$stockInfo = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
You can check the stock information as below:
echo " <pre>"; print_r($stockInfo->getData()); echo "</pre> ";
You may get individual field info like below:
echo $stockInfo->getQty(); echo $stockInfo->getMinQty(); echo $stockInfo->getMinSaleQty();
I hope this tutorial will help you.