1

I have a grouped product with a large amount of simple products. I want the quantity of the simple product to default to the maximum stock available.

Issue with this that the current "Add To Cart" button adds all the simple products to the cart.

I'd like to add a button next to each simple item that will only add that item to the cart, is that possible?

1 Answer 1

3

You can edit this template from your theme catalog/product/view/type/grouped.phtml and replace the sectnion that lists all the simple products:

     <?php if ($_product->isSaleable()): ?>
        <td class="a-center">
        <?php if ($_item->isSaleable()) : ?>
            <input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php else: ?>
            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
        <?php endif; ?>
        </td>
     <?php endif; ?>

with this:

   <?php if ($_product->isSaleable()): ?>
        <td class="a-center">
        <?php if ($_item->isSaleable()) : ?>
            <input type="text" name="super_group[<?php echo $_item->getId() ?>]" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" /> 
             <!-- [+]  add this-->
            <button type="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>' + 'qty/' + $(this).previous().value)">Add to cart</button>
             <!-- [-]  add this-->
        <?php else: ?>
            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
        <?php endif; ?>
        </td>
     <?php endif; ?>

I didn't test the code so there might be some errors bu this sounds like the way to go. You can work on the button styling and translating the add to cart text.

5
  • 1
    Thanks, but i Tried that code, getting error Parse error: syntax error, unexpected T_ENDFOREACH on line 79
    – Aszental
    Nov 27, 2013 at 10:31
  • @user1700160 Make sure you did not delete any endif. To make it easier, just revert to the original file and add this <button type="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>' + 'qty/' + $(this).previous().value)">Add to cart</button> after the qty input.
    – Marius
    Nov 27, 2013 at 10:47
  • Thanks, any guides to how i can style the button?
    – Aszental
    Nov 27, 2013 at 23:35
  • @user1700160. Just see how the other buttons in your website look like and set the same classes and markup.
    – Marius
    Nov 28, 2013 at 6:38
  • I have tried but not working brother...! Feb 22, 2019 at 10:10

Your Answer

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

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