How to get all data about the product having id including stock status and quantity?


if you load the product like $product = Mage::getModel('catalog/product')->load($id);, to get the qty available for the product, you can do $qty = $product->getStockItem()->getQty();

and to check if the product is in stock:

   $isProductInStatus = $product->isInStock();

In block:

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

the above has nothing to do with collection and instead load function just set the product model data. As part of the product model load process, the stock item model is loaded and this is why we can query qty like I show above

  • Thank you, what about quantities ? As in collection i can join table and get anything i need how to do it in case of a single product ? Same way ?
    – Rob D. A.
    Jul 16 '19 at 16:01
  • I think this will do the job. By any chance do you know how to check if the "product stock is managed" on or off ? is it ('catalog/product') model as well ? How to get it ?
    – Rob D. A.
    Jul 17 '19 at 8:01
  • print_r($product->getStockItem()->getData()) will show you many stock info you can get, hoepfully it should help Jul 17 '19 at 11:11

You asked about fetching stock as part of collection

$collection = Mage::getModel('catalog/product')

foreach ($collection as $product) {
    echo $product->getStockItem()->getIsInStock();

You can also do it this way too. Which might be more efficient. Loading large collections or products within collections is expensive in terms of resource. This has a smaller footprint.

$stockItem = Mage::getModel('cataloginventory/stock_item')
  • No, what am i asking is how to het data having product id ... all data including stock state and if stock is configured to be managed or not etc
    – Rob D. A.
    Jul 16 '19 at 20:21
  • Original answer then. Zend_Debug/var_dump $product->getStockItem() Jul 16 '19 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.