diff --git a/app/code/Magento/Reports/Model/Resource/Helper.php b/app/code/Magento/Reports/Model/Resource/Helper.php index 08387fcd26d8ced85ade91d97758b45dddecef3b..28c78260fb24c6f69755ad1b109a2362e8473699 100644 --- a/app/code/Magento/Reports/Model/Resource/Helper.php +++ b/app/code/Magento/Reports/Model/Resource/Helper.php @@ -39,15 +39,15 @@ class Helper extends \Magento\Framework\DB\Helper implements \Magento\Reports\Mo /** * Update rating position * - * @param string $type day|month|year + * @param string $adapter + * @param string $type * @param string $column * @param string $mainTable - * @param string $aggregationTable + * @param $aggregationTable * @return $this */ - public function updateReportRatingPos($type, $column, $mainTable, $aggregationTable) + public function updateReportRatingPos($adapter, $type, $column, $mainTable, $aggregationTable) { - $adapter = $this->_getWriteAdapter(); $periodSubSelect = $adapter->select(); $ratingSubSelect = $adapter->select(); $ratingSelect = $adapter->select(); diff --git a/app/code/Magento/Reports/Model/Resource/HelperInterface.php b/app/code/Magento/Reports/Model/Resource/HelperInterface.php index efac474d6d53cd191dbda7619ececade1aa79b5f..9a836b234967b5cf1ab8bba8df4dd92f08b03e5c 100644 --- a/app/code/Magento/Reports/Model/Resource/HelperInterface.php +++ b/app/code/Magento/Reports/Model/Resource/HelperInterface.php @@ -24,11 +24,12 @@ interface HelperInterface /** * Update rating position * - * @param string $type day|month|year - * @param string $column - * @param string $mainTable - * @param string $aggregationTable - * @return \Magento\Framework\DB\Helper\AbstractHelper + * @param $adapter + * @param $type + * @param $column + * @param $mainTable + * @param $aggregationTable + * @return mixed */ - public function updateReportRatingPos($type, $column, $mainTable, $aggregationTable); + public function updateReportRatingPos($adapter, $type, $column, $mainTable, $aggregationTable); } diff --git a/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php b/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php index 9ebd26efbd7e7dc3edd48e5e8a00dc901ec666ab..74e6f7c80d6078759ad73074c96297843dd4942d 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php +++ b/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php @@ -222,12 +222,28 @@ class Viewed extends \Magento\Sales\Model\Resource\Report\AbstractReport $insertQuery = $select->insertFromSelect($this->getMainTable(), array_keys($columns)); $adapter->query($insertQuery); - $this->_resourceHelper->updateReportRatingPos('day', 'views_num', $mainTable, $this->getTable(self::AGGREGATION_DAILY)); - $this->_resourceHelper->updateReportRatingPos('month', 'views_num', $mainTable, $this->getTable(self::AGGREGATION_MONTHLY)); - $this->_resourceHelper->updateReportRatingPos('year', 'views_num', $mainTable, $this->getTable(self::AGGREGATION_YEARLY)); - + $this->_resourceHelper->updateReportRatingPos( + $adapter, + 'day', + 'views_num', + $mainTable, + $this->getTable(self::AGGREGATION_DAILY) + ); + $this->_resourceHelper->updateReportRatingPos( + $adapter, + 'month', + 'views_num', + $mainTable, + $this->getTable(self::AGGREGATION_MONTHLY) + ); + $this->_resourceHelper->updateReportRatingPos( + $adapter, + 'year', + 'views_num', + $mainTable, + $this->getTable(self::AGGREGATION_YEARLY) + ); $this->_setFlagData(\Magento\Reports\Model\Flag::REPORT_PRODUCT_VIEWED_FLAG_CODE); - return $this; } } diff --git a/app/code/Magento/Sales/Model/Resource/Helper.php b/app/code/Magento/Sales/Model/Resource/Helper.php index 958b798694b8037c3a4c0899d001dc5271cc4574..d5aa62d239d22d957a5858c2ba65e364dbbe4b89 100644 --- a/app/code/Magento/Sales/Model/Resource/Helper.php +++ b/app/code/Magento/Sales/Model/Resource/Helper.php @@ -44,17 +44,31 @@ class Helper extends \Magento\Framework\DB\Helper implements HelperInterface $mainTable, $aggregationTable ) { + $adapter = $this->_resource->getConnection('sales_write'); if ($aggregation == $aggregationAliases['monthly']) { $this->_reportsResourceHelper->updateReportRatingPos( + $adapter, 'month', 'qty_ordered', $mainTable, $aggregationTable ); } elseif ($aggregation == $aggregationAliases['yearly']) { - $this->_reportsResourceHelper->updateReportRatingPos('year', 'qty_ordered', $mainTable, $aggregationTable); + $this->_reportsResourceHelper->updateReportRatingPos( + $adapter, + 'year', + 'qty_ordered', + $mainTable, + $aggregationTable + ); } else { - $this->_reportsResourceHelper->updateReportRatingPos('day', 'qty_ordered', $mainTable, $aggregationTable); + $this->_reportsResourceHelper->updateReportRatingPos( + $adapter, + 'day', + 'qty_ordered', + $mainTable, + $aggregationTable + ); } return $this; diff --git a/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php b/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php index 43d3b6911072c8b354383f9dd07b9598a9d12eeb..269266158968000964b00f096d8703e0d3ff86c4 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php @@ -134,26 +134,8 @@ class Bestsellers extends AbstractReport 'period' => $periodExpr, 'store_id' => 'source_table.store_id', 'product_id' => 'order_item.product_id', - 'product_name' => new \Zend_Db_Expr( - sprintf('MIN(%s)', $adapter->getIfNullSql('product_name.value', 'product_default_name.value')) - ), - 'product_price' => new \Zend_Db_Expr( - sprintf( - '%s * %s', - new \Zend_Db_Expr( - sprintf( - 'MIN(%s)', - $adapter->getIfNullSql( - $adapter->getIfNullSql('product_price.value', 'product_default_price.value'), - 0 - ) - ) - ), - new \Zend_Db_Expr( - sprintf('MIN(%s)', $adapter->getIfNullSql('source_table.base_to_global_rate', '0')) - ) - ) - ), + 'product_name' => new \Zend_Db_Expr('MIN(order_item.name)'), + 'product_price' => new \Zend_Db_Expr('MIN(order_item.base_price) * MIN(source_table.base_to_global_rate)'), 'qty_ordered' => new \Zend_Db_Expr('SUM(order_item.qty_ordered)'), ]; @@ -167,61 +149,8 @@ class Bestsellers extends AbstractReport )->where( 'source_table.state != ?', \Magento\Sales\Model\Order::STATE_CANCELED - ); - - $joinExpr = [ - 'product.entity_id = order_item.product_id', - $adapter->quoteInto('product.type_id NOT IN(?)', $this->ignoredProductTypes), - ]; - - $joinExpr = implode(' AND ', $joinExpr); - $select->joinInner(['product' => $this->getTable('catalog_product_entity')], $joinExpr, []); - - // join product attributes Name & Price - $attr = $this->_productResource->getAttribute('name'); - $joinExprProductName = [ - 'product_name.entity_id = product.entity_id', - 'product_name.store_id = source_table.store_id', - $adapter->quoteInto('product_name.attribute_id = ?', $attr->getAttributeId()), - ]; - $joinExprProductName = implode(' AND ', $joinExprProductName); - $joinProductName = [ - 'product_default_name.entity_id = product.entity_id', - 'product_default_name.store_id = 0', - $adapter->quoteInto('product_default_name.attribute_id = ?', $attr->getAttributeId()), - ]; - $joinProductName = implode(' AND ', $joinProductName); - $select->joinLeft( - ['product_name' => $attr->getBackend()->getTable()], - $joinExprProductName, - [] - )->joinLeft( - ['product_default_name' => $attr->getBackend()->getTable()], - $joinProductName, - [] - ); - $attr = $this->_productResource->getAttribute('price'); - $joinExprProductPrice = [ - 'product_price.entity_id = product.entity_id', - 'product_price.store_id = source_table.store_id', - $adapter->quoteInto('product_price.attribute_id = ?', $attr->getAttributeId()), - ]; - $joinExprProductPrice = implode(' AND ', $joinExprProductPrice); - - $joinProductPrice = [ - 'product_default_price.entity_id = product.entity_id', - 'product_default_price.store_id = 0', - $adapter->quoteInto('product_default_price.attribute_id = ?', $attr->getAttributeId()), - ]; - $joinProductPrice = implode(' AND ', $joinProductPrice); - $select->joinLeft( - ['product_price' => $attr->getBackend()->getTable()], - $joinExprProductPrice, - [] - )->joinLeft( - ['product_default_price' => $attr->getBackend()->getTable()], - $joinProductPrice, - [] + )->where( + 'order_item.product_type NOT IN(?)', $this->ignoredProductTypes ); if ($subSelect !== null) { diff --git a/app/code/Magento/Sales/etc/di.xml b/app/code/Magento/Sales/etc/di.xml index 4c103a22dfeac23baa5d7ae31b49d560eddcf6b9..eeee3d72fc70325b74b14ff5a10befc3934ffc00 100644 --- a/app/code/Magento/Sales/etc/di.xml +++ b/app/code/Magento/Sales/etc/di.xml @@ -205,4 +205,14 @@ <argument name="resourcePrefix" xsi:type="string">sales</argument> </arguments> </type> + <type name="Magento\Sales\Model\Resource\Report\Order\Createdat"> + <arguments> + <argument name="resourcePrefix" xsi:type="string">sales</argument> + </arguments> + </type> + <type name="Magento\Sales\Model\Resource\Report\Bestsellers"> + <arguments> + <argument name="resourcePrefix" xsi:type="string">sales</argument> + </arguments> + </type> </config>