@@ -36,10 +36,10 @@ class Reorder
36
36
* List of error messages and codes.
37
37
*/
38
38
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 ,
40
40
'The fewest you may purchase is ' => self ::ERROR_INSUFFICIENT_STOCK ,
41
41
'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 ,
43
43
];
44
44
45
45
/**
@@ -131,14 +131,7 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
131
131
132
132
$ items = $ order ->getItemsCollection ();
133
133
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 );
142
135
}
143
136
144
137
try {
@@ -157,7 +150,6 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
157
150
* @param \Magento\Quote\Model\Quote $cart
158
151
* @param Item $orderItem
159
152
* @return void
160
- * @throws \Magento\Framework\Exception\LocalizedException
161
153
*/
162
154
private function addOrderItem (\Magento \Quote \Model \Quote $ cart , $ orderItem ): void
163
155
{
@@ -176,7 +168,14 @@ private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): voi
176
168
);
177
169
return ;
178
170
}
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
+ }
180
179
}
181
180
}
182
181
@@ -236,15 +235,14 @@ private function prepareOutput(CartInterface $cart): Data\ReorderOutput
236
235
/**
237
236
* Add error message for a cart item
238
237
*
239
- * @param Item $item
240
- * @param string $message
238
+ * @param string $sku
239
+ * @param string|null $message
241
240
* @return string
242
241
*/
243
- private function addCartItemError (Item $ item , string $ message ): string
242
+ private function addCartItemError (string $ sku , string $ message = null ): string
244
243
{
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 ));
249
247
}
250
248
}
0 commit comments