@@ -769,7 +769,7 @@ public function addOrdersCount()
769769 */
770770 public function addRevenueToSelect ($ convertCurrency = false )
771771 {
772- $ expr = $ this ->getTotalsExpression (
772+ $ expr = $ this ->getTotalsExpressionWithDiscountRefunded (
773773 !$ convertCurrency ,
774774 $ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_refunded ' , 0 ),
775775 $ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_canceled ' , 0 ),
@@ -792,7 +792,7 @@ public function addSumAvgTotals($storeId = 0)
792792 /**
793793 * calculate average and total amount
794794 */
795- $ expr = $ this ->getTotalsExpression (
795+ $ expr = $ this ->getTotalsExpressionWithDiscountRefunded (
796796 $ storeId ,
797797 $ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_refunded ' , 0 ),
798798 $ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_canceled ' , 0 ),
@@ -810,16 +810,40 @@ public function addSumAvgTotals($storeId = 0)
810810 }
811811
812812 /**
813- * Get SQL expression for totals
813+ * Get SQL expression for totals.
814814 *
815815 * @param int $storeId
816816 * @param string $baseSubtotalRefunded
817817 * @param string $baseSubtotalCanceled
818- * @param string $baseDiscountRefunded
819818 * @param string $baseDiscountCanceled
820819 * @return string
820+ * @deprecated
821+ * @see getTotalsExpressionWithDiscountRefunded
821822 */
822823 protected function getTotalsExpression (
824+ $ storeId ,
825+ $ baseSubtotalRefunded ,
826+ $ baseSubtotalCanceled ,
827+ $ baseDiscountCanceled
828+ ) {
829+ $ template = ($ storeId != 0 )
830+ ? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s) '
831+ : '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
832+ . ' * main_table.base_to_global_rate) ' ;
833+ return sprintf ($ template , $ baseSubtotalRefunded , $ baseSubtotalCanceled , $ baseDiscountCanceled );
834+ }
835+
836+ /**
837+ * Get SQL expression for totals with discount refunded.
838+ *
839+ * @param int $storeId
840+ * @param string $baseSubtotalRefunded
841+ * @param string $baseSubtotalCanceled
842+ * @param string $baseDiscountRefunded
843+ * @param string $baseDiscountCanceled
844+ * @return string
845+ */
846+ private function getTotalsExpressionWithDiscountRefunded (
823847 $ storeId ,
824848 $ baseSubtotalRefunded ,
825849 $ baseSubtotalCanceled ,
0 commit comments