I'm using the Commerce Ajax Add to Cart module to add a product to my cart using AJAX. I guess I'll have to do that by creating a patch.
It's working fine, but I'd like to change how a product is added to the cart. For example, users add 4 times the same product in the cart. I've already made some changes so the by default, the quantity in my item cart is four. For now, if users click on *Add to cart, then the quantity will be added to the cart.
Instead of adding the quantity to the cart, I'd like to update the quantity. If users click on Add to cart and the quantity is five, instead of adding five to the quantity, the quantity for the product is five instead of nine.
After digging, I've found on commerce/modules/cart/src/Form/AddToCartForm.php
submitForm(), which uses the following code.
$this->entity = $this->cartManager->addOrderItem($cart, $order_item, $form_state->get(['settings', 'combine']));
I tried to remove the order item before adding the item (to "simulate" a quantity of 0) with this code.
I also tried by updating the order item cart.
$this->entity = $this->cartManager->updateOrderItem($cart, $order_item, $form_state->get(['settings', 'combine']));
Neither of them gave the expected result.
Do you have any idea?