diff --git a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php index badb6be8877..6b03b957bf8 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php @@ -168,7 +168,7 @@ protected function _prepareSummaryLive($range, $customStart, $customEnd, $isFilt $this->getSelect() ->columns([ - 'quantity' => 'COUNT(main_table.entity_id)', + 'quantity' => new Zend_Db_Expr('COUNT(main_table.entity_id)'), 'range' => $tzRangeOffsetExpression, ]) ->where('main_table.state NOT IN (?)', [ @@ -203,8 +203,8 @@ protected function _prepareSummaryAggregated($range, $customStart, $customEnd) $rangePeriod2 = str_replace($tableName, "MIN($tableName)", $rangePeriod); $this->getSelect()->columns([ - 'revenue' => 'SUM(main_table.total_revenue_amount)', - 'quantity' => 'SUM(main_table.orders_count)', + 'revenue' => new Zend_Db_Expr('SUM(main_table.total_revenue_amount)'), + 'quantity' => new Zend_Db_Expr('SUM(main_table.orders_count)'), 'range' => $rangePeriod2, ]) ->order('range') @@ -512,7 +512,7 @@ public function calculateSales($isFilter = 0) 0 ); $this->getSelect()->columns([ - 'lifetime' => 'SUM(main_table.total_revenue_amount)', + 'lifetime' => new Zend_Db_Expr('SUM(main_table.total_revenue_amount)'), 'average' => $averageExpr ]); @@ -535,8 +535,8 @@ public function calculateSales($isFilter = 0) $this->getSelect() ->columns([ - 'lifetime' => "SUM({$expr})", - 'average' => "AVG({$expr})" + 'lifetime' => new Zend_Db_Expr("SUM({$expr})"), + 'average' => new Zend_Db_Expr("AVG({$expr})") ]) ->where('main_table.status NOT IN(?)', $statuses) ->where('main_table.state NOT IN(?)', [ @@ -584,31 +584,31 @@ public function setStoreIds($storeIds) $baseTotalInvocedCost = $adapter->getIfNullSql('main_table.base_total_invoiced_cost', 0); if ($storeIds) { $this->getSelect()->columns([ - 'subtotal' => 'SUM(main_table.base_subtotal)', - 'tax' => 'SUM(main_table.base_tax_amount)', - 'shipping' => 'SUM(main_table.base_shipping_amount)', - 'discount' => 'SUM(main_table.base_discount_amount)', - 'total' => 'SUM(main_table.base_grand_total)', - 'invoiced' => 'SUM(main_table.base_total_paid)', - 'refunded' => 'SUM(main_table.base_total_refunded)', - 'profit' => "SUM($baseSubtotalInvoiced) " + 'subtotal' => new Zend_Db_Expr('SUM(main_table.base_subtotal)'), + 'tax' => new Zend_Db_Expr('SUM(main_table.base_tax_amount)'), + 'shipping' => new Zend_Db_Expr('SUM(main_table.base_shipping_amount)'), + 'discount' => new Zend_Db_Expr('SUM(main_table.base_discount_amount)'), + 'total' => new Zend_Db_Expr('SUM(main_table.base_grand_total)'), + 'invoiced' => new Zend_Db_Expr('SUM(main_table.base_total_paid)'), + 'refunded' => new Zend_Db_Expr('SUM(main_table.base_total_refunded)'), + 'profit' => new Zend_Db_Expr("SUM($baseSubtotalInvoiced) " . "+ SUM({$baseDiscountRefunded}) - SUM({$baseSubtotalRefunded}) " - . "- SUM({$baseDiscountInvoiced}) - SUM({$baseTotalInvocedCost})" + . "- SUM({$baseDiscountInvoiced}) - SUM({$baseTotalInvocedCost})") ]); } else { $this->getSelect()->columns([ - 'subtotal' => 'SUM(main_table.base_subtotal * main_table.base_to_global_rate)', - 'tax' => 'SUM(main_table.base_tax_amount * main_table.base_to_global_rate)', - 'shipping' => 'SUM(main_table.base_shipping_amount * main_table.base_to_global_rate)', - 'discount' => 'SUM(main_table.base_discount_amount * main_table.base_to_global_rate)', - 'total' => 'SUM(main_table.base_grand_total * main_table.base_to_global_rate)', - 'invoiced' => 'SUM(main_table.base_total_paid * main_table.base_to_global_rate)', - 'refunded' => 'SUM(main_table.base_total_refunded * main_table.base_to_global_rate)', - 'profit' => "SUM({$baseSubtotalInvoiced} * main_table.base_to_global_rate) " + 'subtotal' => new Zend_Db_Expr('SUM(main_table.base_subtotal * main_table.base_to_global_rate)'), + 'tax' => new Zend_Db_Expr('SUM(main_table.base_tax_amount * main_table.base_to_global_rate)'), + 'shipping' => new Zend_Db_Expr('SUM(main_table.base_shipping_amount * main_table.base_to_global_rate)'), + 'discount' => new Zend_Db_Expr('SUM(main_table.base_discount_amount * main_table.base_to_global_rate)'), + 'total' => new Zend_Db_Expr('SUM(main_table.base_grand_total * main_table.base_to_global_rate)'), + 'invoiced' => new Zend_Db_Expr('SUM(main_table.base_total_paid * main_table.base_to_global_rate)'), + 'refunded' => new Zend_Db_Expr('SUM(main_table.base_total_refunded * main_table.base_to_global_rate)'), + 'profit' => new Zend_Db_Expr("SUM({$baseSubtotalInvoiced} * main_table.base_to_global_rate) " . "+ SUM({$baseDiscountRefunded} * main_table.base_to_global_rate) " . "- SUM({$baseSubtotalRefunded} * main_table.base_to_global_rate) " . "- SUM({$baseDiscountInvoiced} * main_table.base_to_global_rate) " - . "- SUM({$baseTotalInvocedCost} * main_table.base_to_global_rate)" + . "- SUM({$baseTotalInvocedCost} * main_table.base_to_global_rate)") ]); } diff --git a/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php index 54700755dd9..7bb19c5b0bf 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Review/Product/Collection.php @@ -56,7 +56,7 @@ public function joinReview() 'e.entity_id = r.entity_pk_value', [ 'review_cnt' => new Zend_Db_Expr(sprintf('(%s)', $subSelect)), - 'last_created' => 'MAX(r.created_at)', + 'last_created' => new Zend_Db_Expr('MAX(r.created_at)'), ] ) ->group('e.entity_id'); @@ -66,22 +66,18 @@ public function joinReview() $this->getConnection()->quoteInto('table_rating.store_id > ?', 0) ]; - /** - * @var array $groupByCondition of group by fields - */ - $groupByCondition = $this->getSelect()->getPart(Zend_Db_Select::GROUP); $percentField = $this->getConnection()->quoteIdentifier('table_rating.percent'); - $sumPercentField = $helper->prepareColumn("SUM({$percentField})", $groupByCondition); - $sumPercentApproved = $helper->prepareColumn('SUM(table_rating.percent_approved)', $groupByCondition); - $countRatingId = $helper->prepareColumn('COUNT(table_rating.rating_id)', $groupByCondition); + $sumPercentField = "SUM({$percentField})"; + $sumPercentApproved = 'SUM(table_rating.percent_approved)'; + $countRatingId = 'COUNT(table_rating.rating_id)'; $this->getSelect() ->joinLeft( ['table_rating' => $this->getTable('rating/rating_vote_aggregated')], implode(' AND ', $joinCondition), [ - 'avg_rating' => sprintf('%s/%s', $sumPercentField, $countRatingId), - 'avg_rating_approved' => sprintf('%s/%s', $sumPercentApproved, $countRatingId), + 'avg_rating' => new Zend_Db_Expr("$sumPercentField / $countRatingId"), + 'avg_rating_approved' => new Zend_Db_Expr("$sumPercentApproved / $countRatingId"), ] );