Skip to content

Commit 70dde3c

Browse files
author
valdislav
committed
MAGETWO-35638: Pull request processing
1 parent 916d07a commit 70dde3c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app/code/Magento/Reports/Model/Resource/Quote/Collection.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected function getOrdersData(array $productIds)
167167
$ordersSubSelect = clone $this->orderResource->getSelect();
168168
$ordersSubSelect->reset()->from(
169169
['oi' => $this->getTable('sales_order_item')],
170-
['orders' => new \Zend_Db_Expr('COUNT(1)'), 'product_id']
170+
['product_id', 'orders' => new \Zend_Db_Expr('COUNT(1)')]
171171
)->where('oi.product_id IN (?)', $productIds)->group(
172172
'oi.product_id'
173173
);
@@ -321,10 +321,11 @@ public function resolveCustomerNames()
321321
/**
322322
* Separate query for product and order data
323323
*
324+
* @param array $productIds
324325
* @return array
325326
* @throws \Magento\Eav\Exception
326327
*/
327-
protected function getProductData()
328+
protected function getProductData(array $productIds)
328329
{
329330
$productConnection = $this->productResource->getConnection('read');
330331
$productAttrName = $this->productResource->getAttribute('name');
@@ -348,7 +349,8 @@ protected function getProductData()
348349
['product_price' => $productAttrPrice->getBackend()->getTable()],
349350
"product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
350351
['price' => new \Zend_Db_Expr('product_price.value')]
351-
);
352+
)->where('main_table.entity_id IN (?)', $productIds);
353+
352354
$productData = $productConnection->fetchAssoc($select);
353355
return $productData;
354356
}
@@ -361,10 +363,13 @@ protected function getProductData()
361363
protected function _afterLoad()
362364
{
363365
parent::_afterLoad();
364-
$productData = $this->getProductData();
365-
$productIds = array_keys($productData);
366-
$orderData = $this->getOrdersData($productIds);
367366
$items = $this->getItems();
367+
$productIds = [];
368+
foreach ($items as $item) {
369+
$productIds[] = $item->getProductId();
370+
}
371+
$productData = $this->getProductData($productIds);
372+
$orderData = $this->getOrdersData($productIds);
368373
foreach ($items as $item) {
369374
$item->setId($item->getProductId());
370375
$item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate());

0 commit comments

Comments
 (0)