1

I want to get the remain quantity of a given product. I'm going to create a report in admin panel which highlights the remaining quantity and re-order level quantity against each product. I was able to get the re-order level quantity by inventory details. And I want to get remain quantity for a given product. Please any suggestions?

2 Answers 2

10

Try

<?php 
$num= Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); 
echo "Remaining products: ".$num;
?>
2
  • 1
    Hi, I tried this. But this returns the entire quantity for the given product. Not the remaining quantity after completing orders.
    – Sukeshini
    Commented Mar 11, 2013 at 4:40
  • 1
    go to system>config>inventory tab and check out Decrease Stock When Order is Placed is yes or not.
    – Vishnu R
    Commented Mar 11, 2013 at 4:46
1

If you are looking for the remaining quantity for products in the cart, you need to take into account configurable vs simple products:

<?php
$quote = Mage::getModel('checkout/cart')->getQuote();
$items = $quote->getAllVisibleItems();

foreach ($items as $item) {
   $cart_product = $item->getProduct();

   if ($option = $item->getOptionByCode('simple_product')) {
      $cart_simple_product = $option->getProduct();
   } else {
      $cart_simple_product = $this->getProduct();
   }

   $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($cart_simple_product);
   $max_available_quantity = (int)$stock->getQty();
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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