Present Quantity of Available Products

Submitted by Eric on Thu, 03/29/2018 - 21:17
Agrupado1

In this tutorial we will show you how many products are available for that product.
For simple products, there are a few ways to do this and I'll show you 2.

The first way would be to change the file app/design/frontend/base/default/template/catalog/product/view/type/default.phtml

Search for:

<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('In stock') ?></span></p>

Replace to:

<p class="availability in-stock"><?php echo $this->__('Availability: ') ?><?=(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?><?php echo $this->__(' em estoque.') ?></p>

It will look like this:
simples1

The second way would be to change the same file.

Search for:

<p class="availability in−stock">__('Availability:') ?> __('In stock') ?>

Just below the code add:

<div class="divider"></div>
<div class="inventory-qty">
 <!--inv-qty--><br />
 <?php<br />
 $__manStock = $_product->getStockItem()->getManageStock();<br />
 $__invAmt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();<br />
 if ($__manStock > 0)<br />
 {<br />
 echo $this->__("Somente $__invAmt disponiveis em estoque");<br />
 }<br />
?>
 </div>

It will look like this:
simples2

To change grouped files need to change some more codes, but nothing too complicated.
Let's edit the file: app/design/frontend/base/default/template/catalog/product/view/type/grouped.phtml

Search for:

<td class="a-center">
            <?php if ($_item->isSaleable()) : ?><br />
                <input name="super_group[<?php echo $_item->getId() ?>]" value="<?php echo $_item->getQty()*1 ?>" type="text" class="input-text qty" /><br />
            <?php else: ?><br />
                <?php echo $this->__('Out of stock.') ?><br />
            <?php endif; ?>
            </td>

Now enter above this code the following code:

<td class="a-center">
            <?php if($_product->isSaleable()): ?><br />
                <?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty()?><br />
            <?php else: ?><?php echo $this->__('Out of Stock') ?><?php endif; ?>
            </td>

Lastly, look for:

<thead>
<tr>
<th><?php echo $this->__('Product Name') ?></th>
<th class="a-right"><?php echo $this->__('Price') ?></th>
<p>            <?php if ($_product->isSaleable()): ?></p>
<th class="a-center"><?php echo $this->__('Qty') ?></th>
<p>            <?php endif; ?><br />
        </tr>
</thead>

And replace for:

<thead>
<tr>
<th><?php echo $this->__('Product Name') ?></th>
<th class="a-left"><?php echo $this->__('Price') ?></th>
<th class="a-right"><?php echo $this->__('Availability') ?></th>
<p>            <?php if ($_product->isSaleable()): ?></p>
<th class="a-center"><?php echo $this->__('Qty') ?></th>
<p>            <?php endif; ?><br />
        </tr>
</thead>

Okay, now the grouped products will look like this:
agrupado2

I hope you enjoyed the tutorial and leave your comments!


FacebookTwitterGoogle+Share