2

Grouped Products - is it possible to show out of stock status individually (by each product)?

Magento: 1.9

  • 1
    Where you want to add this "out of stock" status, for products within grouped product. In grouped product details page ? – Alex Constantinescu Mar 8 '16 at 19:44
  • On Grouped product detail page – Jai Mar 9 '16 at 3:58
4

File: template/catalog/product/view/type/grouped.phtml

<?php // If QTY is OUT OF STOCK then display it to user

                $_product = Mage::getModel('catalog/product')->load($_item->getId());
                $stock = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

             if($stock < 1 ) { 
                 echo '<p class="out-of-stock-qty">';  echo $this->__(' --- Out of Stock --- ');  echo '</p>';
                 }

            ?>      

$_item->getId() is ID of product and this can be used on any type of product where you need to display qty of product Or just to inform about available stock. This might help someone.

0

In my Magento instalation, this is the default behaviour and the code responsible for that is located in template/catalog/product/view/type/grouped.phtml

<?php foreach ($_associatedProducts as $_item): ?>
........
    <?php if ($_product->isSaleable()): ?>
            <div class="qty-wrapper">
            <?php if ($_item->isSaleable()) : ?>
              <input id="super_group_<?php echo $_item->getId(); ?>" type="text" pattern="\d*" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
              <label for="super_group_<?php echo $_item->getId(); ?>" class="qty-label">
               <?php echo $this->__('Quantity'); ?>
              </label>
              <?php else: ?>
                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
              <?php endif; ?>
            </div>
<?php endif; ?>
...........
<?php endforeach; ?>
  • If item is out of stock then OUT OF STOCK need to display with product. thats what required so that end user dont add into cart or aware not to add this item to cart – Jai Mar 10 '16 at 17:02
  • the code from above does what you want – Alex Constantinescu Mar 10 '16 at 18:23
  • No. If i can check number of quantity after line <?php if ($_item->isSaleable()) : ?> then we can display message that its out of stock. Can you pls let me know if we can get number of quantity here? – Jai Mar 11 '16 at 4:06

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.