Magento – Show Inventory Levels on Product Pages

One of our client needed to display their actual quantity on hand inventory, rather that the normal ‘Availability-In Stock’. on product detail page. For this you need to look on this file.

app/design/frontend/YOURTEMPLATE/default/template/catalog/product/view/type/default.phtml

If you do not have the above in the directory then you should copy that from the base folder and put in custom template. Approach the below code :

<?php if ($_product->isAvailable()): ?>
<?php $quantity1 = intval(Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($_product)->getQty()); ?>
<div class=”add-to-box”>
<?php if($quantity1 > 0) { ?>
<p class=”availability in-stock”>
<?php echo $this->__(‘Qty on Hand:’) ?>
<?php echo $quantity1;?>
</span>
</p>
<?php } elseif($quantity1 == 0) { ?>
<p class=”availability in-stock”>
<?php echo $this->__(‘Qty on Hand:’) ?><br/><br/><span>
<?php foreach ($_product->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) {
$stock = intval(Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($simple)->getQty());
echo $simple->getName().” “.$simple->getSize().” have a stock of $stock”;
echo ‘<br/>’;
} ?></span>
</p>
<?php } ?>
</div>
<?php else: ?>
<p class=”availability out-of-stock”><?php echo $this->__(‘Availability:’) ?> <span><?php echo $this->__(‘Out of stock’) ?>