@@ -125,7 +125,7 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
125
125
126
126
$ cart = $ this ->customerCartProvider ->resolve ($ customerId );
127
127
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 );
129
129
return $ this ->prepareOutput ($ cart );
130
130
}
131
131
@@ -134,13 +134,10 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
134
134
try {
135
135
$ this ->addOrderItem ($ cart , $ item );
136
136
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
137
- $ this ->addError ($ e ->getMessage ());
137
+ $ this ->addError ($ this -> addCartItemError ( $ item , $ e ->getMessage () ));
138
138
} catch (\Throwable $ e ) {
139
139
$ 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 );
144
141
}
145
142
}
146
143
@@ -174,7 +171,7 @@ private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): voi
174
171
$ product = $ this ->productRepository ->getById ($ orderItem ->getProductId (), false , null , true );
175
172
} catch (NoSuchEntityException $ e ) {
176
173
$ 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 ()),
178
175
self ::ERROR_PRODUCT_NOT_FOUND
179
176
);
180
177
return ;
@@ -190,11 +187,11 @@ private function addOrderItem(\Magento\Quote\Model\Quote $cart, $orderItem): voi
190
187
* @param string|null $code
191
188
* @return void
192
189
*/
193
- private function addError ($ message , string $ code = null ): void
190
+ private function addError (string $ message , string $ code = null ): void
194
191
{
195
192
$ this ->errors [] = new Data \Error (
196
- ( string ) $ message ,
197
- $ code ?? $ this ->getErrorCode (( string ) $ message )
193
+ $ message ,
194
+ $ code ?? $ this ->getErrorCode ($ message )
198
195
);
199
196
}
200
197
@@ -235,4 +232,19 @@ private function prepareOutput(CartInterface $cart): Data\ReorderOutput
235
232
$ this ->errors = [];
236
233
return $ output ;
237
234
}
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
+ }
238
250
}
0 commit comments