Skip to content

Commit dc7a7f8

Browse files
committed
ACP2E-2174: allow qty change for cart items without errors
1 parent cc6a411 commit dc7a7f8

File tree

2 files changed

+7
-5
lines changed
  • app/code/Magento/Checkout/Model
  • dev/tests/integration/testsuite/Magento/Checkout/Controller

2 files changed

+7
-5
lines changed

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ public function updateItems($data)
523523
);
524524

525525
$qtyRecalculatedFlag = false;
526+
$itemErrors = [];
526527
foreach ($data as $itemId => $itemInfo) {
527528
$item = $this->getQuote()->getItemById($itemId);
528529
if (!$item) {
@@ -536,15 +537,12 @@ public function updateItems($data)
536537

537538
$qty = isset($itemInfo['qty']) ? (double)$itemInfo['qty'] : false;
538539
if ($qty > 0) {
539-
if ($item->getHasError() && !$item->getProduct()->isInStock()) {
540-
$item->setUseOldQty(true);
541-
}
542540
$item->clearMessage();
543541
$item->setHasError(false);
544542
$item->setQty($qty);
545543

546544
if ($item->getHasError()) {
547-
throw new \Magento\Framework\Exception\LocalizedException(__($item->getMessage()));
545+
$itemErrors[$item->getId()] = __($item->getMessage());
548546
}
549547

550548
if (isset($itemInfo['before_suggest_qty']) && $itemInfo['before_suggest_qty'] != $qty) {
@@ -568,6 +566,10 @@ public function updateItems($data)
568566
['cart' => $this, 'info' => $infoDataObject]
569567
);
570568

569+
if (count($itemErrors)) {
570+
throw new \Magento\Framework\Exception\LocalizedException(current($itemErrors));
571+
}
572+
571573
return $this;
572574
}
573575

dev/tests/integration/testsuite/Magento/Checkout/Controller/CartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,10 @@ private function updatePostRequest(
594594
$this->dispatch('checkout/cart/updateItemQty');
595595
} else {
596596
$this->dispatch('checkout/cart/updatePost');
597+
$quote->collectTotals();
597598
}
598599
$response = $this->getResponse()->getBody();
599600
$response = json_decode($response, true);
600-
$quote->collectTotals();
601601
return $response;
602602
}
603603
}

0 commit comments

Comments
 (0)