Magento – Show Inventory Levels on Product Pages
Today I will show you how we can add Quantity on hand information on the product detail page.Normal Magento shows ‘Availability-In Stock’ by default. We need to change that Qty on hand like the below image
For this you need to do the below steps :
Go to app/design/frontend/base/default/template/catalog/product/view/type/default.phtml.
Get a copy of that file and move it to your custom theme, making sure to add folders as needed to maintain the correct path. Here is the code snippet for adding Quantity on Hand to your product pages.
Replace below code
<?php if ($_product--->isAvailable()): ?>
with
<?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:’) ?></p>
<?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>’; } ?>
</p>
<?php } ?>
</div>