Add items to the Ubercart cart with custom forms
The request for more robust Ubercart add to cart forms comes up fairly regularly. People generally have in mind the sort of form that allows customers to specify quantities for a set of products and add them to the cart all at once. The request came up so often that I put a short explanation on how to accomplish this through a custom form into an FAQ post on Ubercart.org.
This article will walk through a very basic example of how you can use the Ubercart function uc_cart_add_item() in a custom form submit handler to add multiple items to the cart at once. This article assumes a basic knowledge of Drupal's Forms API. Code examples are from Drupal 6, but they are mostly applicable to Drupal 5 as well.
Provides two catalog display types that allow buying multiple items with one click. The catalog display types look the same as the default list table and grid formats, but without the add to cart buttons for individual products and with a button at the bottom of the catalog page instead. When the button is pressed all products with positive quantity field values will be added to the cart.
UC Ajax Cart - Drupal 6
UC Ajax Cart provide another block for cart. So disabled cart block and enable UC Ajax Cart block
UC Add to Cart Tweaks
The UC Add to Cart Tweaks product feature allows you to alter ways the add to cart form behaves for any product in your Ubercart store. The current tweaks provided allow you to empty the shopping cart when the add to cart form is submitted and to alter the add to cart redirect URL.
Creating cart links
Cart links are simple to form using a few actions and arguments with the following rules:
- The cart link should be /cart/add/cart_link_content.
- Chain together as many actions as you want with dashes.
- Do not put any spaces or use dashes in any action arguments.
- Use the table below to learn about actions and their arguments.
- Arguments come directly after their action letters.
- Specify the redirection by adding ?destination=url where url is the page to go to.
|i||Sets the ID of the cart link.||A custom text ID for the link.|
|e||Empties the customer's cart.||None.|
|m||Displays a preset message to the customer.||A message ID.|
|p||Adds a product to the cart.||A product string using the rules below...|
- You must at least specify a node ID immediately after the 'p'.
- Add additional specifications separated by underscores.
- Specify the quantity with q followed by the number to add.
- Specify attributes/options using a#o#, replacing # with the ID of the attribute and option.
- Turn off the add to cart message with m0.
This example will empty the cart, add 5 of product 1 to the cart, track clicks with the ID "monday_special", and redirect the user to the cart. To use this on your site, simply create an HTML link to the URL you create:
<a href="http://www.example.com/cart/add/e-p1_q5-imonday_special?destination=cart">Link text.</a>
I was wondering if there was a way to include features as an argument in the link as well. I"m using the downpayment module which allows one to make a downpayment on the product. So when i pull up a product there is select box to choose weather a customer wants to make full payment or downpayment, it's not an option or an attribute, it's a feature so I'm not really sure how to go about creating a link that would add a product to the cart with just a downpayment. Thanks much!