How to get product availabilty with product id in magento?

is it possible to get product availability by passing product id to magento system? I will post in this if i find the answer..

Thanks, Balan

-------------Problems Reply------------

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')

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')

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

For some types of products zero qty of product doesn't mean it's out of stock. Then you can use

$stockStatus = Mage::getModel('cataloginventory/stock_item')

For collection one of the ways is

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('status', 1)
->addFieldToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)

if (! Mage::helper('cataloginventory')->isShowOutOfStock()) {

Magento 1.7

$product = Mage::getModel('catalog/product')->load($productId);
$qty = $product->getStockItem()->getQty();

Should work too

Category:magento Views:1 Time:2011-04-12
Tags: magento

Related post

Copyright (C), All Rights Reserved.

processed in 0.068 (s). 11 q(s)