diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
index 99925d37866..d1b1c7b5fb2 100644
--- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
+++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
@@ -201,6 +201,8 @@ public function generateChart(): array
break;
case Mage_Reports_Helper_Data::PERIOD_7_DAYS:
case Mage_Reports_Helper_Data::PERIOD_1_MONTH:
+ case Mage_Reports_Helper_Data::PERIOD_3_MONTHS:
+ case Mage_Reports_Helper_Data::PERIOD_6_MONTHS:
$this->_axisLabels[$idx][$_index] = $this->formatDate(
new Zend_Date($_label, 'yyyy-MM-dd'),
);
@@ -243,9 +245,10 @@ private function getChartDatasAndDates(): array
$date = '';
$dates = [];
$datas = [];
+ $period = $this->getDataHelper()->getParam('period');
while ($dateStart->compare($dateEnd) < 0) {
- switch ($this->getDataHelper()->getParam('period')) {
+ switch ($period) {
case Mage_Reports_Helper_Data::PERIOD_24_HOURS:
$date = $dateStart->toString('yyyy-MM-dd HH:00');
$dateStart->addHour(1);
@@ -255,22 +258,52 @@ private function getChartDatasAndDates(): array
$date = $dateStart->toString('yyyy-MM-dd');
$dateStart->addDay(1);
break;
+ case Mage_Reports_Helper_Data::PERIOD_3_MONTHS:
+ case Mage_Reports_Helper_Data::PERIOD_6_MONTHS:
+ $date = $dateStart->toString('yyyy-MM-dd');
+ $dateStart->addWeek(1);
+ break;
case Mage_Reports_Helper_Data::PERIOD_1_YEAR:
case Mage_Reports_Helper_Data::PERIOD_2_YEARS:
$date = $dateStart->toString('yyyy-MM');
$dateStart->addMonth(1);
break;
}
+ if (in_array($period, [
+ Mage_Reports_Helper_Data::PERIOD_3_MONTHS,
+ Mage_Reports_Helper_Data::PERIOD_6_MONTHS,
+ ])) {
+ $axisTimestamps = [];
+ foreach ($this->_axisLabels['x'] as $axisDate) {
+ $axisTimestamps[] = (new Zend_Date($axisDate, 'yyyy-MM-dd'))->getTimestamp();
+ }
+ }
foreach (array_keys($this->getAllSeries()) as $index) {
- if (in_array($date, $this->_axisLabels['x'])) {
- $datas[$index][] = (float) array_shift($this->_allSeries[$index]);
+ if (isset($axisTimestamps)) {
+ $dateObj = new Zend_Date($date, 'yyyy-MM-dd');
+ $weekStartTs = $dateObj->getTimestamp();
+ $weekEndTs = $dateObj->addWeek(1)->getTimestamp();
+
+ $found = false;
+ foreach ($axisTimestamps as $axisTs) {
+ if ($axisTs >= $weekStartTs && $axisTs < $weekEndTs) {
+ $datas[$index][] = (float) array_shift($this->_allSeries[$index]);
+ $found = true;
+ break;
+ }
+ }
+
+ if (!$found) {
+ $datas[$index][] = 0;
+ }
} else {
- $datas[$index][] = 0;
+ $datas[$index][] = in_array($date, $this->_axisLabels['x'])
+ ? (float) array_shift($this->_allSeries[$index])
+ : 0;
}
}
$dates[] = $date;
}
-
return [$datas, $dates];
}
diff --git a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php
index 750c433a11e..7699f5778d4 100644
--- a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php
+++ b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php
@@ -77,6 +77,8 @@ public function getDatePeriods()
Mage_Reports_Helper_Data::PERIOD_24_HOURS => $this->__('Last 24 Hours'),
Mage_Reports_Helper_Data::PERIOD_7_DAYS => $this->__('Last 7 Days'),
Mage_Reports_Helper_Data::PERIOD_1_MONTH => $this->__('Current Month'),
+ Mage_Reports_Helper_Data::PERIOD_3_MONTHS => $this->__('Last 3 Months'),
+ Mage_Reports_Helper_Data::PERIOD_6_MONTHS => $this->__('Last 6 Months'),
Mage_Reports_Helper_Data::PERIOD_1_YEAR => $this->__('YTD'),
Mage_Reports_Helper_Data::PERIOD_2_YEARS => $this->__('2YTD'),
];
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 b3dc66e971a..446b94906cc 100644
--- a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php
+++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php
@@ -236,6 +236,8 @@ protected function _getRangeExpression($range)
break;
case Mage_Reports_Helper_Data::PERIOD_7_DAYS:
case Mage_Reports_Helper_Data::PERIOD_1_MONTH:
+ case Mage_Reports_Helper_Data::PERIOD_3_MONTHS:
+ case Mage_Reports_Helper_Data::PERIOD_6_MONTHS:
$expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d');
break;
case Mage_Reports_Helper_Data::PERIOD_1_YEAR:
@@ -341,7 +343,14 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects =
break;
case Mage_Reports_Helper_Data::PERIOD_1_MONTH:
+ case Mage_Reports_Helper_Data::PERIOD_3_MONTHS:
+ case Mage_Reports_Helper_Data::PERIOD_6_MONTHS:
$dateStart->setDay(Mage::getStoreConfig('reports/dashboard/mtd_start'));
+ if ($range === Mage_Reports_Helper_Data::PERIOD_3_MONTHS) {
+ $dateStart->subMonth(2);
+ } elseif ($range === Mage_Reports_Helper_Data::PERIOD_6_MONTHS) {
+ $dateStart->subMonth(5);
+ }
break;
case Mage_Reports_Helper_Data::PERIOD_CUSTOM:
diff --git a/app/locale/en_US/Mage_Adminhtml.csv b/app/locale/en_US/Mage_Adminhtml.csv
index c85c5f04c78..dfe7fdfee1a 100644
--- a/app/locale/en_US/Mage_Adminhtml.csv
+++ b/app/locale/en_US/Mage_Adminhtml.csv
@@ -527,6 +527,8 @@
"Key %s does not contain scalar value","Key %s does not contain scalar value"
"Key %s does not exist in array","Key %s does not exist in array"
"Last 24 Hours","Last 24 Hours"
+"Last 3 Months","Last 3 Months"
+"Last 6 Months","Last 6 Months"
"Last 5 Orders","Last 5 Orders"
"Last 5 Search Terms","Last 5 Search Terms"
"Last 7 Days","Last 7 Days"
diff --git a/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php b/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php
index 8e6d9f24190..64239b60d40 100644
--- a/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php
+++ b/tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php
@@ -63,6 +63,8 @@ public function testGetDatePeriods(): void
'24h' => $this->subject->__('Last 24 Hours'),
'7d' => $this->subject->__('Last 7 Days'),
'1m' => $this->subject->__('Current Month'),
+ '3m' => $this->subject->__('Last 3 Months'),
+ '6m' => $this->subject->__('Last 6 Months'),
'1y' => $this->subject->__('YTD'),
'2y' => $this->subject->__('2YTD'),
];