Skip to content

Commit e578c7c

Browse files
committed
MC-33400: [Improvement] Magento\Checkout\Model\Cart::addOrderItem
1 parent 3c33e1b commit e578c7c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,7 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems, string
183183
}
184184
}
185185

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);
197187

198188
// compare founded products and throw an error if some product not exists
199189
$productsNotFound = array_diff($orderItemProductIds, array_keys($products));
@@ -218,6 +208,28 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems, string
218208
}
219209
}
220210

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+
221233
/**
222234
* Adds order item product to cart.
223235
*

0 commit comments

Comments
 (0)