Skip to content

Commit

Permalink
ENGCOM-4302: Backward compatibility fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Mar 22, 2019
1 parent f893a92 commit 57c4db4
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions app/code/Magento/Reports/Model/ResourceModel/Order/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public function addOrdersCount()
*/
public function addRevenueToSelect($convertCurrency = false)
{
$expr = $this->getTotalsExpression(
$expr = $this->getTotalsExpressionWithDiscountRefunded(
!$convertCurrency,
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
Expand All @@ -792,7 +792,7 @@ public function addSumAvgTotals($storeId = 0)
/**
* calculate average and total amount
*/
$expr = $this->getTotalsExpression(
$expr = $this->getTotalsExpressionWithDiscountRefunded(
$storeId,
$this->getConnection()->getIfNullSql('main_table.base_subtotal_refunded', 0),
$this->getConnection()->getIfNullSql('main_table.base_subtotal_canceled', 0),
Expand All @@ -810,16 +810,40 @@ public function addSumAvgTotals($storeId = 0)
}

/**
* Get SQL expression for totals
* Get SQL expression for totals.
*
* @param int $storeId
* @param string $baseSubtotalRefunded
* @param string $baseSubtotalCanceled
* @param string $baseDiscountRefunded
* @param string $baseDiscountCanceled
* @return string
* @deprecated
* @see getTotalsExpressionWithDiscountRefunded
*/
protected function getTotalsExpression(
$storeId,
$baseSubtotalRefunded,
$baseSubtotalCanceled,
$baseDiscountCanceled
) {
$template = ($storeId != 0)
? '(main_table.base_subtotal - %2$s - %1$s - ABS(main_table.base_discount_amount) - %3$s)'
: '((main_table.base_subtotal - %1$s - %2$s - ABS(main_table.base_discount_amount) + %3$s) '
. ' * main_table.base_to_global_rate)';
return sprintf($template, $baseSubtotalRefunded, $baseSubtotalCanceled, $baseDiscountCanceled);
}

/**
* Get SQL expression for totals with discount refunded.
*
* @param int $storeId
* @param string $baseSubtotalRefunded
* @param string $baseSubtotalCanceled
* @param string $baseDiscountRefunded
* @param string $baseDiscountCanceled
* @return string
*/
private function getTotalsExpressionWithDiscountRefunded(
$storeId,
$baseSubtotalRefunded,
$baseSubtotalCanceled,
Expand Down

0 comments on commit 57c4db4

Please sign in to comment.