1

On my commerce site, I would like to use exact functionality like both ubercart cart links or ubercart kits have - to add multiple different products to cart at once (one click on button or link, no quantity).
Requirement is: products inside cart should behave as single products, with quantity enabled. I do not need discounts.

modules I tried:

  • commerce product bundle - adds all products as one product, you can only change quantity
  • commerce bundle - separate products but quantity fields disabled.

Rules links look promising but I am not so sure how it would work with many kits. Do anybody have a solution for this? Thank you.

User case: Create various product kits (as content types) with add to cart button. After adding to cart, products behave like normal simple products. (Ubercart has this funtctionality - while creating a product kit, you can check wether you want the products to behave in cart like a kit(a bundle) or as a separate products.)

3
  • 1
    By multiple products you mean different products should be added by one Add to Cart button or you want to add let's say 2 or 3 products of the same type with one Button click?
    – rashidkhan
    Sep 24, 2015 at 0:40
  • please provide more details about what you want, your question is not clear
    – Yuseferi
    Sep 25, 2015 at 6:13
  • I meant multiple different products - same functionality as ubercart for drupal 6 has.
    – loparr
    Sep 25, 2015 at 15:28

3 Answers 3

3

I am working on the very same requirement - different products from a single (product kit) content type, single add to cart button, and products after adding to cart behave normally.

In this process, I use Commerce Product Kit module. It provides a field formatter for product reference field or an entity reference field pointing to commerce products.
The instructions on use of the module are given on the project page. Try it out and report any issues that you could find :)

P.S: I am the author and maintainer of the module.

1
  • HI, If this works as advertised, than finally it is solved. I wonder why nobody requested this function before.
    – loparr
    Mar 19, 2016 at 19:59
3

Commerce Add to Cart Extras

This module provides alternative ways of adding products to cart.

The initial version provides a views field handler ("Commerce Product: Quantity input field") that relies on the Views Form API (a part of Views 3 since RC1) to output a quantity textfield that turns the view into an add to cart form. The default quantity can be configured, and only products with a quantity larger than 0 are added to the cart.

1

You can do that by creating a rule, which you then trigger by rules link, or a view VBO block, like (copied from here https://www.drupal.org/node/1468392#comment-10270105):

The Rules Part:

  1. create a new rules component. Make it an Action set.
  2. First, add a name. EG "VBO Add To Cart". Below, you'll see a table with three rows - you only need to fill in the top one. Choose Commerce product from the dropdown (under Entity), and then fill in the other 2 with something memorable like 'Commerce Product' for the label. The machine name needs to be something like commerce_product. Click continue.
  3. On the next page, choose 'add action'. Choose the type of action: Add product to cart.
  4. On the next page you need to add the user and the sku. In the user field, start by writing 'site'. This will trigger the dropdown, and you can choose site:current-user. Then for the SKU - first click 'switch to data selection'. You can then click in the field, and select the entity you named earlier (not site). Then you can select sku. Now change the quantity if you need to, then click save.

The Views Part (The easy part)

For this you need VBO installed. Make a view displaying a table of commerce products. You can add the name and the price fields. Next add the VBO field. From the actions list, you should see your newly created rule action. Select it, and if you want, choose to skip the confirmation. Under the bulk options, I also changed it to display as single buttons, as I only have this one action that can be performed. Now save the view. (If you want the tickbox on the left of your table, just rearrange the fields.

Now place your view where you want it (eg a block on a page, or a page, or inserted into a panel) and view it. You should be able to select multiple products with the checkboxes, and then add them to the cart with one click.

Or do it programmatically, like

<?php
    global $user;
    $line_item = commerce_product_line_item_new(commerce_product_load($YOUR_PRODUCT_ID));
    commerce_cart_product_add($user->uid, $line_item);
    $line_item = commerce_product_line_item_new(commerce_product_load($OTHER_PRODUCT_ID));
    commerce_cart_product_add($user->uid, $line_item);
?>

in a custom (Ajax) callback.

5
  • the question is not clear what he want , how can u reply it ??? :D
    – Yuseferi
    Sep 24, 2015 at 8:41
  • maybe i hit his need ;)
    – rémy
    Sep 24, 2015 at 16:26
  • @rémy Hi, I added more explanation.
    – loparr
    Sep 25, 2015 at 15:33
  • i copied the linked text here for you. does it match your need to have a block ? or how do you want to display these bundle-add-to-cart links ?
    – rémy
    Sep 28, 2015 at 7:22
  • Hi, thank you for answers. I would like to display the bundles wherever I want. Can be also on product page (related kits). Code snippet is not ok because - I do not want to use code snippets each time I want to create a product kit. Moreover it will be difficult to maintain many product kits. Is it possible to create a content type (product kit) with references to products and use your solution to add the products to cart at once (using one add to cart button, without additional forms)? Thank you.
    – loparr
    Sep 30, 2015 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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