diff --git a/app/code/Magento/Contact/Block/ContactForm.php b/app/code/Magento/Contact/Block/ContactForm.php
new file mode 100644
index 0000000000000..907bccb5a494b
--- /dev/null
+++ b/app/code/Magento/Contact/Block/ContactForm.php
@@ -0,0 +1,24 @@
+_isScopePrivate = true;
+ }
+}
diff --git a/app/code/Magento/Contact/Test/Unit/Block/ContactFormTest.php b/app/code/Magento/Contact/Test/Unit/Block/ContactFormTest.php
new file mode 100644
index 0000000000000..446279ee14ef7
--- /dev/null
+++ b/app/code/Magento/Contact/Test/Unit/Block/ContactFormTest.php
@@ -0,0 +1,44 @@
+contextMock = $this->getMockBuilder('Magento\Framework\View\Element\Template\Context')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->contactForm = new ContactForm(
+ $this->contextMock
+ );
+ }
+
+ /**
+ * @return void
+ */
+ public function testScope()
+ {
+ $this->assertTrue($this->contactForm->isScopePrivate());
+ }
+}
diff --git a/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml b/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml
index e5e4b57692094..843206e4e00d5 100644
--- a/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml
+++ b/app/code/Magento/Contact/view/frontend/layout/contact_index_index.xml
@@ -11,7 +11,7 @@
-
+
diff --git a/app/code/Magento/Reports/Block/Adminhtml/Product/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Product/Grid.php
deleted file mode 100644
index 9d2cde108b310..0000000000000
--- a/app/code/Magento/Reports/Block/Adminhtml/Product/Grid.php
+++ /dev/null
@@ -1,137 +0,0 @@
-
- */
-class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
-{
- /**
- * @var \Magento\Reports\Model\Resource\Product\CollectionFactory
- */
- protected $_collectionFactory;
-
- /**
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\Backend\Helper\Data $backendHelper
- * @param \Magento\Reports\Model\Resource\Product\CollectionFactory $collectionFactory
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Template\Context $context,
- \Magento\Backend\Helper\Data $backendHelper,
- \Magento\Reports\Model\Resource\Product\CollectionFactory $collectionFactory,
- array $data = []
- ) {
- $this->_collectionFactory = $collectionFactory;
- parent::__construct($context, $backendHelper, $data);
- }
-
- /**
- * @return void
- */
- protected function _construct()
- {
- parent::_construct();
- $this->setId('productsReportGrid');
- $this->setDefaultSort('entity_id');
- $this->setDefaultDir('desc');
- }
-
- /**
- * @return \Magento\Backend\Block\Widget\Grid
- */
- protected function _prepareCollection()
- {
- $collection = $this->_collectionFactory->create();
- $collection->getEntity()->setStore(0);
-
- $this->setCollection($collection);
-
- return parent::_prepareCollection();
- }
-
- /**
- * @return void
- */
- protected function _afterLoadCollection()
- {
- $totalObj = new \Magento\Reports\Model\Totals();
- $this->setTotals($totalObj->countTotals($this));
- }
-
- /**
- * @return \Magento\Backend\Block\Widget\Grid\Extended
- */
- protected function _prepareColumns()
- {
- $this->addColumn(
- 'entity_id',
- ['header' => __('ID'), 'width' => '50px', 'index' => 'entity_id', 'total' => 'Total']
- );
-
- $this->addColumn('name', ['header' => __('Name'), 'index' => 'name']);
-
- $this->addColumn(
- 'viewed',
- [
- 'header' => __('Viewed'),
- 'width' => '50px',
- 'align' => 'right',
- 'index' => 'viewed',
- 'total' => 'sum'
- ]
- );
-
- $this->addColumn(
- 'added',
- ['header' => __('Added'), 'width' => '50px', 'align' => 'right', 'index' => 'added', 'total' => 'sum']
- );
-
- $this->addColumn(
- 'purchased',
- [
- 'header' => __('Purchased'),
- 'width' => '50px',
- 'align' => 'right',
- 'index' => 'purchased',
- 'total' => 'sum'
- ]
- );
-
- $this->addColumn(
- 'fulfilled',
- [
- 'header' => __('Fulfilled'),
- 'width' => '50px',
- 'align' => 'right',
- 'index' => 'fulfilled',
- 'total' => 'sum'
- ]
- );
-
- $this->addColumn(
- 'revenue',
- [
- 'header' => __('Revenue'),
- 'width' => '50px',
- 'align' => 'right',
- 'index' => 'revenue',
- 'total' => 'sum'
- ]
- );
-
- $this->setCountTotals(true);
-
- $this->addExportType('*/*/exportProductsCsv', __('CSV'));
- $this->addExportType('*/*/exportProductsExcel', __('Excel XML'));
-
- return parent::_prepareColumns();
- }
-}
diff --git a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php
index d40166dff4bb5..59d5cef6ac745 100644
--- a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php
+++ b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/Grid.php
@@ -8,6 +8,8 @@
/**
* Adminhtml abandoned shopping carts report grid block
*
+ * @method \Magento\Reports\Model\Resource\Quote\Collection getCollection
+ *
* @author Magento Core Team
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
diff --git a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php
index 347405789dc2e..53044f15068e6 100644
--- a/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php
+++ b/app/code/Magento/Reports/Block/Adminhtml/Shopcart/Product/Grid.php
@@ -16,7 +16,7 @@ class Grid extends \Magento\Reports\Block\Adminhtml\Grid\Shopcart
/**
* @var \Magento\Reports\Model\Resource\Quote\CollectionFactory
*/
- protected $_quotesFactory;
+ protected $quoteItemCollectionFactory;
/**
* @var \Magento\Quote\Model\QueryResolver
@@ -26,18 +26,18 @@ class Grid extends \Magento\Reports\Block\Adminhtml\Grid\Shopcart
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Helper\Data $backendHelper
- * @param \Magento\Reports\Model\Resource\Quote\CollectionFactoryInterface $quotesFactory
+ * @param \Magento\Reports\Model\Resource\Quote\Item\CollectionFactory $quoteItemCollectionFactory
* @param \Magento\Quote\Model\QueryResolver $queryResolver
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Helper\Data $backendHelper,
- \Magento\Reports\Model\Resource\Quote\CollectionFactoryInterface $quotesFactory,
\Magento\Quote\Model\QueryResolver $queryResolver,
+ \Magento\Reports\Model\Resource\Quote\Item\CollectionFactory $quoteItemCollectionFactory,
array $data = []
) {
- $this->_quotesFactory = $quotesFactory;
+ $this->quoteItemCollectionFactory = $quoteItemCollectionFactory;
$this->queryResolver = $queryResolver;
parent::__construct($context, $backendHelper, $data);
}
@@ -56,7 +56,8 @@ protected function _construct()
*/
protected function _prepareCollection()
{
- $collection = $this->_quotesFactory->create();
+ /** @var \Magento\Reports\Model\Resource\Quote\Item\Collection $collection */
+ $collection = $this->quoteItemCollectionFactory->create();
$collection->prepareActiveCartItems();
$this->setCollection($collection);
return parent::_prepareCollection();
@@ -68,11 +69,11 @@ protected function _prepareCollection()
protected function _prepareColumns()
{
$this->addColumn(
- 'entity_id',
+ 'product_id',
[
'header' => __('ID'),
'align' => 'right',
- 'index' => 'entity_id',
+ 'index' => 'product_id',
'sortable' => false,
'header_css_class' => 'col-id',
'column_css_class' => 'col-id'
@@ -146,6 +147,6 @@ protected function _prepareColumns()
*/
public function getRowUrl($row)
{
- return $this->getUrl('catalog/product/edit', ['id' => $row->getEntityId()]);
+ return $this->getUrl('catalog/product/edit', ['id' => $row->getProductId()]);
}
}
diff --git a/app/code/Magento/Reports/Model/Resource/Order/Collection.php b/app/code/Magento/Reports/Model/Resource/Order/Collection.php
index 0dd3a60c83761..17ff425618942 100644
--- a/app/code/Magento/Reports/Model/Resource/Order/Collection.php
+++ b/app/code/Magento/Reports/Model/Resource/Order/Collection.php
@@ -900,8 +900,8 @@ public function addCreateAtPeriodFilter($period)
$this->addFieldToFilter(
$fieldToFilter,
[
- 'from' => $from->format(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT),
- 'to' => $to->format(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT)
+ 'from' => $from->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
+ 'to' => $to->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
]
);
diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php
index ea190558cac88..fc5ed24362727 100644
--- a/app/code/Magento/Reports/Model/Resource/Quote/Collection.php
+++ b/app/code/Magento/Reports/Model/Resource/Quote/Collection.php
@@ -3,96 +3,35 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-
-// @codingStandardsIgnoreFile
-
-/**
- * Reports quote collection
- *
- * @author Magento Core Team
- */
namespace Magento\Reports\Model\Resource\Quote;
-/**
- * Class Collection
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
class Collection extends \Magento\Quote\Model\Resource\Quote\Collection
{
- const SELECT_COUNT_SQL_TYPE_CART = 1;
-
- /**
- * @var int
- */
- protected $_selectCountSqlType = 0;
-
- /**
- * Join fields
- *
- * @var array
- */
- protected $_joinedFields = [];
-
- /**
- * Map
- *
- * @var array
- */
- protected $_map = ['fields' => ['store_id' => 'main_table.store_id']];
-
- /**
- * @var \Magento\Catalog\Model\Resource\Product\Collection
- */
- protected $productResource;
-
/**
* @var \Magento\Customer\Model\Resource\Customer
*/
protected $customerResource;
/**
- * @var \Magento\Sales\Model\Resource\Order\Collection
- */
- protected $orderResource;
-
- /**
- * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
+ * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
* @param \Magento\Framework\Event\ManagerInterface $eventManager
- * @param \Magento\Catalog\Model\Resource\Product\Collection $productResource
* @param \Magento\Customer\Model\Resource\Customer $customerResource
- * @param \Magento\Sales\Model\Resource\Order\Collection $orderResource
- * @param null $connection
+ * @param \Zend_Db_Adapter_Abstract $connection
* @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource
*/
public function __construct(
- \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
+ \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
\Magento\Framework\Event\ManagerInterface $eventManager,
- \Magento\Catalog\Model\Resource\Product\Collection $productResource,
\Magento\Customer\Model\Resource\Customer $customerResource,
- \Magento\Sales\Model\Resource\Order\Collection $orderResource,
$connection = null,
\Magento\Framework\Model\Resource\Db\AbstractDb $resource = null
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
- $this->productResource = $productResource;
$this->customerResource = $customerResource;
- $this->orderResource = $orderResource;
- }
-
- /**
- * Set type for COUNT SQL select
- *
- * @param int $type
- * @return $this
- */
- public function setSelectCountSqlType($type)
- {
- $this->_selectCountSqlType = $type;
- return $this;
}
/**
@@ -129,89 +68,6 @@ public function prepareForAbandonedReport($storeIds, $filter = null)
return $this;
}
- /**
- * Prepare select query for products in carts report
- *
- * @return \Magento\Framework\DB\Select
- */
- public function prepareActiveCartItems()
- {
- $quoteItemsSelect = $this->getSelect();
- $quoteItemsSelect->reset()
- ->from(['main_table' => $this->getTable('quote')], '')
- ->columns('quote_items.product_id')
- ->columns(['carts' => new \Zend_Db_Expr('COUNT(quote_items.item_id)')])
- ->columns('main_table.base_to_global_rate')
- ->joinInner(
- ['quote_items' => $this->getTable('quote_item')],
- 'quote_items.quote_id = main_table.entity_id',
- null
- )->where(
- 'main_table.is_active = ?',
- 1
- )->group(
- 'quote_items.product_id'
- );
-
- return $quoteItemsSelect;
- }
-
- /**
- * Orders quantity data
- *
- * @param array $productIds
- * @return array
- */
- protected function getOrdersData(array $productIds)
- {
- $ordersSubSelect = clone $this->orderResource->getSelect();
- $ordersSubSelect->reset()->from(
- ['oi' => $this->getTable('sales_order_item')],
- ['product_id', 'orders' => new \Zend_Db_Expr('COUNT(1)')]
- )->where('oi.product_id IN (?)', $productIds)->group(
- 'oi.product_id'
- );
-
- return $this->orderResource->getConnection()->fetchAssoc($ordersSubSelect);
- }
-
- /**
- * Add store ids to filter
- *
- * @param array $storeIds
- * @return $this
- */
- public function addStoreFilter($storeIds)
- {
- $this->addFieldToFilter('store_id', ['in' => $storeIds]);
- return $this;
- }
-
- /**
- * Add customer data
- *
- * @param array|null $filter
- * @return $this
- */
- public function addCustomerData($filter = null)
- {
- $customersSelect = $this->customerResource->getReadConnection()->select();
- $customersSelect->from(['customer' => 'customer_entity'], 'entity_id');
- if (isset($filter['customer_name'])) {
- $customersSelect = $this->getCustomerNames($customersSelect);
- $customerName = $customersSelect->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' ');
- $customersSelect->where(
- $customerName . ' LIKE ?', '%' . $filter['customer_name'] . '%'
- );
- }
- if (isset($filter['email'])) {
- $customersSelect->where('customer.email LIKE ?', '%' . $filter['email'] . '%');
- }
- $filteredCustomers = $this->customerResource->getReadConnection()->fetchCol($customersSelect);
- $this->getSelect()->where('main_table.customer_id IN (?)', $filteredCustomers);
- return $this;
- }
-
/**
* Add subtotals
*
@@ -225,7 +81,8 @@ public function addSubtotal($storeIds = '', $filter = null)
$this->getSelect()->columns(
['subtotal' => '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)']
);
- $this->_joinedFields['subtotal'] = '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)';
+ $this->_joinedFields['subtotal'] =
+ '(main_table.base_subtotal_with_discount*main_table.base_to_global_rate)';
} else {
$this->getSelect()->columns(['subtotal' => 'main_table.base_subtotal_with_discount']);
$this->_joinedFields['subtotal'] = 'main_table.base_subtotal_with_discount';
@@ -252,17 +109,32 @@ public function addSubtotal($storeIds = '', $filter = null)
}
/**
- * Get select count sql
+ * Resolve customers data based on ids quote table.
*
- * @return \Magento\Framework\DB\Select
+ * @return void
*/
- public function getSelectCountSql()
+ public function resolveCustomerNames()
{
- $countSelect = clone $this->prepareActiveCartItems();
- $countSelect->reset(\Zend_Db_Select::COLUMNS)
- ->reset(\Zend_Db_Select::GROUP)
- ->columns('COUNT(DISTINCT quote_items.product_id)');
- return $countSelect;
+ $select = $this->customerResource->getReadConnection()->select();
+ $customerName = $select->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' ');
+
+ $select->from(
+ ['customer' => $this->customerResource->getTable('customer_entity')]
+ )->columns(
+ ['customer_name' => $customerName]
+ )->where(
+ 'customer.entity_id IN (?)',
+ array_column(
+ $this->getData(),
+ 'customer_id'
+ )
+ );
+ $customersData = $select->getAdapter()->fetchAll($this->getCustomerNames($select));
+
+ foreach ($this->getItems() as $item) {
+ $item->setData(array_merge($item->getData(), current($customersData)));
+ next($customersData);
+ }
}
/**
@@ -286,100 +158,12 @@ protected function getCustomerNames($select)
'customer.entity_id = cust_lname.entity_id',
['lastname' => 'cust_lname.value']
)->where(
- 'cust_fname.attribute_id = ?', (int)$attrFirstnameId
+ 'cust_fname.attribute_id = ?',
+ (int)$attrFirstnameId
)->where(
- 'cust_lname.attribute_id = ?', (int)$attrLastnameId
+ 'cust_lname.attribute_id = ?',
+ (int)$attrLastnameId
);
return $select;
}
-
- /**
- * Resolve customers data based on ids quote table.
- *
- * @return void
- */
- public function resolveCustomerNames()
- {
- $select = $this->customerResource->getReadConnection()->select();
- $customerName = $select->getAdapter()->getConcatSql(['cust_fname.value', 'cust_lname.value'], ' ');
-
- $select->from(
- ['customer' => 'customer_entity']
- )->columns(
- ['customer_name' => $customerName]
- )->where(
- 'customer.entity_id IN (?)', array_column($this->getData(), 'customer_id')
- );
- $customersData = $select->getAdapter()->fetchAll($this->getCustomerNames($select));
-
- foreach($this->getItems() as $item) {
- $item->setData(array_merge($item->getData(), current($customersData)));
- next($customersData);
- }
- }
-
- /**
- * Separate query for product and order data
- *
- * @param array $productIds
- * @return array
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- protected function getProductData(array $productIds)
- {
- $productConnection = $this->productResource->getConnection('read');
- $productAttrName = $this->productResource->getAttribute('name');
- $productAttrNameId = (int)$productAttrName->getAttributeId();
- $productAttrPrice = $this->productResource->getAttribute('price');
- $productAttrPriceId = (int)$productAttrPrice->getAttributeId();
-
- $select = clone $this->productResource->getSelect();
- $select->reset();
- $select->from(
- ['main_table' => $this->getTable('catalog_product_entity')]
- )->useStraightJoin(
- true
- )->joinInner(
- ['product_name' => $productAttrName->getBackend()->getTable()],
- 'product_name.entity_id = main_table.entity_id'
- . ' AND product_name.attribute_id = ' . $productAttrNameId
- . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
- ['name' => 'product_name.value']
- )->joinInner(
- ['product_price' => $productAttrPrice->getBackend()->getTable()],
- "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
- ['price' => new \Zend_Db_Expr('product_price.value')]
- )->where('main_table.entity_id IN (?)', $productIds);
-
- $productData = $productConnection->fetchAssoc($select);
- return $productData;
- }
-
- /**
- * Add data fetched from another database
- *
- * @return $this
- */
- protected function _afterLoad()
- {
- parent::_afterLoad();
- $items = $this->getItems();
- $productIds = [];
- foreach ($items as $item) {
- $productIds[] = $item->getProductId();
- }
- $productData = $this->getProductData($productIds);
- $orderData = $this->getOrdersData($productIds);
- foreach ($items as $item) {
- $item->setId($item->getProductId());
- $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate());
- $item->setName($productData[$item->getProductId()]['name']);
- $item->setOrders(0);
- if (isset($orderData[$item->getProductId()])) {
- $item->setOrders($orderData[$item->getProductId()]['orders']);
- }
- }
-
- return $this;
- }
}
diff --git a/app/code/Magento/Reports/Model/Resource/Quote/Item/Collection.php b/app/code/Magento/Reports/Model/Resource/Quote/Item/Collection.php
new file mode 100644
index 0000000000000..63c1a45f5132c
--- /dev/null
+++ b/app/code/Magento/Reports/Model/Resource/Quote/Item/Collection.php
@@ -0,0 +1,227 @@
+ ['store_id' => 'main_table.store_id']];
+
+ /**
+ * @var \Magento\Catalog\Model\Resource\Product\Collection
+ */
+ protected $productResource;
+
+ /**
+ * @var \Magento\Customer\Model\Resource\Customer
+ */
+ protected $customerResource;
+
+ /**
+ * @var \Magento\Sales\Model\Resource\Order\Collection
+ */
+ protected $orderResource;
+
+ /**
+ * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
+ * @param \Psr\Log\LoggerInterface $logger
+ * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
+ * @param \Magento\Framework\Event\ManagerInterface $eventManager
+ * @param \Magento\Catalog\Model\Resource\Product\Collection $productResource
+ * @param \Magento\Customer\Model\Resource\Customer $customerResource
+ * @param \Magento\Sales\Model\Resource\Order\Collection $orderResource
+ * @param \Zend_Db_Adapter_Abstract $connection
+ * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource
+ */
+ public function __construct(
+ \Magento\Framework\Data\Collection\EntityFactory $entityFactory,
+ \Psr\Log\LoggerInterface $logger,
+ \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
+ \Magento\Framework\Event\ManagerInterface $eventManager,
+ \Magento\Catalog\Model\Resource\Product\Collection $productResource,
+ \Magento\Customer\Model\Resource\Customer $customerResource,
+ \Magento\Sales\Model\Resource\Order\Collection $orderResource,
+ $connection = null,
+ \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null
+ ) {
+ parent::__construct(
+ $entityFactory,
+ $logger,
+ $fetchStrategy,
+ $eventManager,
+ $connection,
+ $resource
+ );
+ $this->productResource = $productResource;
+ $this->customerResource = $customerResource;
+ $this->orderResource = $orderResource;
+ }
+
+ /**
+ * Resource initialization
+ *
+ * @return void
+ */
+ protected function _construct()
+ {
+ $this->_init('Magento\Quote\Model\Quote\Item', 'Magento\Quote\Model\Resource\Quote\Item');
+ }
+
+
+ /**
+ * Prepare select query for products in carts report
+ *
+ * @return \Magento\Framework\DB\Select
+ */
+ public function prepareActiveCartItems()
+ {
+ $quoteItemsSelect = $this->getSelect();
+ $quoteItemsSelect->reset()
+ ->from(['main_table' => $this->getTable('quote_item')], '')
+ ->columns('main_table.product_id')
+ ->columns(['carts' => new \Zend_Db_Expr('COUNT(main_table.item_id)')])
+ ->columns('quote.base_to_global_rate')
+ ->joinInner(
+ ['quote' => $this->getTable('quote')],
+ 'main_table.quote_id = quote.entity_id',
+ null
+ )->where(
+ 'quote.is_active = ?',
+ 1
+ )->group(
+ 'main_table.product_id'
+ );
+
+ return $quoteItemsSelect;
+ }
+
+ /**
+ * Orders quantity data
+ *
+ * @param array $productIds
+ * @return array
+ */
+ protected function getOrdersData(array $productIds)
+ {
+ $ordersSubSelect = clone $this->orderResource->getSelect();
+ $ordersSubSelect->reset()->from(
+ ['oi' => $this->getTable('sales_order_item')],
+ ['product_id', 'orders' => new \Zend_Db_Expr('COUNT(1)')]
+ )->where('oi.product_id IN (?)', $productIds)->group(
+ 'oi.product_id'
+ );
+
+ return $this->orderResource->getConnection()->fetchAssoc($ordersSubSelect);
+ }
+
+ /**
+ * Add store ids to filter
+ *
+ * @param array $storeIds
+ * @return $this
+ */
+ public function addStoreFilter($storeIds)
+ {
+ $this->addFieldToFilter('store_id', ['in' => $storeIds]);
+ return $this;
+ }
+
+ /**
+ * Get select count sql
+ *
+ * @return \Magento\Framework\DB\Select
+ */
+ public function getSelectCountSql()
+ {
+ $countSelect = clone $this->prepareActiveCartItems();
+ $countSelect->reset(\Zend_Db_Select::COLUMNS)
+ ->reset(\Zend_Db_Select::GROUP)
+ ->columns('COUNT(DISTINCT main_table.product_id)');
+ return $countSelect;
+ }
+
+ /**
+ * Separate query for product and order data
+ *
+ * @param array $productIds
+ * @return array
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ protected function getProductData(array $productIds)
+ {
+ $productConnection = $this->productResource->getConnection('read');
+ $productAttrName = $this->productResource->getAttribute('name');
+ $productAttrNameId = (int)$productAttrName->getAttributeId();
+ $productAttrPrice = $this->productResource->getAttribute('price');
+ $productAttrPriceId = (int)$productAttrPrice->getAttributeId();
+
+ $select = clone $this->productResource->getSelect();
+ $select->reset();
+ $select->from(
+ ['main_table' => $this->getTable('catalog_product_entity')]
+ )->useStraightJoin(
+ true
+ )->joinInner(
+ ['product_name' => $productAttrName->getBackend()->getTable()],
+ 'product_name.entity_id = main_table.entity_id'
+ . ' AND product_name.attribute_id = ' . $productAttrNameId
+ . ' AND product_name.store_id = ' . \Magento\Store\Model\Store::DEFAULT_STORE_ID,
+ ['name' => 'product_name.value']
+ )->joinInner(
+ ['product_price' => $productAttrPrice->getBackend()->getTable()],
+ "product_price.entity_id = main_table.entity_id AND product_price.attribute_id = {$productAttrPriceId}",
+ ['price' => new \Zend_Db_Expr('product_price.value')]
+ )->where('main_table.entity_id IN (?)', $productIds);
+
+ $productData = $productConnection->fetchAssoc($select);
+ return $productData;
+ }
+
+ /**
+ * Add data fetched from another database
+ *
+ * @return $this
+ */
+ protected function _afterLoad()
+ {
+ parent::_afterLoad();
+ $items = $this->getItems();
+ $productIds = [];
+ foreach ($items as $item) {
+ $productIds[] = $item->getProductId();
+ }
+ $productData = $this->getProductData($productIds);
+ $orderData = $this->getOrdersData($productIds);
+ foreach ($items as $item) {
+ $item->setId($item->getProductId());
+ $item->setPrice($productData[$item->getProductId()]['price'] * $item->getBaseToGlobalRate());
+ $item->setName($productData[$item->getProductId()]['name']);
+ $item->setOrders(0);
+ if (isset($orderData[$item->getProductId()])) {
+ $item->setOrders($orderData[$item->getProductId()]['orders']);
+ }
+ }
+
+ return $this;
+ }
+}
diff --git a/app/code/Magento/Reports/Model/Resource/Report/Collection.php b/app/code/Magento/Reports/Model/Resource/Report/Collection.php
index c8ee5836cf242..641b5704a92e0 100644
--- a/app/code/Magento/Reports/Model/Resource/Report/Collection.php
+++ b/app/code/Magento/Reports/Model/Resource/Report/Collection.php
@@ -174,7 +174,7 @@ protected function _getDayInterval(\DateTime $dateStart)
\IntlDateFormatter::SHORT,
\IntlDateFormatter::NONE
),
- 'start' => $dateStart->format('Y-m-d H:i:s'),
+ 'start' => $dateStart->format('Y-m-d 00:00:00'),
'end' => $dateStart->format('Y-m-d 23:59:59'),
];
return $interval;
diff --git a/app/code/Magento/Reports/Model/Totals.php b/app/code/Magento/Reports/Model/Totals.php
deleted file mode 100644
index 75fbaaed53317..0000000000000
--- a/app/code/Magento/Reports/Model/Totals.php
+++ /dev/null
@@ -1,76 +0,0 @@
-
- */
-class Totals
-{
- /**
- * Retrieve count totals
- *
- * @param \Magento\Backend\Block\Widget\Grid $grid
- * @param string $from
- * @param string $to
- * @return \Magento\Framework\Object
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- public function countTotals($grid, $from, $to)
- {
- $columns = [];
- foreach ($grid->getColumns() as $col) {
- $columns[$col->getIndex()] = ["total" => $col->getTotal(), "value" => 0];
- }
-
- $count = 0;
- /**
- * This method doesn't work because of commit 6e15235, see MAGETWO-4751
- */
- $report = $grid->getCollection()->getReportFull($from, $to);
- foreach ($report as $item) {
- if ($grid->getSubReportSize() && $count >= $grid->getSubReportSize()) {
- continue;
- }
- $data = $item->getData();
-
- foreach ($columns as $field => $a) {
- if ($field !== '') {
- $columns[$field]['value'] = $columns[$field]['value'] + (isset($data[$field]) ? $data[$field] : 0);
- }
- }
- $count++;
- }
- $data = [];
- foreach ($columns as $field => $a) {
- if ($a['total'] == 'avg') {
- if ($field !== '') {
- if ($count != 0) {
- $data[$field] = $a['value'] / $count;
- } else {
- $data[$field] = 0;
- }
- }
- } elseif ($a['total'] == 'sum') {
- if ($field !== '') {
- $data[$field] = $a['value'];
- }
- } elseif (strpos($a['total'], '/') !== false) {
- if ($field !== '') {
- $data[$field] = 0;
- }
- }
- }
-
- $totals = new \Magento\Framework\Object();
- $totals->setData($data);
-
- return $totals;
- }
-}
diff --git a/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php
index d3b7eadd6da68..9e9363ce7bfd0 100644
--- a/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php
+++ b/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/Quote/CollectionTest.php
@@ -33,17 +33,17 @@ public function testGetSelectCountSql()
->getConstructArguments('Magento\Reports\Model\Resource\Quote\Collection');
$collection = $this->getMock(
'Magento\Reports\Model\Resource\Quote\Collection',
- ['prepareActiveCartItems', 'getSelect'],
+ ['getSelect'],
$constructArgs,
'',
false
);
- $collection->expects($this->once())->method('prepareActiveCartItems')->willReturn($this->selectMock);
+ $collection->expects($this->once())->method('getSelect')->willReturn($this->selectMock);
$this->selectMock->expects($this->atLeastOnce())->method('reset')->willReturnSelf();
$this->selectMock->expects($this->once())
->method('columns')
- ->with('COUNT(DISTINCT quote_items.product_id)')
+ ->with('COUNT(*)')
->willReturnSelf();
$this->assertEquals($this->selectMock, $collection->getSelectCountSql());
}
@@ -52,9 +52,9 @@ public function testPrepareActiveCartItems()
{
/** @var $collection \PHPUnit_Framework_MockObject_MockObject */
$constructArgs = $this->objectManager
- ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Collection');
+ ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Item\Collection');
$collection = $this->getMock(
- 'Magento\Reports\Model\Resource\Quote\Collection',
+ 'Magento\Reports\Model\Resource\Quote\Item\Collection',
['getSelect', 'getTable'],
$constructArgs,
'',
@@ -76,7 +76,7 @@ public function testLoadWithFilter()
{
/** @var $collection \PHPUnit_Framework_MockObject_MockObject */
$constructArgs = $this->objectManager
- ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Collection');
+ ->getConstructArguments('Magento\Reports\Model\Resource\Quote\Item\Collection');
$constructArgs['eventManager'] = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false);
$readConnectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false);
$resourceMock = $this->getMock('\Magento\Quote\Model\Resource\Quote', [], [], '', false);
@@ -87,7 +87,7 @@ public function testLoadWithFilter()
$constructArgs['orderResource'] = $orderResourceMock;
$collection = $this->getMock(
- 'Magento\Reports\Model\Resource\Quote\Collection',
+ 'Magento\Reports\Model\Resource\Quote\Item\Collection',
[
'_beforeLoad',
'_renderFilters',
diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php
index 5462dd5b09991..d9a4d886c26c1 100644
--- a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php
+++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Sales/Sales/GridTest.php
@@ -80,7 +80,7 @@ public function testGetCountTotals($from, $to, $expectedResult)
$block->setFilterData($filterData);
$block->toHtml();
- $this->assertEquals($block->getCountTotals(), $expectedResult);
+ $this->assertEquals($expectedResult, $block->getCountTotals());
}
/**
@@ -90,9 +90,10 @@ public function testGetCountTotals($from, $to, $expectedResult)
*/
public function getCountTotalsDataProvider()
{
+ $time = time();
return [
- [date("Y-m-d", time() + 24 * 60 * 60), date("Y-m-d", time() + 48 * 60 * 60), false],
- [date("Y-m-d", time() - 24 * 60 * 60), date("Y-m-d", time() + 24 * 60 * 60), true],
+ [date("Y-m-d", $time + 48 * 60 * 60), date("Y-m-d", $time + 72 * 60 * 60), false],
+ [date("Y-m-d", $time - 48 * 60 * 60), date("Y-m-d", $time + 48 * 60 * 60), true],
[null, null, false],
];
}
diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php
new file mode 100644
index 0000000000000..c5e7f6fd6978c
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Abandoned/GridTest.php
@@ -0,0 +1,37 @@
+get('Magento\Framework\View\LayoutInterface');
+ /** @var Grid $grid */
+ $grid = $layout->createBlock('Magento\Reports\Block\Adminhtml\Shopcart\Abandoned\Grid');
+ $result = $grid->getPreparedCollection();
+
+ $this->assertCount(1, $result->getItems());
+ /** @var Quote $quote */
+ $quote = $result->getFirstItem();
+ $this->assertEquals('customer@example.com', $quote->getCustomerEmail());
+ $this->assertEquals(10.00, $quote->getSubtotal());
+ }
+}
diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/GridTestAbstract.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/GridTestAbstract.php
new file mode 100644
index 0000000000000..42c3700c1d1a5
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/GridTestAbstract.php
@@ -0,0 +1,32 @@
+create('Magento\Customer\Api\CustomerRepositoryInterface');
+ $customerData = $customerRepository->getById(1);
+
+ /** @var Quote $quoteFixture */
+ $quoteFixture = $objectManager->create('Magento\Quote\Model\Quote');
+ $quoteFixture->load('test01', 'reserved_order_id');
+ $quoteFixture->setIsActive(true);
+ $quoteFixture->setCustomer($customerData);
+ $quoteFixture->save();
+ }
+}
diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Product/GridTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Product/GridTest.php
new file mode 100644
index 0000000000000..204b1b64c7106
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Shopcart/Product/GridTest.php
@@ -0,0 +1,39 @@
+get('Magento\Framework\View\LayoutInterface');
+ /** @var Grid $grid */
+ $grid = $layout->createBlock('Magento\Reports\Block\Adminhtml\Shopcart\Product\Grid');
+ $result = $grid->getPreparedCollection();
+
+ $this->assertCount(1, $result->getItems());
+ /** @var Item $quoteItem */
+ $quoteItem = $result->getFirstItem();
+ $this->assertInstanceOf('Magento\Quote\Model\Quote\Item', $quoteItem);
+
+ $this->assertEquals(1, $quoteItem->getProductId());
+ $this->assertEquals('Simple Product', $quoteItem->getName());
+ }
+}
diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
index 59cf16d245655..7f76c862105e0 100755
--- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
+++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
@@ -3161,6 +3161,8 @@
['Magento\Framework\Exception\File\ValidatorException'],
['Magento\Framework\Filesystem\FilesystemException', 'Magento\Framework\Exception\FileSystemException'],
['Magento\Shipping\Exception'],
+ ['Magento\Reports\Block\Adminhtml\Product\Grid'],
+ ['Magento\Reports\Model\Totals'],
['Magento\Log\Model\Shell'],
['Magento\Log\App\Shell'],
['Magento\Framework\App\Cache\ManagerApp'],
diff --git a/dev/tools/performance-toolkit/fixtures/orders.php b/dev/tools/performance-toolkit/fixtures/orders.php
index 041fcea755125..db077ab2fbbdd 100644
--- a/dev/tools/performance-toolkit/fixtures/orders.php
+++ b/dev/tools/performance-toolkit/fixtures/orders.php
@@ -190,7 +190,9 @@ public function execute()
$country = 'US';
$zip = '11111';
$phone = '911';
- $time = date("Y-m-d h:i:s");
+ $dateStart = new \DateTime();
+ $dateStart->setTimezone(new \DateTimeZone('Etc/UTC'));
+ $time = $dateStart->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
$simpleProductIdLen[0] = strlen($simpleProductId[0]($entityId));
$simpleProductIdLen[1] = strlen($simpleProductId[1]($entityId));