Skip to content

Commit 26ba03d

Browse files
committed
ACP2E-368: Issue when adding multiple items in addProductsToCart graphQL mutation
1 parent 117be18 commit 26ba03d

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,17 @@ public function execute(string $maskedCartId, array $cartItems): AddProductsToCa
106106
}
107107

108108
$failedCartItems = $this->addItemsToCart($cart, $cartItems);
109-
if (count($failedCartItems) !== count($cartItems)) {
109+
$saveCart = !empty($cartItems) && empty($failedCartItems);
110+
if (!empty($failedCartItems)) {
110111
/* Revert changes introduced by add to cart processes in case of an error */
111112
$cart->getItemsCollection()->clear();
112113
$newFailedCartItems = $this->addItemsToCart($cart, array_diff_key($cartItems, $failedCartItems));
113114
$failedCartItems += $newFailedCartItems;
114115
$saveCart = empty($newFailedCartItems);
115-
} else {
116-
$saveCart = false;
117-
}
118-
119-
foreach (array_keys($cartItems) as $cartItemPosition) {
120-
if (isset($failedCartItems[$cartItemPosition])) {
121-
array_push($allErrors, ...$failedCartItems[$cartItemPosition]);
116+
foreach (array_keys($cartItems) as $cartItemPosition) {
117+
if (isset($failedCartItems[$cartItemPosition])) {
118+
array_push($allErrors, ...$failedCartItems[$cartItemPosition]);
119+
}
122120
}
123121
}
124122

0 commit comments

Comments
 (0)