I am trying to add a configurable product with with different variants but its showing one item with 2 quantity instead of showing 2 item with each quantity one.
$wholedata = $this->getRequest()->getParams();
$productId =$wholedata['product_id'];
$superattribute = array();
foreach ($wholedata['qty'] as $eachkey => $eachparam) {
foreach ($wholedata['config'] as $key => $value) {
$superattribute[$key] = $value[$eachkey];
}
$params = array(
'form_key' => $this->formKey->getFormKey(),
//'product' => $productId, //product Id
'qty' =>$eachparam,
'selected_configurable_option' => '',
'super_attribute' => $superattribute
);
$_product = $this->product->load($productId);
$this->cart->addProduct($productId, $params);
$this->cart->save();
}
But Strange when I added it one by one and just refresh the cart page in-between then it works fine
If have tried to use $quote->collectTotals()->save();
as well $checkoutsession->getQuote()->setCartWasUpdated(true);
but nothing works.
Please help