1

The below code works well for products who's stock is being managed, but it displays "0" if "Manage Stock" is selected as "No" in the Magento backend. There's probably at least a few hundred products where the stock isn't currently managed, so going through them all isn't feasible. So, is it possible, when the product's stock isn't managed, to swap the "0" it places there with some sort of text like "call us about inventory"?

This is in app/design/frontend/{theme}/default/template/catalog/product/view/type/default.phtml :

<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"> <span class="fa fa-check"> </span> <?php echo $this->__('Qty Available:') ?> <span><!--<?php echo $this->__('In stock') ?>--><?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?></span></p>
<?php else: ?>
    <p class="availability out-of-stock"> <span class="fa fa-times"> </span> <?php echo $this->__('') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>

Some extra context: The "0" appears because Manage Stock is set to "No", Qty is set to "0", and the Stock Availability set to "In Stock". Even though the Manage Stock is set to "No", the code above still seems like it ignores that & grabs whatever is in the Qty field anyway.

1

Use following code:

<?php if ($_product->isAvailable()): ?>
    <p class="availability in-stock"> <span class="fa fa-check"> </span> <?php echo $this->__('Qty Available:') ?> <span><!--<?php echo $this->__('In stock') ?>-->
    <?php $manageStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product->getId())->getManageStock();
     if($manageStock == 0) { 

     echo 'Call us about inventory';
     }else{
     ?>

    <?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?></span>
    <?php } ?>
    </p>
    <?php else: ?>
        <p class="availability out-of-stock"> <span class="fa fa-times"> </span> <?php echo $this->__('') ?> <span><?php echo $this->__('Out of stock') ?></span></p>
    <?php endif; ?>
1
  • I took what you posted & suited it a bit more for my particular application & it's working just as I wanted. Thanks for sending me in the right direction! – Daryl Gochnauer Apr 8 '16 at 16:37

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.