4

I want to split the quantity text box into three text boxes,i.e., for child, adult and others separatly before add to cart for only bundled products. I did by adding the following code in the addtocart.phtml

 <?php if ($_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE): ?>
            <label for="qty"><?php echo $this->__('Adult Qty:') ?></label>
            <input type="text" name="qty" id="adult-qty" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
            <label for="qty"><?php echo $this->__('Child Qty:') ?></label>
            <input type="text" name="qty" id="child-qty" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
            <label for="qty"><?php echo $this->__('Infant Qty:') ?></label>
            <input type="text" name="qty" id="infant-qty" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
        <?php endif; ?>

Now what i need is have to add these three quantities and save as a total quantity. Also have to view child,adult and others quantities separately in teh shopping cart page. Can anyone have idea on this?

5
  • What is the usecase? Commented May 15, 2014 at 15:29
  • Have to store the total quantity of these 3 quantities into database and have to give the splittable view to the users Commented May 15, 2014 at 15:40
  • JavaScript then Commented May 15, 2014 at 16:21
  • Yes by using js we can add it and insert into the DB. But how to split it and view in next page without storing them separately into the DB? Commented May 15, 2014 at 16:24
  • Also if change the quantity by using jquery while typing the quantity text boxes getting the following error. "Item qty declaration error." Commented May 15, 2014 at 16:35

2 Answers 2

3
+25

Vinai gave a great answer on this:

https://stackoverflow.com/questions/9412074/magento-quote-order-product-item-attribute-based-on-user-input/9496266#9496266

What you want to do is use JS to calculate the qty and put it into a hidden field. The different quantities can just be saved in three different attributes for quote_item or as a json string, whatever suits you.

You don't need to transfer it to the order_item if you don't need it in backend, order confirmation or to buy the stuff again. If you need one of those, you have to implement the whole observer logic for orders too.

1

It looks to me that you're trying to implement functionality already in place -- grouped products:

http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-grouped-product

I have to admit that using bundled products as group elements might not work, but I'm pretty confident that overcoming this obstacle is much easier than implementing something else.

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.