@@ -769,7 +769,7 @@ public function addOrdersCount()
769
769
*/
770
770
public function addRevenueToSelect ($ convertCurrency = false )
771
771
{
772
- $ expr = $ this ->getTotalsExpression (
772
+ $ expr = $ this ->getTotalsExpressionWithDiscountRefunded (
773
773
!$ convertCurrency ,
774
774
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_refunded ' , 0 ),
775
775
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_canceled ' , 0 ),
@@ -792,7 +792,7 @@ public function addSumAvgTotals($storeId = 0)
792
792
/**
793
793
* calculate average and total amount
794
794
*/
795
- $ expr = $ this ->getTotalsExpression (
795
+ $ expr = $ this ->getTotalsExpressionWithDiscountRefunded (
796
796
$ storeId ,
797
797
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_refunded ' , 0 ),
798
798
$ this ->getConnection ()->getIfNullSql ('main_table.base_subtotal_canceled ' , 0 ),
@@ -810,16 +810,40 @@ public function addSumAvgTotals($storeId = 0)
810
810
}
811
811
812
812
/**
813
- * Get SQL expression for totals
813
+ * Get SQL expression for totals.
814
814
*
815
815
* @param int $storeId
816
816
* @param string $baseSubtotalRefunded
817
817
* @param string $baseSubtotalCanceled
818
- * @param string $baseDiscountRefunded
819
818
* @param string $baseDiscountCanceled
820
819
* @return string
820
+ * @deprecated
821
+ * @see getTotalsExpressionWithDiscountRefunded
821
822
*/
822
823
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 (
823
847
$ storeId ,
824
848
$ baseSubtotalRefunded ,
825
849
$ baseSubtotalCanceled ,
0 commit comments