I know there are already a lot of answers for how to add multiple products at once. I don't think this is a duplicate because here we are talking about subproducts not products.
Currently on my catalog product view there are 4 radio buttons so that the customer can select 4 different variations of the product. If the customer selects variation #1 and clicks add to cart
, then there will be 1 item in the cart. If they go back to the catalog product view and select variation #2 and click add to cart
, then there will be two separate items in the cart. So these two variations are essentially two different "products" because they have different "subtitles", different prices and they have their own row on the cart view.
The 4 radio buttons are all part of the same radio button group, thus the customer can only add a single variation to the cart at a time. If they want to add another variation to the cart they must go back to the product page and click add to cart
again.
We want to break the radio buttons up into two groups of 2 so that the customer can select 2 variations at once and then click add to cart
in order to add the 2 variations to the cart at the same time.
The issue that I am having is that I can't figure out how to alter CartController::addAction
so that it will add 2 product variations to the cart at the same time.
The only difference in terms of the $params
from one variation to another is the value for $params['super_attribute']['my_val']
. If I hardcode this value into addAction()
then I can control which variation gets added to the cart - so I know that's what controls the variation.
As a test I thought I would be able to change this:
$cart->addProduct($product, $params);
to this:
$params['super_attribute']['my_val'] = 1;
$cart->addProduct($product, $params);
$params['super_attribute']['my_val'] = 2;
$cart->addProduct($product, $params);
but what ends up happening with that approach is that the first one gets added twice(ie. it's the only one in the cart with a quantity of 2). I've tried several other variations of this test code but nothing works.
Is there a way to do this in CartController::addAction
(or some of the PHP it calls)? Or should I try a different way(like maybe make an AJAX call to the API)?