Skip to content

Commit 7e7700d

Browse files
committed
MC-32201: Reorder functionality
1 parent 0be47d5 commit 7e7700d

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ public function addProduct(
16791679

16801680
// collect errors instead of throwing first one
16811681
if ($item->getHasError()) {
1682+
$this->deleteItem($item);
16821683
foreach ($item->getMessage(false) as $message) {
16831684
if (!in_array($message, $errors)) {
16841685
// filter duplicate messages

app/code/Magento/Sales/Model/Reorder/Reorder.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ class Reorder
3636
* List of error messages and codes.
3737
*/
3838
private const MESSAGE_CODES = [
39-
'The product that you are trying to add is not available' => self::ERROR_NOT_SALABLE,
39+
'Product that you are trying to add is not available' => self::ERROR_NOT_SALABLE,
4040
'The fewest you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
4141
'The most you may purchase is' => self::ERROR_INSUFFICIENT_STOCK,
42-
'The requested quantity is not available' => self::ERROR_INSUFFICIENT_STOCK,
42+
'The requested qty is not available' => self::ERROR_INSUFFICIENT_STOCK,
4343
];
4444

4545
/**
@@ -131,14 +131,7 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
131131

132132
$items = $order->getItemsCollection();
133133
foreach ($items as $item) {
134-
try {
135-
$this->addOrderItem($cart, $item);
136-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
137-
$this->addError($this->addCartItemError($item, $e->getMessage()));
138-
} catch (\Throwable $e) {
139-
$this->logger->critical($e);
140-
$this->addError($this->addCartItemError($item, $e->getMessage()), self::ERROR_UNDEFINED);
141-
}
134+
$this->addOrderItem($cart, $item);
142135
}
143136

144137
try {
@@ -157,7 +150,6 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
157150
* @param \Magento\Quote\Model\Quote $cart
158151
* @param Item $orderItem
159152
* @return void
160-
* @throws \Magento\Framework\Exception\LocalizedException
161153
*/
162154
private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): void
163155
{
@@ -176,7 +168,14 @@ private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): voi
176168
);
177169
return;
178170
}
179-
$cart->addProduct($product, $info);
171+
try {
172+
$cart->addProduct($product, $info);
173+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
174+
$this->addError($this->addCartItemError($product->getSku(), $e->getMessage()));
175+
} catch (\Throwable $e) {
176+
$this->logger->critical($e);
177+
$this->addError($this->addCartItemError($product->getSku()), self::ERROR_UNDEFINED);
178+
}
180179
}
181180
}
182181

@@ -236,15 +235,14 @@ private function prepareOutput(CartInterface $cart): Data\ReorderOutput
236235
/**
237236
* Add error message for a cart item
238237
*
239-
* @param Item $item
240-
* @param string $message
238+
* @param string $sku
239+
* @param string|null $message
241240
* @return string
242241
*/
243-
private function addCartItemError(Item $item, string $message): string
242+
private function addCartItemError(string $sku, string $message = null): string
244243
{
245-
return (string) __(
246-
'Could not add the product with SKU "%sku" to the shopping cart: %message',
247-
['sku' => $item->getSku() ?? '-', 'message' => $message]
248-
);
244+
return (string)($message
245+
? __('Could not add the product with SKU "%1" to the shopping cart: %2', $sku, $message)
246+
: __('Could not add the product with SKU "%1" to the shopping cart', $sku));
249247
}
250248
}

0 commit comments

Comments
 (0)