Skip to content

Commit d312613

Browse files
committed
Merge branch 'MAGETWO-35638' of https://github.corp.ebay.com/magento-firedrakes/magento2ce into MAGETWO-34647
2 parents ba9756c + 43dade1 commit d312613

File tree

9 files changed

+380
-292
lines changed

9 files changed

+380
-292
lines changed

app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,7 @@ protected function _construct()
5757
protected function _prepareCollection()
5858
{
5959
$collection = $this->_quotesFactory->create();
60-
if ($this->queryResolver->isSingleQuery()) {
61-
$collection->prepareForProductsInCarts();
62-
$collection->setSelectCountSqlType(
63-
\Magento\Reports\Model\Resource\Quote\Collection::SELECT_COUNT_SQL_TYPE_CART
64-
);
65-
} else {
66-
$collection->prepareActiveCartItems();
67-
}
60+
$collection->prepareActiveCartItems();
6861
$this->setCollection($collection);
6962
return parent::_prepareCollection();
7063
}
@@ -80,6 +73,7 @@ protected function _prepareColumns()
8073
'header' => __('ID'),
8174
'align' => 'right',
8275
'index' => 'entity_id',
76+
'sortable' => false,
8377
'header_css_class' => 'col-id',
8478
'column_css_class' => 'col-id'
8579
]
@@ -90,6 +84,7 @@ protected function _prepareColumns()
9084
[
9185
'header' => __('Product'),
9286
'index' => 'name',
87+
'sortable' => false,
9388
'header_css_class' => 'col-product',
9489
'column_css_class' => 'col-product'
9590
]
@@ -104,6 +99,7 @@ protected function _prepareColumns()
10499
'type' => 'currency',
105100
'currency_code' => $currencyCode,
106101
'index' => 'price',
102+
'sortable' => false,
107103
'renderer' => 'Magento\Reports\Block\Adminhtml\Grid\Column\Renderer\Currency',
108104
'rate' => $this->getRate($currencyCode),
109105
'header_css_class' => 'col-price',
@@ -117,6 +113,7 @@ protected function _prepareColumns()
117113
'header' => __('Carts'),
118114
'align' => 'right',
119115
'index' => 'carts',
116+
'sortable' => false,
120117
'header_css_class' => 'col-carts',
121118
'column_css_class' => 'col-carts'
122119
]
@@ -128,6 +125,7 @@ protected function _prepareColumns()
128125
'header' => __('Orders'),
129126
'align' => 'right',
130127
'index' => 'orders',
128+
'sortable' => false,
131129
'header_css_class' => 'col-qty',
132130
'column_css_class' => 'col-qty'
133131
]

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

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class Collection extends \Magento\Customer\Model\Resource\Customer\Collection
6666
*/
6767
protected $_quoteItemFactory;
6868

69+
/**
70+
* @var \Magento\Sales\Model\Resource\Order\Collection
71+
*/
72+
protected $orderResource;
73+
6974
/**
7075
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
7176
* @param \Psr\Log\LoggerInterface $logger
@@ -79,6 +84,7 @@ class Collection extends \Magento\Customer\Model\Resource\Customer\Collection
7984
* @param \Magento\Framework\Object\Copy\Config $fieldsetConfig
8085
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
8186
* @param \Magento\Quote\Model\Resource\Quote\Item\CollectionFactory $quoteItemFactory
87+
* @param \Magento\Sales\Model\Resource\Order\Collection $orderResource
8288
* @param mixed $connection
8389
* @param string $modelName
8490
*
@@ -97,6 +103,7 @@ public function __construct(
97103
\Magento\Framework\Object\Copy\Config $fieldsetConfig,
98104
\Magento\Quote\Model\QuoteRepository $quoteRepository,
99105
\Magento\Quote\Model\Resource\Quote\Item\CollectionFactory $quoteItemFactory,
106+
\Magento\Sales\Model\Resource\Order\Collection $orderResource,
100107
$connection = null,
101108
$modelName = self::CUSTOMER_MODEL_NAME
102109
) {
@@ -114,6 +121,7 @@ public function __construct(
114121
$connection,
115122
$modelName
116123
);
124+
$this->orderResource = $orderResource;
117125
$this->quoteRepository = $quoteRepository;
118126
$this->_quoteItemFactory = $quoteItemFactory;
119127
}
@@ -152,90 +160,6 @@ public function addCustomerName()
152160
return $this;
153161
}
154162

155-
/**
156-
* Order for each customer
157-
*
158-
* @param string $fromDate
159-
* @param string $toDate
160-
* @return $this
161-
*/
162-
public function joinOrders($fromDate = '', $toDate = '')
163-
{
164-
if ($fromDate != '' && $toDate != '') {
165-
$dateFilter = " AND orders.created_at BETWEEN '{$fromDate}' AND '{$toDate}'";
166-
} else {
167-
$dateFilter = '';
168-
}
169-
170-
$this->getSelect()->joinLeft(
171-
['orders' => $this->getTable('sales_order')],
172-
"orders.customer_id = e.entity_id" . $dateFilter,
173-
[]
174-
);
175-
176-
return $this;
177-
}
178-
179-
/**
180-
* Add orders count
181-
*
182-
* @return $this
183-
*/
184-
public function addOrdersCount()
185-
{
186-
$this->getSelect()->columns(
187-
["orders_count" => "COUNT(orders.entity_id)"]
188-
)->where(
189-
'orders.state <> ?',
190-
\Magento\Sales\Model\Order::STATE_CANCELED
191-
)->group(
192-
"e.entity_id"
193-
);
194-
195-
return $this;
196-
}
197-
198-
/**
199-
* Order summary info for each customer such as orders_count, orders_avg_amount, orders_total_amount
200-
*
201-
* @param int $storeId
202-
* @return $this
203-
*/
204-
public function addSumAvgTotals($storeId = 0)
205-
{
206-
$adapter = $this->getConnection();
207-
$baseSubtotalRefunded = $adapter->getIfNullSql('orders.base_subtotal_refunded', 0);
208-
$baseSubtotalCanceled = $adapter->getIfNullSql('orders.base_subtotal_canceled', 0);
209-
210-
/**
211-
* calculate average and total amount
212-
*/
213-
$expr = $storeId ==
214-
0 ?
215-
"(orders.base_subtotal - {$baseSubtotalCanceled} - {$baseSubtotalRefunded}) * orders.base_to_global_rate" :
216-
"orders.base_subtotal - {$baseSubtotalCanceled} - {$baseSubtotalRefunded}";
217-
218-
$this->getSelect()->columns(
219-
["orders_avg_amount" => "AVG({$expr})"]
220-
)->columns(
221-
["orders_sum_amount" => "SUM({$expr})"]
222-
);
223-
224-
return $this;
225-
}
226-
227-
/**
228-
* Order by total amount
229-
*
230-
* @param string $dir
231-
* @return $this
232-
*/
233-
public function orderByTotalAmount($dir = self::SORT_ORDER_DESC)
234-
{
235-
$this->getSelect()->order("orders_sum_amount {$dir}");
236-
return $this;
237-
}
238-
239163
/**
240164
* Add order statistics
241165
*
@@ -259,17 +183,17 @@ protected function _addOrdersStatistics()
259183
$customerIds = $this->getColumnValues($this->getResource()->getIdFieldName());
260184

261185
if ($this->_addOrderStatistics && !empty($customerIds)) {
262-
$adapter = $this->getConnection();
186+
$adapter = $this->orderResource->getConnection();
263187
$baseSubtotalRefunded = $adapter->getIfNullSql('orders.base_subtotal_refunded', 0);
264188
$baseSubtotalCanceled = $adapter->getIfNullSql('orders.base_subtotal_canceled', 0);
265189

266190
$totalExpr = $this->_addOrderStatFilter ?
267191
"(orders.base_subtotal-{$baseSubtotalCanceled}-{$baseSubtotalRefunded})*orders.base_to_global_rate" :
268192
"orders.base_subtotal-{$baseSubtotalCanceled}-{$baseSubtotalRefunded}";
269193

270-
$select = $this->getConnection()->select();
194+
$select = $this->orderResource->getConnection()->select();
271195
$select->from(
272-
['orders' => $this->getTable('sales_order')],
196+
['orders' => $this->orderResource->getTable('sales_order')],
273197
[
274198
'orders_avg_amount' => "AVG({$totalExpr})",
275199
'orders_sum_amount' => "SUM({$totalExpr})",
@@ -286,7 +210,7 @@ protected function _addOrdersStatistics()
286210
'orders.customer_id'
287211
);
288212

289-
foreach ($this->getConnection()->fetchAll($select) as $ordersInfo) {
213+
foreach ($this->orderResource->getConnection()->fetchAll($select) as $ordersInfo) {
290214
$this->getItemById($ordersInfo['customer_id'])->addData($ordersInfo);
291215
}
292216
}

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

Lines changed: 10 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class Collection extends \Magento\Catalog\Model\Resource\Product\Collection
5656
*/
5757
protected $_productType;
5858

59+
/**
60+
* @var \Magento\Quote\Model\Resource\Quote\Collection
61+
*/
62+
protected $quoteResource;
63+
5964
/**
6065
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
6166
* @param \Psr\Log\LoggerInterface $logger
@@ -79,6 +84,7 @@ class Collection extends \Magento\Catalog\Model\Resource\Product\Collection
7984
* @param \Magento\Catalog\Model\Resource\Product $product
8085
* @param \Magento\Reports\Model\Event\TypeFactory $eventTypeFactory
8186
* @param \Magento\Catalog\Model\Product\Type $productType
87+
* @param \Magento\Quote\Model\Resource\Quote\Collection $quoteResource
8288
* @param mixed $connection
8389
*
8490
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -106,6 +112,7 @@ public function __construct(
106112
\Magento\Catalog\Model\Resource\Product $product,
107113
\Magento\Reports\Model\Event\TypeFactory $eventTypeFactory,
108114
\Magento\Catalog\Model\Product\Type $productType,
115+
\Magento\Quote\Model\Resource\Quote\Collection $quoteResource,
109116
$connection = null
110117
) {
111118
$this->setProductEntityId($product->getEntityIdField());
@@ -135,6 +142,7 @@ public function __construct(
135142
);
136143
$this->_eventTypeFactory = $eventTypeFactory;
137144
$this->_productType = $productType;
145+
$this->quoteResource = $quoteResource;
138146
}
139147

140148
/**
@@ -239,7 +247,7 @@ protected function _joinFields()
239247
public function getSelectCountSql()
240248
{
241249
if ($this->_selectCountSqlType == self::SELECT_COUNT_SQL_TYPE_CART) {
242-
$countSelect = clone $this->getSelect();
250+
$countSelect = clone $this->quoteResource->getSelect();
243251
$countSelect->reset()->from(
244252
['quote_item_table' => $this->getTable('quote_item')],
245253
['COUNT(DISTINCT quote_item_table.product_id)']
@@ -263,102 +271,6 @@ public function getSelectCountSql()
263271
return $countSelect;
264272
}
265273

266-
/**
267-
* Add orders count
268-
*
269-
* @param string $from
270-
* @param string $to
271-
* @return $this
272-
*/
273-
public function addOrdersCount($from = '', $to = '')
274-
{
275-
$orderItemTableName = $this->getTable('sales_order_item');
276-
$productFieldName = sprintf('e.%s', $this->getProductEntityId());
277-
278-
$this->getSelect()->joinLeft(
279-
['order_items' => $orderItemTableName],
280-
"order_items.product_id = {$productFieldName}",
281-
[]
282-
)->columns(
283-
['orders' => 'COUNT(order_items2.item_id)']
284-
)->group(
285-
$productFieldName
286-
);
287-
288-
$dateFilter = ['order_items2.item_id = order_items.item_id'];
289-
if ($from != '' && $to != '') {
290-
$dateFilter[] = $this->_prepareBetweenSql('order_items2.created_at', $from, $to);
291-
}
292-
293-
$this->getSelect()->joinLeft(
294-
['order_items2' => $orderItemTableName],
295-
implode(' AND ', $dateFilter),
296-
[]
297-
);
298-
299-
return $this;
300-
}
301-
302-
/**
303-
* Add ordered qty's
304-
*
305-
* @param string $from
306-
* @param string $to
307-
* @return $this
308-
*/
309-
public function addOrderedQty($from = '', $to = '')
310-
{
311-
$adapter = $this->getConnection();
312-
$compositeTypeIds = $this->_productType->getCompositeTypes();
313-
$orderTableAliasName = $adapter->quoteIdentifier('order');
314-
315-
$orderJoinCondition = [
316-
$orderTableAliasName . '.entity_id = order_items.order_id',
317-
$adapter->quoteInto("{$orderTableAliasName}.state <> ?", \Magento\Sales\Model\Order::STATE_CANCELED),
318-
];
319-
320-
$productJoinCondition = [
321-
$adapter->quoteInto('(e.type_id NOT IN (?))', $compositeTypeIds),
322-
'e.entity_id = order_items.product_id',
323-
$adapter->quoteInto('e.attribute_set_id = ?', $this->getProductAttributeSetId()),
324-
];
325-
326-
if ($from != '' && $to != '') {
327-
$fieldName = $orderTableAliasName . '.created_at';
328-
$orderJoinCondition[] = $this->_prepareBetweenSql($fieldName, $from, $to);
329-
}
330-
331-
$this->getSelect()->reset()->from(
332-
['order_items' => $this->getTable('sales_order_item')],
333-
['ordered_qty' => 'SUM(order_items.qty_ordered)', 'order_items_name' => 'order_items.name']
334-
)->joinInner(
335-
['order' => $this->getTable('sales_order')],
336-
implode(' AND ', $orderJoinCondition),
337-
[]
338-
)->joinLeft(
339-
['e' => $this->getProductEntityTableName()],
340-
implode(' AND ', $productJoinCondition),
341-
[
342-
'entity_id' => 'order_items.product_id',
343-
'attribute_set_id' => 'e.attribute_set_id',
344-
'type_id' => 'e.type_id',
345-
'sku' => 'e.sku',
346-
'has_options' => 'e.has_options',
347-
'required_options' => 'e.required_options',
348-
'created_at' => 'e.created_at',
349-
'updated_at' => 'e.updated_at'
350-
]
351-
)->where(
352-
'parent_item_id IS NULL'
353-
)->group(
354-
'order_items.product_id'
355-
)->having(
356-
'SUM(order_items.qty_ordered) > ?',
357-
0
358-
);
359-
return $this;
360-
}
361-
362274
/**
363275
* Set order
364276
*
@@ -368,7 +280,7 @@ public function addOrderedQty($from = '', $to = '')
368280
*/
369281
public function setOrder($attribute, $dir = self::SORT_ORDER_DESC)
370282
{
371-
if (in_array($attribute, ['carts', 'orders', 'ordered_qty'])) {
283+
if (in_array($attribute, ['carts'])) {
372284
$this->getSelect()->order($attribute . ' ' . $dir);
373285
} else {
374286
parent::setOrder($attribute, $dir);

app/code/Magento/Reports/Model/Resource/Product/Lowstock/Collection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Collection extends \Magento\Reports\Model\Resource\Product\Collection
6868
* @param \Magento\Catalog\Model\Resource\Product $product
6969
* @param \Magento\Reports\Model\Event\TypeFactory $eventTypeFactory
7070
* @param \Magento\Catalog\Model\Product\Type $productType
71+
* @param \Magento\Quote\Model\Resource\Quote\Collection $quoteResource
7172
* @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
7273
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
7374
* @param \Magento\CatalogInventory\Model\Resource\Stock\Item $itemResource
@@ -98,6 +99,7 @@ public function __construct(
9899
\Magento\Catalog\Model\Resource\Product $product,
99100
\Magento\Reports\Model\Event\TypeFactory $eventTypeFactory,
100101
\Magento\Catalog\Model\Product\Type $productType,
102+
\Magento\Quote\Model\Resource\Quote\Collection $quoteResource,
101103
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
102104
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
103105
\Magento\CatalogInventory\Model\Resource\Stock\Item $itemResource,
@@ -126,6 +128,7 @@ public function __construct(
126128
$product,
127129
$eventTypeFactory,
128130
$productType,
131+
$quoteResource,
129132
$connection
130133
);
131134
$this->stockRegistry = $stockRegistry;

0 commit comments

Comments
 (0)