Skip to content

Commit 473b8d8

Browse files
author
Prabhu Ram
committed
- Fixed bug to save a product if another product in cart has an error
1 parent 762a3c1 commit 473b8d8

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

app/code/Magento/Quote/Model/Cart/AddProductsToCart.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ public function execute(string $maskedCartId, array $cartItems): AddProductsToCa
115115
}
116116
}
117117

118-
if (count($this->errors) === 0) {
119-
$this->cartRepository->save($cart);
120-
} else {
118+
if (!count($this->errors) === 0) {
121119
/* Revert changes introduced by add to cart processes in case of an error */
122120
$cart->getItemsCollection()->clear();
123121
}
@@ -155,6 +153,7 @@ private function addItemToCart(CartInterface $cart, Data\CartItem $cartItem, int
155153

156154
try {
157155
$result = $cart->addProduct($product, $this->requestBuilder->build($cartItem));
156+
$this->cartRepository->save($cart);
158157
} catch (\Throwable $e) {
159158
$this->addError(
160159
__($e->getMessage())->render(),

0 commit comments

Comments
 (0)