1

I have some products in a Drupal Website using Drupal Commerce. Those products are listed via a custom modules to the front end. If the user clicks on any of the products then it goes to the product display page. There I have 2 checkbox and the Add to Cart Button. Such as

  • Gift Packaging ($10.99)
  • Custom Messages ($4.99) These are 2 checkboxes coming from a drupal form created on my custom module. I want to add these as line items to the Selected Product. Such as,

If user choses Product A and Gift Packaging then, Product A ($10.00) Gift Packaging ($10.99) Total : $20.99

  1. So how can I add the chosen line item to that product once the user clicks on the Add to Cart Button. I have a function that is fired once the button is clicked. The function is "my_module_add_to_cart()".
  2. How can I show the updated Price as $20.99 to the /cart page table?

1 Answer 1

2

Why not use Commerce Product Options which provides this functionality out of the box, directly in the default Add to Cart form?

To adjust the price based on the chosen options, you can use the Commerce Pricing module, which comes as part of the Commerce project. It basically provides a number of rules conditions and actions which allow you to adjust the price of a line item and e.g. add a fixed amount or multiply it by a certain value.

2
  • I am not using the default add to cart button. I am using a custom form and a submit hook to deal with it. I am adding the product via commerce_cart_product_add_by_id API. So in that hook submit I have to add the line items after adding the product to cart. Any suggestions? Commented Apr 17, 2012 at 4:58
  • 1
    Well, either look at the code of the referenced module and reproduce what it does or alternatively you maybe could simply use the default form and then customize it using hook_form_alter().
    – Berdir
    Commented Apr 17, 2012 at 8:23

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.