Skip to content

Commit 2cb1367

Browse files
committed
MC-32201: Reorder functionality
1 parent e167e84 commit 2cb1367

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
125125

126126
$cart = $this->customerCartProvider->resolve($customerId);
127127
if (!$this->reorderHelper->canReorder($order->getId())) {
128-
$this->addError(__('Reorder is not available.'), self::ERROR_REORDER_NOT_AVAILABLE);
128+
$this->addError((string)__('Reorder is not available.'), self::ERROR_REORDER_NOT_AVAILABLE);
129129
return $this->prepareOutput($cart);
130130
}
131131

@@ -134,13 +134,10 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
134134
try {
135135
$this->addOrderItem($cart, $item);
136136
} catch (\Magento\Framework\Exception\LocalizedException $e) {
137-
$this->addError($e->getMessage());
137+
$this->addError($this->addCartItemError($item, $e->getMessage()));
138138
} catch (\Throwable $e) {
139139
$this->logger->critical($e);
140-
$this->addError(
141-
__('We can\'t add this item to your shopping cart right now.'),
142-
self::ERROR_UNDEFINED
143-
);
140+
$this->addError($this->addCartItemError($item, $e->getMessage()), self::ERROR_UNDEFINED);
144141
}
145142
}
146143

@@ -174,7 +171,7 @@ private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): voi
174171
$product = $this->productRepository->getById($orderItem->getProductId(), false, null, true);
175172
} catch (NoSuchEntityException $e) {
176173
$this->addError(
177-
__('Could not find a product with ID "%1"', $orderItem->getProductId()),
174+
(string)__('Could not find a product with ID "%1"', $orderItem->getProductId()),
178175
self::ERROR_PRODUCT_NOT_FOUND
179176
);
180177
return;
@@ -190,11 +187,11 @@ private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): voi
190187
* @param string|null $code
191188
* @return void
192189
*/
193-
private function addError($message, string $code = null): void
190+
private function addError(string $message, string $code = null): void
194191
{
195192
$this->errors[] = new Data\Error(
196-
(string)$message,
197-
$code ?? $this->getErrorCode((string)$message)
193+
$message,
194+
$code ?? $this->getErrorCode($message)
198195
);
199196
}
200197

@@ -235,4 +232,19 @@ private function prepareOutput(CartInterface $cart): Data\ReorderOutput
235232
$this->errors = [];
236233
return $output;
237234
}
235+
236+
/**
237+
* Add error message for a cart item
238+
*
239+
* @param Item $item
240+
* @param string $message
241+
* @return string
242+
*/
243+
private function addCartItemError(Item $item, string $message): string
244+
{
245+
return (string) __(
246+
'Could not add the product with SKU "%sku" to the shopping cart: %message',
247+
['sku' => $item->getSku() ?? '-', 'message' => $message]
248+
);
249+
}
238250
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/ReorderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ private function assertProductNotAvailable()
126126
[
127127
'path' => ['orderNumber'],
128128
'code' => 'NOT_SALABLE',
129-
'message' => 'Product that you are trying to add is not available.',
129+
'message' => 'Could not add the product with SKU "simple" to the shopping cart: '
130+
. 'Product that you are trying to add is not available.',
130131
],
131132
],
132133
'cart' => [

0 commit comments

Comments
 (0)