3

I replaced the table view with a drop down view. Now, the file "template/catalog/product/view/type/grouped.phtml" looks like this:

..

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" class="add-to-cart" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div style="float:right;border:1px solid;padding:5px; width: 100%;">
    <?php if($_product->isGrouped()): ?>
        <?php $_subAssociatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); ?>
        <?php if(count($_subAssociatedProducts)){?>
            <!--<div class="groupedTitle">Dimensiune / Grosime</div>-->
            <select id="grouped_products" name="grouped_products" onchange="addSuperQty('<?php echo $_product->getId()?>',this.value);">
                <?php foreach ($_subAssociatedProducts as $_item) {?>
                <option value="<?php echo $_item->getId()?>" id="<?php echo number_format($_item->getFinalPrice(),2); ?>"><?php echo $this->htmlEscape($_item->getName())?></option>
                <?php } ?>
            </select>
        <?php }?>
        <span id="span_<?php echo $this->getId()?>"></span>
        <input type="button" value="-" id="minus1" class="minus" />
        <input type="text" size="3" name="qty" onchange="changeQty(this.value,'<?php echo $_product->getId()?>');" id="<?php echo $_product->getId()?>_qty" maxlength="12" value="<?php echo $_product->getProductDefaultQty() * 1 ?>" class="input-text qty" />
        <input type="button" value="+" id="add1" class="plus" />
    <?php else:?>
        <input type="button" value="-" id="minus1" class="minus" />
        <input type="text" size="3" name="qty" id="qty" maxlength="12" value="<?php echo $_product->getProductDefaultQty() * 1 ?>" class="input-text qty" />
        <input type="button" value="+" id="add1" class="plus" />

    <?php endif; ?>
    <button type="button" class="button btn-cart" onclick="this.form.submit()"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
</div>
</form>

..

<script type="text/javascript">
    function addSuperQty(spanId,itemId)
    {
        var qty = document.getElementById(spanId+'_qty').value;
        var ID = 'span_'+spanId;
        document.getElementById(ID).innerHTML = '<input type="hidden" value="'+qty+'" id="super_group_'+spanId+'"  name="super_group['+itemId+']" />';
    }

    function changeQty(val,itemId)
    {
        document.getElementById('super_group_'+itemId).value = val;
    }
</script>

For all my grouped products, the default value is 0. So this:

<?php echo $_product->getProductDefaultQty() * 1 ?>

Displays 0 for the quantity each time. What is wrong? On older Magento versions it worked.

When I set a bigger product quantity and try to add the product (sub product) into my account, I receive this error: Please specify the quantity of product(s).

Please help me to fix the problem. Thanks!

3

The name of the input box is wrong in your case. It must be super_group[#item_id]. Please replace item_id with the actual #item id. You can achieve it using jquery/javascript, etc.

  • I'm using javascript. Please take a look again at the code from above. I added the js part. Still not working. – Pascut Oct 28 '14 at 21:26
  • It was a javascript error. Thanks for telling me about js :) – Pascut Oct 28 '14 at 21:36
1

I've found the problem. I used $this instead of $_product on this line:

<span id="span_<?php echo $this->getId()?>"></span>

So now I have:

<span id="span_<?php echo $_product->getId()?>"></span>

There was a JavaScript error. I was too sleepy to notice this error. (use Firebug)

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.