I looked for this online and nothing worked.

I want a banner/label to show on my category view (in grid mode) that a certain product is out of stuck.

I tried to add:

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
$qty = $stock->getQty();
if($qty <= 0)
<span class="out-of-stock"><span>Sold Out</span></span>

after the foreach product in the grid mode but didn't work


I also have something like this

<div class="product-secondary">
                    <?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
                        <p class="action"><button type="button" title="<?php echo $this->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                    <?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
                        <p class="action"><a title="<?php echo $this->quoteEscape($this->__('View Details')) ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a></p>
                    <?php else: ?>
                        <p class="action availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>

1 Answer 1


Try this :

$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);

    //in stock!
    //not in stock!
  • do I put that on grid mode after the foreach?
    – MagTubsvyu
    Jun 28, 2018 at 14:24
  • check my edited version. I have something like that look please
    – MagTubsvyu
    Jun 28, 2018 at 14:26
  • yes you can add after foreach Jun 28, 2018 at 14:30
  • going to try and check. Do I need to reindex or is flushing the cache enough?
    – MagTubsvyu
    Jun 28, 2018 at 14:31
  • Still not working :/ It shows in list mode, but not in grid mode. And yes, I added after the foreach on the grid mode view area
    – MagTubsvyu
    Jun 28, 2018 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.