Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get product availability with product id in magento?

Tags:

magento

Is it possible to get product availability by passing a product ID to the Magento system?

like image 444
balanv Avatar asked Apr 12 '11 07:04

balanv


2 Answers

To fetch the quantity (in stock) for any given product

$model = Mage::getModel('catalog/product'); 
$_product = $model->load($product_id); 
$stocklevel = (int)Mage::getModel('cataloginventory/stock_item')
                ->loadByProduct($_product)->getQty();
like image 122
Peter Lindqvist Avatar answered Sep 30 '22 06:09

Peter Lindqvist


You can get stock info (Mage_CatalogInventory_Model_Stock_Item class) by product's ID without loading whole product data (at least in Magento 1.7)

$stockItem = Mage::getModel('cataloginventory/stock_item')
               ->loadByProduct($productId);

And then you can use getQty() and other methods on $stockItem object to get required info. You can find them in the source file for the class

like image 31
Anatoly A. Kazantsev Avatar answered Sep 30 '22 08:09

Anatoly A. Kazantsev