Skip to content

Commit

Permalink
Fixed Mage_Reports_Model_Resource_Order_Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed Dec 29, 2022
1 parent 5b16123 commit 5145052
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
8 changes: 8 additions & 0 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@

Varien_Autoload::register();

/** AUTOLOADER PATCH **/
if (file_exists($autoloaderPath = BP . DS . 'vendor/autoload.php') ||
file_exists($autoloaderPath = BP . DS . '../vendor/autoload.php')
) {
require $autoloaderPath;
}
/** AUTOLOADER PATCH **/

/* Support additional includes, such as composer's vendor/autoload.php files */
foreach (glob(BP . DS . 'app' . DS . 'etc' . DS . 'includes' . DS . '*.php') as $path) {
include_once $path;
Expand Down
48 changes: 24 additions & 24 deletions app/code/core/Mage/Reports/Model/Resource/Order/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 (?)', [
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
]);

Expand All @@ -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(?)', [
Expand Down Expand Up @@ -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)")
]);
}

Expand Down

0 comments on commit 5145052

Please sign in to comment.