Here is a quick code to get any product�s stock information 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.
First load the product. Product can be loaded in different ways. Here are the two different ways to load any product in Magento:-
1. Load product by product ID
First load the product. Product can be loaded in different ways. Here are the two different ways to load any product in Magento:-
1. Load product by product ID
$id = 52; $_product = Mage::getModel('catalog/product')->load($id);2. Load product by SKU
$sku = "microsoftnatural"; $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);Now, get stock information for the loaded product.
$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);You can check stock data in this way:-
echo "Or, you can print individually like this:-"; print_r($stock->getData()); echo "";
echo $stock->getQty(); echo $stock->getMinQty(); echo $stock->getMinSaleQty();
No comments:
Post a Comment