Skip to content
43 changes: 38 additions & 5 deletions app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
Expand Down Expand Up @@ -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);
Expand All @@ -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];
}

Expand Down
2 changes: 2 additions & 0 deletions app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions app/locale/en_US/Mage_Adminhtml.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Mage/Adminhtml/Helper/Dashboard/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
Expand Down
Loading