Skip to main content

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 function where we have to prepare the needed $data of the products/tickets. For everything to work, we need a 'tickets' array in the $data array with the following keys:
  • datetime: the unix timestamp for the date and time of the event the ticket is for
  • spectacle: the nid of the spectacle the ticket refers to


Popular posts from this blog

Configure drupal_http_request() on the fly

The drupal_http_request() function supports connections using a proxy. You can configure a global proxy to use for all drupal_http_request() callbacks from the settings.php file of your website/installation by filling the following lines with the proper information:For those of you preferring a UI, then HTTP proxy module is for you.But what if you only want to use a proxy in some cases; like a custom module? In that case you will need the following function(modify accordingly):Now all you have to do is Call <?php _MYMODULE_change_proxy(); ?>.Do your drupal_http_request() calls.Call <?php _MYMODULE_change_proxy(TRUE); ?> to reset your previous settings.

Drupal: Allow registrations through Invite or Referral modules only

The Invite module provides invitations from existing users to their contacts. The Referral module, in contrary, creates a special URL for each existing user, which can be found in each user's profile, and allows new user registration. Even though, these two modules seem to provide the same functionality, they don't (and they shouldn't). Invite module, provides a mechanism for a site administrator to limit new registrations to "Invitations only". Referral module doesn't provide any of this functionality. Some users have requested the Invite module and Referral module to join in one module. Until now, there isn't anything to that direction. Wouldn't it be great though if there was a solution to limit drupal registration to referral or invitation only? Copy the functions below to a refinvite.module file in your sites→all→modules→refinvite folder and enable the module. Then go to http://<your-address-here>/admin/user/settings and enable the new …

Send mass email to certain users using VBO

Views Bulk Operations uses the built-in actions to act upon nodes, users, entities etc. Among these actions is our ability to send emails to users. If you try to use this action though you will encounter a small but serious problem. You are asked for an email address to send your message. You might say "but I have selected the users I want this message to reach. Why should I input an address again?". Don't get overwhelmed. What this field expects is not an address but a token. Specially this token [user-email]. If the website is intended for you, then you might say that's not such a problem to write this token down again and again. But if the manager of the website is bound to be the client or if you just want to spend less time writing things down, you might prefer to use a custom hook_form_alter() callback to set a default value. It could be done in both theme and module environment so suit yourself. Just add the following in your module or theme.