@@ -148,16 +148,16 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
148
148
return $ this ->prepareOutput ($ cart );
149
149
}
150
150
151
- $ cartWithItems = $ this ->addItemsToCart ($ cart , $ order ->getItemsCollection ());
151
+ $ this ->addItemsToCart ($ cart , $ order ->getItemsCollection ());
152
152
153
153
try {
154
- $ this ->cartRepository ->save ($ cartWithItems );
154
+ $ this ->cartRepository ->save ($ cart );
155
155
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
156
156
// handle exception from \Magento\Quote\Model\QuoteRepository\SaveHandler::save
157
157
$ this ->addError ($ e ->getMessage ());
158
158
}
159
159
160
- $ savedCart = $ this ->cartRepository ->get ($ cartWithItems ->getId ());
160
+ $ savedCart = $ this ->cartRepository ->get ($ cart ->getId ());
161
161
162
162
return $ this ->prepareOutput ($ savedCart );
163
163
}
@@ -167,9 +167,9 @@ public function execute(string $orderNumber, string $storeId): Data\ReorderOutpu
167
167
*
168
168
* @param Quote $cart
169
169
* @param ItemCollection $orderItems
170
- * @return Quote
170
+ * @return void
171
171
*/
172
- private function addItemsToCart (Quote $ cart , ItemCollection $ orderItems ): Quote
172
+ private function addItemsToCart (Quote $ cart , ItemCollection $ orderItems ): void
173
173
{
174
174
$ orderItemProductIds = [];
175
175
/** @var \Magento\Sales\Model\Order\Item[] $orderItemsByProductId */
@@ -179,10 +179,11 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems): Quote
179
179
foreach ($ orderItems as $ item ) {
180
180
if ($ item ->getParentItem () === null ) {
181
181
$ orderItemProductIds [] = $ item ->getProductId ();
182
- $ orderItemsByProductId [$ item ->getProductId ()] = $ item ;
182
+ $ orderItemsByProductId [$ item ->getProductId ()][ $ item -> getId ()] = $ item ;
183
183
}
184
184
}
185
185
186
+ /** @var \Magento\Framework\Api\SearchCriteria $criteria */
186
187
$ criteria = $ this ->searchCriteriaBuilder
187
188
->addFilter ('entity_id ' , $ orderItemProductIds , 'in ' )
188
189
->create ();
@@ -204,11 +205,14 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems): Quote
204
205
205
206
/** @var ProductInterface $product */
206
207
foreach ($ products as $ product ) {
207
- $ orderItem = $ orderItemsByProductId [$ product ->getId ()];
208
- $ this ->addItemToCart ($ orderItem , $ cart , $ product );
208
+ if (!isset ($ orderItemsByProductId [$ product ->getId ()])) {
209
+ continue ;
210
+ }
211
+ $ orderItems = $ orderItemsByProductId [$ product ->getId ()];
212
+ foreach ($ orderItems as $ orderItem ) {
213
+ $ this ->addItemToCart ($ orderItem , $ cart , $ product );
214
+ }
209
215
}
210
-
211
- return $ cart ;
212
216
}
213
217
214
218
/**
@@ -217,9 +221,9 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems): Quote
217
221
* @param OrderItemInterface $orderItem
218
222
* @param Quote $cart
219
223
* @param ProductInterface $product
220
- * @return Quote
224
+ * @return void
221
225
*/
222
- private function addItemToCart (OrderItemInterface $ orderItem , Quote $ cart , ProductInterface $ product ): Quote
226
+ private function addItemToCart (OrderItemInterface $ orderItem , Quote $ cart , ProductInterface $ product ): void
223
227
{
224
228
$ info = $ orderItem ->getProductOptionByCode ('info_buyRequest ' );
225
229
$ info = new \Magento \Framework \DataObject ($ info );
@@ -242,8 +246,6 @@ private function addItemToCart(OrderItemInterface $orderItem, Quote $cart, Produ
242
246
$ this ->addError ($ this ->getCartItemErrorMessage ($ orderItem , $ product , $ error ));
243
247
}
244
248
}
245
-
246
- return $ cart ;
247
249
}
248
250
249
251
/**
0 commit comments