Skip to main content

Posts

Showing posts from August, 2012

Drupal: Ubercart: One add-to-cart for many items

Ubercart includes a module called Ubercart Product Kit to allow a user to add more products to the cart when a user selects a product kit node.

In my case, I wanted the user to be able to buy many tickets for an event without going back and forth all the time. The "qty" field was not an option, since every ticket (thanks to the Repeat Date module) may be used for today, tomorrow, two months later etc. As a result any product in the cart must exist only once as it has a special code generated for each one. So I needed another way.

I saw the uc_product_kit module and saw that it used uc_cart_add_item() function to add more products in a hook_add_item(). I tried this but I couldn't make it work.

And then I fell on this conversation where PaulW suggested to use an extra submit function to add more items to the cart. And this worked perfectly!

See below:
In my module's hook_form_alter, after identifying the proper form id etc I use

After that, we declare our submit funct…