Skip to content

Commit d5f4517

Browse files
author
Serhiy Shkolyarenko
committed
MAGETWO-39117: Updating qty that exceeds the qty in stock for registered customer by API should return error
moved error processing to the quote scope.
1 parent 76a923a commit d5f4517

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

app/code/Magento/Quote/Model/Quote/Item/CartItemPersister.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ public function save(CartInterface $quote, CartItemInterface $item)
7272
$item = $quote->updateItem($itemId, $buyRequestData);
7373
} else {
7474
$currentItem->setQty($qty);
75-
if (!empty($currentItem->getErrorInfos())) {
76-
$errors = $currentItem->getErrorInfos();
77-
/** @var \Magento\Framework\Message\MessageInterface $error */
78-
$errorData = array_shift($errors);
79-
throw new CouldNotSaveException($errorData['message']);
80-
}
8175
}
8276
} else {
8377
/** add new item to shopping cart */

app/code/Magento/Quote/Model/QuoteRepository/SaveHandler.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Quote\Api\Data\CartInterface;
99
use Magento\Framework\Exception\InputException;
10+
use Magento\Framework\Exception\CouldNotSaveException;
1011

1112
class SaveHandler
1213
{
@@ -70,6 +71,13 @@ public function save(CartInterface $quote)
7071
}
7172
}
7273
}
74+
$errors = $quote->getErrors();
75+
if (!empty($errors)) {
76+
$renderedErrors = $this->renderErrors($errors);
77+
throw new CouldNotSaveException(
78+
__('Following errors occurred on save: %1', implode('; ', $renderedErrors))
79+
);
80+
}
7381

7482
// Billing Address processing
7583
$billingAddress = $quote->getBillingAddress();
@@ -83,6 +91,21 @@ public function save(CartInterface $quote)
8391
return $quote;
8492
}
8593

94+
/**
95+
* @param array $errors
96+
* @return array
97+
*/
98+
private function renderErrors($errors)
99+
{
100+
$renderedErrors = [];
101+
/** @var \Magento\Framework\Message\Error $error */
102+
foreach ($errors as $error) {
103+
$renderedErrors[] = $error->getText();
104+
}
105+
return $renderedErrors;
106+
}
107+
108+
86109
/**
87110
* @param \Magento\Quote\Model\Quote $quote
88111
* @return void

0 commit comments

Comments
 (0)