@@ -183,17 +183,7 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems, string
183
183
}
184
184
}
185
185
186
- /** @var Collection $collection */
187
- $ collection = $ this ->productCollectionFactory ->create ();
188
-
189
- $ collection ->setStore ($ storeId );
190
- $ collection ->addIdFilter ($ orderItemProductIds );
191
- $ collection ->addStoreFilter ();
192
- $ collection ->addAttributeToSelect ('* ' );
193
- $ collection ->joinAttribute ('status ' , 'catalog_product/status ' , 'entity_id ' , null , 'inner ' );
194
- $ collection ->joinAttribute ('visibility ' , 'catalog_product/visibility ' , 'entity_id ' , null , 'inner ' );
195
-
196
- $ products = $ collection ->getItems ();
186
+ $ products = $ this ->getOrderProducts ($ storeId , $ orderItemProductIds );
197
187
198
188
// compare founded products and throw an error if some product not exists
199
189
$ productsNotFound = array_diff ($ orderItemProductIds , array_keys ($ products ));
@@ -218,6 +208,28 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems, string
218
208
}
219
209
}
220
210
211
+ /**
212
+ * Get order products by store id and order item product ids.
213
+ *
214
+ * @param string $storeId
215
+ * @param int[] $orderItemProductIds
216
+ * @return Product[]
217
+ * @throws \Magento\Framework\Exception\LocalizedException
218
+ */
219
+ private function getOrderProducts (string $ storeId , array $ orderItemProductIds ): array
220
+ {
221
+ /** @var Collection $collection */
222
+ $ collection = $ this ->productCollectionFactory ->create ();
223
+ $ collection ->setStore ($ storeId )
224
+ ->addIdFilter ($ orderItemProductIds )
225
+ ->addStoreFilter ()
226
+ ->addAttributeToSelect ('* ' )
227
+ ->joinAttribute ('status ' , 'catalog_product/status ' , 'entity_id ' , null , 'inner ' )
228
+ ->joinAttribute ('visibility ' , 'catalog_product/visibility ' , 'entity_id ' , null , 'inner ' );
229
+
230
+ return $ collection ->getItems ();
231
+ }
232
+
221
233
/**
222
234
* Adds order item product to cart.
223
235
*
0 commit comments