How to add multiple products to cart at the same time with attributes I have different view blocks that display multiple products on the same page, each product has their own attributes such as product bundle and custom line item, these serves as an option set / criteria of the main product. The results of the options slider will be the value of the customs line item that is hidden.

What I plan to accomplish is to add all these selected products with the selected attributes on the cart at the same time with just one button.

Example:

Product 1:



Product 2:



These are the methods/modules I have tried:


VBO + Rules : https://www.drupal.org/node/1468392#comment-10270105
Commerce Add to Cart Extras
Commerce Ajax Add to Cart + Jquery : Looping through all selected products then clicking the add to cart button by jquery. It works but not that great because sometimes some of the products are not being added. Maybe because of all the ajax request running at the same time?


The first two methods work for the main product only, no attributes of the customs line item and bundle products. I tried including the add to cart form in the view with the VBO or commerce product: quantity field of commerce add to cart extras but it doesn't work maybe because it's a form within a form.

Does anyone have any suggestion on how to make this work?

Thank you in advance!
I suggest writing a custom hook_submit() who will add all the items of your views to the shopping cart.

Something like that should do the job.

 global $user;

 $results = views_get_view_result('view_name', 'block_1');

 foreach($results as $item) {
 // Create new line item:
 $line_item = commerce_product_line_item_new($product, $quantity);

 // Add to current user's cart
 $line_item_added = commerce_cart_product_add($user-&gt;uid, $line_item);
 }


Good luck.

Cheers