2

I'm developing my own module for a customizable bundle of commerce products.

I'm saving the subproducts in a field collection in a line item field.

For some reasons I'm doing this with my module, not using "Include this field on Add to Cart forms for line items of this type" in the line item field settings.

Well, when I use my module I use

$form['#submit'][] = 'commerce_custom_bundle_add_to_cart_form_submit';

inside a

commerce_custom_bundle_form_commerce_cart_add_to_cart_form_alter

(is hook_form_BASE_FORM_ID_alter)

Then my function is executed after the product is added to the cart.

The problem is if I choose to add to cart the same product no new line item is created and the existing quantity is increased in 1, obviously.

But I need a new line item, because my custom field changes and I need to not merge the values chosen in the existing line item. I don't know How to force the creation of a new line item.

I tested, if I not use my code and I expose this field in the add to cart form enabling the "Include this field on Add to Cart forms for line items of this type" in the line item field settings. If the same product is added to the cart with a different value in my custom field, is created a new line item.

How do I force the creation of a new line item?

0

To force to create a line_item for every same product added to the cart you just need to uncheck the option "Attempt to combine like products on the same line item in the cart." in the Add to cart form settings of your product reference in your product display content type.

In other words. You have to change the content type that you use to show your product, you had added a product reference to this content type. Then you just has to change in the "Manage display" of your content type, the settings of the "Add to cart Form" of the product reference field, and you have to uncheck "Attempt to combine like products on the same line item in the cart."

This is a screenshot of the manage display page: enter image description here

  • It would be better if you can post with some screenshots. – Jimmy Ko Aug 1 '16 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.