So I am trying to get the available inventory to show in the product info on the product list. So like it would have the price then Available inventory right below it. I was looking for solutions online but not of them seemed to work (whenever i tried an example it wouldn't show and product or would just show an error message).

I noticed that people were saying if you set 'Display products availability in stock in the frontend' in system->configuration->inventory to YES then it would displays an availability message indicating the product stock status. I have it set to yes, however it does not say if it is ever in stock, only if it is out of stock.

People were also saying that this was all programmed in /app/design/frontend/XXX/YYY/template/catalog/product/list.html. I looked in there and none of the code looks like it would do this. So if anyone has a way to display the Available Inventory it would be much appreciated.

Update: I found a code that used getQty() but it did not work (it printed 0 for every product).

Update: The answer below works but has decimal places. To remove those decimals I used round(). So the final code I used was:

$num= Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); 
$num = round($num);
echo "Remaining products: ".$num;
  • You can control if products with no stock are displayed or not. This is a setting in the adminhtml backend (somewhere). So stock availability can control a certain amount of output. You find this behavior hardencoded, partially in INNER JOINs on index tables but also with IF CLAUSES wihthin controller and template code. So probably it is not as easy/straight forward as one might think on first glance. Also take care with resources you find online: Often they are for specific cases and might not cover your case. But still read them as they contain hints and pointers. – hakre Jul 29 '15 at 19:30
  • With available inventory do you meant the numeric amount in the inventory? – hakre Jul 29 '15 at 19:35
  • Yes I wish to show the numeric amount. And I am aware of showing or not showing items out of stock. Thanks – Bryan Hill Jul 29 '15 at 19:55
  • Okay, were you able to locate the out of stock message you experienced in the front within your templates? There is some template logic over there IIRC because you can also control what availability means (e.g. not available if less than X or so). – hakre Jul 29 '15 at 19:58
  • Yeah I am able to display 'out of stock' if the product is out of stock. Its when the product is in stock I want it to say how many are left in stock. I am guessing the solution would include an api call to magento in catalog/product/list.phtml – Bryan Hill Jul 29 '15 at 20:03

To get the inventory of the product anywhere, try below code

    $num= Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); 
    echo "Remaining products: ".$num;

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.