How to Track the Number of Products in Product Inventory in Magento


Track the number of products in your store by adding a stock quantity for each product separately in Magento development. I adjust the quantity automatically when customers complete purchases from your store.

Increase product quantity up to the no of products is in stock on the product details page.

Below the code get the product stock quantity for the item. Add this code above addtocart.phtml file.

The path are=> app/design/frontend/rwd/default/template/catalog/product/addtocart.phtml

$_product2 = $this->getProduct();
 $stockQty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product2);
 $stockQty2= $stockQty->getQty();

Now, add $stockQty2 in javascript document which use increase the quantity.

<script type=""text/javascript"">
	var stockQty2 =<?php echo $stockQty2;  ?> ;
    jQuery('.increment_qty').click(function() {
    	var oldVal = jQuery(this).parent().find(""input"").val();
	if ( parseFloat(oldVal) < stockQty2 ) {
      		if ( parseFloat(oldVal) >= 0 ) {		  
        	var newVal = parseFloat(oldVal) + 1;		


You can apply the code in Magento development. Please share your views in the comment section.


We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.