diff --git a/.gitignore b/.gitignore index cf66e885b71..001b9f842d7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,12 +23,15 @@ /app/etc/modules/Cm_RedisSession.xml /lib/Credis -# flow.js library -/js/lib/uploader +# ChartJs library +/js/lib/chartjs # TinyMCE library /js/lib/tinymce +# flow.js library +/js/lib/uploader + # Add development environment setup files and README # https://github.com/OpenMage/magento-lts/pull/1012 /dev/openmage/docker-magento diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard.php b/app/code/core/Mage/Adminhtml/Block/Dashboard.php index 73a86b54ad5..b92ad182556 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard.php @@ -24,6 +24,9 @@ class Mage_Adminhtml_Block_Dashboard extends Mage_Adminhtml_Block_Template /** * Location of the "Enable Chart" config param + * + * @deprecated + * @see Mage_Adminhtml_Helper_Dashboard_Data::XML_PATH_ENABLE_CHARTS */ public const XML_PATH_ENABLE_CHARTS = 'admin/dashboard/enable_charts'; @@ -60,7 +63,9 @@ protected function _prepareLayout() $this->getLayout()->createBlock('adminhtml/dashboard_searches_top'), ); - if (Mage::getStoreConfig(self::XML_PATH_ENABLE_CHARTS)) { + /** @var Mage_Adminhtml_Helper_Dashboard_Data $helper */ + $helper = Mage::helper('adminhtml/dashboard_data'); + if ($helper->isChartEnabled()) { $block = $this->getLayout()->createBlock('adminhtml/dashboard_diagrams'); } else { $block = $this->getLayout()->createBlock('adminhtml/template') diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php index 108de96bb23..a5e02008bc1 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php @@ -1,17 +1,12 @@ setTemplate('dashboard/graph.phtml'); + $this->setDataHelperName('adminhtml/dashboard_order'); + + /** @var Mage_Adminhtml_Helper_Dashboard_Order $dataHelper */ + $dataHelper = $this->getDataHelper(); + + /** @var Mage_Core_Controller_Request_Http $request */ + $request = $this->getRequest(); + + $dataHelper->setParam('store', $request->getParam('store')); + $dataHelper->setParam('website', $request->getParam('website')); + $dataHelper->setParam('group', $request->getParam('group')); } /** @@ -163,23 +148,20 @@ public function getAllSeries() } /** - * Get chart url - * - * @param bool $directUrl - * @return string + * @deprecated + */ + public function getChartUrl($directUrl = true) + { + return ''; + } + + /** * @throws Mage_Core_Model_Store_Exception * @throws Zend_Date_Exception */ - public function getChartUrl($directUrl = true) + public function generateChart(): array { - $params = [ - 'cht' => 'lc', - 'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0', - 'chm' => 'B,f4d4b2,0,0,0', - 'chco' => 'db4814', - 'chxs' => '0,0,11|1,0,11', - 'chma' => '15,15,15,15', - ]; + $params = []; $this->_allSeries = $this->getRowsData($this->_dataRows); @@ -187,6 +169,69 @@ public function getChartUrl($directUrl = true) $this->setAxisLabels($axis, $this->getRowsData($attr, true)); } + list($datas, $dates) = $this->getChartDatasAndDates(); + $this->_axisLabels['x'] = $dates; + $this->_allSeries = $datas; + + // Image-Charts Awesome data format values + $params['chd'] = 'a:'; + $params['chd'] .= $this->getChartDataFromAllSeries(); + + $valueBuffer = []; + + if (!array_key_exists(self::AXIS_X, $this->_axisLabels) || + !array_key_exists(self::AXIS_Y, $this->_axisLabels) + ) { + return $params; + } + + $params['chxt'] = implode(',', array_keys($this->_axisLabels)); + + $indexid = 0; + foreach (array_keys($this->_axisLabels) as $idx) { + if ($idx === self::AXIS_X) { + foreach ($this->_axisLabels[$idx] as $_index => $_label) { + $this->_axisLabels[$idx][$_index] = ''; + switch ($this->getDataHelper()->getParam('period')) { + case Mage_Reports_Helper_Data::PERIOD_24_HOURS: + $this->_axisLabels[$idx][$_index] = $this->formatTime( + new Zend_Date($_label, 'yyyy-MM-dd HH:00'), + 'short', + ); + break; + case Mage_Reports_Helper_Data::PERIOD_7_DAYS: + case Mage_Reports_Helper_Data::PERIOD_1_MONTH: + $this->_axisLabels[$idx][$_index] = $this->formatDate( + new Zend_Date($_label, 'yyyy-MM-dd'), + ); + break; + case Mage_Reports_Helper_Data::PERIOD_1_YEAR: + case Mage_Reports_Helper_Data::PERIOD_2_YEARS: + $formats = Mage::app()->getLocale()->getTranslationList('datetime'); + $format = $formats['yyMM'] ?? 'MM/yyyy'; + $format = str_replace(['yyyy', 'yy', 'MM'], ['Y', 'y', 'm'], $format); + $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label)); + break; + } + } + + $tmpstring = implode('|', $this->_axisLabels[$idx]); + $valueBuffer[] = $indexid . ':|' . $tmpstring; + } + + if ($idx === self::AXIS_Y) { + $valueBuffer[] = $indexid . ':|' . implode('|', $this->getChartYLabels()); + } + + $indexid++; + } + $params['chxl'] = implode('|', $valueBuffer); + + return $params; + } + + private function getChartDatasAndDates(): array + { $timezoneLocal = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE); list($dateStart, $dateEnd) = Mage::getResourceModel('reports/order_collection') @@ -195,69 +240,69 @@ public function getChartUrl($directUrl = true) $dateStart->setTimezone($timezoneLocal); $dateEnd->setTimezone($timezoneLocal); - $d = ''; + $date = ''; $dates = []; $datas = []; while ($dateStart->compare($dateEnd) < 0) { switch ($this->getDataHelper()->getParam('period')) { - case '24h': - $d = $dateStart->toString('yyyy-MM-dd HH:00'); + case Mage_Reports_Helper_Data::PERIOD_24_HOURS: + $date = $dateStart->toString('yyyy-MM-dd HH:00'); $dateStart->addHour(1); break; - case '7d': - case '1m': - $d = $dateStart->toString('yyyy-MM-dd'); + case Mage_Reports_Helper_Data::PERIOD_7_DAYS: + case Mage_Reports_Helper_Data::PERIOD_1_MONTH: + $date = $dateStart->toString('yyyy-MM-dd'); $dateStart->addDay(1); break; - case '1y': - case '2y': - $d = $dateStart->toString('yyyy-MM'); + 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; } foreach (array_keys($this->getAllSeries()) as $index) { - if (in_array($d, $this->_axisLabels['x'])) { + if (in_array($date, $this->_axisLabels['x'])) { $datas[$index][] = (float) array_shift($this->_allSeries[$index]); } else { $datas[$index][] = 0; } } - $dates[] = $d; + $dates[] = $date; } - /** - * setting skip step - */ - if (count($dates) > 8 && count($dates) < 15) { - $c = 1; - } elseif (count($dates) >= 15) { - $c = 2; - } else { - $c = 0; - } - /** - * skipping some x labels for good reading - */ - $i = 0; - foreach ($dates as $k => $d) { - if ($i == $c) { - $dates[$k] = $d; - $i = 0; - } else { - $dates[$k] = ''; - $i++; + return [$datas, $dates]; + } + + private function getChartDataFromAllSeries(): string + { + $yorigin = 0; + $chartdata = []; + + foreach ($this->getAllSeries() as $serie) { + $thisdataarray = $serie; + $thisdataarrayCount = count($thisdataarray); + for ($j = 0; $j < $thisdataarrayCount; $j++) { + $currentvalue = $thisdataarray[$j]; + if (is_numeric($currentvalue)) { + $ylocation = $yorigin + $currentvalue; + $chartdata[] = $ylocation . $this->dataDelimiter; + } else { + $chartdata[] = $this->dataMissing . $this->dataDelimiter; + } } + $chartdata[] = $this->dataSetdelimiter; } - $this->_axisLabels['x'] = $dates; - $this->_allSeries = $datas; + $buffer = implode('', $chartdata); + $buffer = rtrim($buffer, $this->dataSetdelimiter); + $buffer = rtrim($buffer, $this->dataDelimiter); - // Image-Charts Awesome data format values - $params['chd'] = 'a:'; - $dataDelimiter = ','; - $dataSetdelimiter = '|'; - $dataMissing = '_'; + return str_replace(($this->dataDelimiter . $this->dataDelimiter), $this->dataSetdelimiter, $buffer); + } + + private function getChartYLabels(): array + { $localmaxlength = []; $localmaxvalue = []; $localminvalue = []; @@ -282,10 +327,6 @@ public function getChartUrl($directUrl = true) // default values $yLabels = []; - $miny = 0; - $maxy = 0; - $yorigin = 0; - if ($minvalue >= 0 && $maxvalue >= 0) { $miny = 0; if ($maxvalue > 10) { @@ -298,109 +339,7 @@ public function getChartUrl($directUrl = true) } } - $chartdata = []; - - foreach ($this->getAllSeries() as $serie) { - $thisdataarray = $serie; - $thisdataarrayCount = count($thisdataarray); - for ($j = 0; $j < $thisdataarrayCount; $j++) { - $currentvalue = $thisdataarray[$j]; - if (is_numeric($currentvalue)) { - $ylocation = $yorigin + $currentvalue; - $chartdata[] = $ylocation . $dataDelimiter; - } else { - $chartdata[] = $dataMissing . $dataDelimiter; - } - } - $chartdata[] = $dataSetdelimiter; - } - $buffer = implode('', $chartdata); - - $buffer = rtrim($buffer, $dataSetdelimiter); - $buffer = rtrim($buffer, $dataDelimiter); - $buffer = str_replace(($dataDelimiter . $dataSetdelimiter), $dataSetdelimiter, $buffer); - - $params['chd'] .= $buffer; - - $valueBuffer = []; - - if (count($this->_axisLabels)) { - $params['chxt'] = implode(',', array_keys($this->_axisLabels)); - $indexid = 0; - foreach (array_keys($this->_axisLabels) as $idx) { - if ($idx === 'x') { - /** - * Format date - */ - foreach ($this->_axisLabels[$idx] as $_index => $_label) { - if ($_label != '') { - switch ($this->getDataHelper()->getParam('period')) { - case '24h': - $this->_axisLabels[$idx][$_index] = $this->formatTime( - new Zend_Date($_label, 'yyyy-MM-dd HH:00'), - 'short', - ); - break; - case '7d': - case '1m': - $this->_axisLabels[$idx][$_index] = $this->formatDate( - new Zend_Date($_label, 'yyyy-MM-dd'), - ); - break; - case '1y': - case '2y': - $formats = Mage::app()->getLocale()->getTranslationList('datetime'); - $format = $formats['yyMM'] ?? 'MM/yyyy'; - $format = str_replace(['yyyy', 'yy', 'MM'], ['Y', 'y', 'm'], $format); - $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label)); - break; - } - } else { - $this->_axisLabels[$idx][$_index] = ''; - } - } - - $tmpstring = implode('|', $this->_axisLabels[$idx]); - - $valueBuffer[] = $indexid . ':|' . $tmpstring; - if (count($this->_axisLabels[$idx]) > 1) { - $deltaX = 100 / (count($this->_axisLabels[$idx]) - 1); - } else { - $deltaX = 100; - } - } elseif ($idx === 'y') { - $valueBuffer[] = $indexid . ':|' . implode('|', $yLabels); - if (count($yLabels) - 1) { - $deltaY = 100 / (count($yLabels) - 1); - } else { - $deltaY = 100; - } - } - $indexid++; - } - $params['chxl'] = implode('|', $valueBuffer); - } - - // chart size - $params['chs'] = $this->getWidth() . 'x' . $this->getHeight(); - - if (isset($deltaX, $deltaY)) { - $params['chg'] = $deltaX . ',' . $deltaY . ',1,0'; - } - - // return the encoded data - if ($directUrl) { - $p = []; - foreach ($params as $name => $value) { - $p[] = $name . '=' . urlencode($value); - } - return self::API_URL . '?' . implode('&', $p); - } - - $gaData = urlencode(base64_encode(json_encode($params))); - $gaHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData); - $params = ['ga' => $gaData, 'h' => $gaHash]; - return $this->getUrl('*/*/tunnel', ['_query' => $params]); + return $yLabels; } /** @@ -506,9 +445,45 @@ protected function _prepareData() $availablePeriods = array_keys($helper->getDatePeriods()); $period = $this->getRequest()->getParam('period'); + $this->setChartId($this->getHtmlId() . random_int(0, 100)); $this->getDataHelper()->setParam( 'period', ($period && in_array($period, $availablePeriods)) ? $period : '24h', ); } + + public function getChartData(): string + { + return json_encode($this->_allSeries[array_key_first($this->_allSeries)]); + } + + public function getChartLabels(): string + { + return json_encode($this->_axisLabels['x']); + } + + public function getChartType(): string + { + return 'bar'; + } + + public function getChartId(): string + { + return $this->getDataByKey('chart_id'); + } + + public function setChartId(string $chartId): self + { + return $this->setData('chart_id', $chartId); + } + + public function getChartBackgroundColor(): string + { + return 'rgba(113,121,142,0.7)'; + } + + public function getChartHoverBackgroundColor(): string + { + return 'rgba(113,121,142,1.0)'; + } } diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php index a882f2c49c4..e7117d531fe 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Amounts.php @@ -22,6 +22,11 @@ */ class Mage_Adminhtml_Block_Dashboard_Tab_Amounts extends Mage_Adminhtml_Block_Dashboard_Graph { + protected $_axisMaps = [ + 'x' => 'range', + 'y' => 'revenue', + ]; + /** * Initialize object */ @@ -38,17 +43,7 @@ public function __construct() */ protected function _prepareData() { - $this->setDataHelperName('adminhtml/dashboard_order'); - $this->getDataHelper()->setParam('store', $this->getRequest()->getParam('store')); - $this->getDataHelper()->setParam('website', $this->getRequest()->getParam('website')); - $this->getDataHelper()->setParam('group', $this->getRequest()->getParam('group')); - $this->setDataRows('revenue'); - $this->_axisMaps = [ - 'x' => 'range', - 'y' => 'revenue', - ]; - parent::_prepareData(); } } diff --git a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php index 00b690c36da..74af61ed4d0 100644 --- a/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php +++ b/app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Orders.php @@ -22,6 +22,11 @@ */ class Mage_Adminhtml_Block_Dashboard_Tab_Orders extends Mage_Adminhtml_Block_Dashboard_Graph { + protected $_axisMaps = [ + 'x' => 'range', + 'y' => 'quantity', + ]; + public function __construct() { $this->setHtmlId('orders'); @@ -35,17 +40,7 @@ public function __construct() */ protected function _prepareData() { - $this->setDataHelperName('adminhtml/dashboard_order'); - $this->getDataHelper()->setParam('store', $this->getRequest()->getParam('store')); - $this->getDataHelper()->setParam('website', $this->getRequest()->getParam('website')); - $this->getDataHelper()->setParam('group', $this->getRequest()->getParam('group')); - $this->setDataRows('quantity'); - $this->_axisMaps = [ - 'x' => 'range', - 'y' => 'quantity', - ]; - parent::_prepareData(); } } diff --git a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php index 7bcaeed611a..024c575c0d9 100644 --- a/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php +++ b/app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php @@ -14,6 +14,8 @@ * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +use Composer\InstalledVersions; + /** * Data helper for dashboard * @@ -22,11 +24,24 @@ */ class Mage_Adminhtml_Helper_Dashboard_Data extends Mage_Core_Helper_Data { + /** + * Location of the "Enable Chart" config param + */ + public const XML_PATH_ENABLE_CHARTS = 'admin/dashboard/enable_charts'; + protected $_moduleName = 'Mage_Adminhtml'; protected $_locale = null; protected $_stores = null; + public function isChartEnabled(): bool + { + if (!InstalledVersions::isInstalled('nnnick/chartjs')) { + return false; + } + return Mage::getStoreConfigFlag(self::XML_PATH_ENABLE_CHARTS); + } + /** * Retrieve stores configured in system. * @@ -54,16 +69,16 @@ public function countStores() /** * Prepare array with periods for dashboard graphs * - * @return array + * @return string[] */ public function getDatePeriods() { return [ - '24h' => $this->__('Last 24 Hours'), - '7d' => $this->__('Last 7 Days'), - '1m' => $this->__('Current Month'), - '1y' => $this->__('YTD'), - '2y' => $this->__('2YTD'), + 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_1_YEAR => $this->__('YTD'), + Mage_Reports_Helper_Data::PERIOD_2_YEARS => $this->__('2YTD'), ]; } @@ -73,6 +88,7 @@ public function getDatePeriods() * * @param string $data * @return string + * @deprecated */ public function getChartDataHash($data) { diff --git a/app/code/core/Mage/Adminhtml/controllers/DashboardController.php b/app/code/core/Mage/Adminhtml/controllers/DashboardController.php index c8927590a7c..a2b77fef199 100644 --- a/app/code/core/Mage/Adminhtml/controllers/DashboardController.php +++ b/app/code/core/Mage/Adminhtml/controllers/DashboardController.php @@ -74,29 +74,4 @@ public function ajaxBlockAction() } $this->getResponse()->setBody($output); } - - public function tunnelAction() - { - $httpClient = new Varien_Http_Client(); - $gaData = $this->getRequest()->getParam('ga'); - $gaHash = $this->getRequest()->getParam('h'); - if ($gaData && $gaHash) { - $newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData); - if (hash_equals($newHash, $gaHash)) { - $params = json_decode(base64_decode(urldecode($gaData)), true); - if ($params) { - $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL) - ->setParameterGet($params) - ->setConfig(['timeout' => 5]) - ->request('GET'); - - $headers = $response->getHeaders(); - - $this->getResponse() - ->setHeader('Content-type', $headers['Content-type']) - ->setBody($response->getBody()); - } - } - } - } } diff --git a/app/code/core/Mage/Install/Model/Installer.php b/app/code/core/Mage/Install/Model/Installer.php index c743ab52857..d7e9ba7d52d 100644 --- a/app/code/core/Mage/Install/Model/Installer.php +++ b/app/code/core/Mage/Install/Model/Installer.php @@ -141,9 +141,9 @@ public function installDb() } if (!empty($data['enable_charts'])) { - $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 1); + $setupModel->setConfigData(Mage_Adminhtml_Helper_Dashboard_Data::XML_PATH_ENABLE_CHARTS, 1); } else { - $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 0); + $setupModel->setConfigData(Mage_Adminhtml_Helper_Dashboard_Data::XML_PATH_ENABLE_CHARTS, 0); } $unsecureBaseUrl = Mage::getBaseUrl('web'); diff --git a/app/code/core/Mage/Reports/Helper/Data.php b/app/code/core/Mage/Reports/Helper/Data.php index 7adac525d11..50eae144892 100644 --- a/app/code/core/Mage/Reports/Helper/Data.php +++ b/app/code/core/Mage/Reports/Helper/Data.php @@ -24,6 +24,15 @@ class Mage_Reports_Helper_Data extends Mage_Core_Helper_Abstract public const REPORT_PERIOD_TYPE_MONTH = 'month'; public const REPORT_PERIOD_TYPE_YEAR = 'year'; + public const PERIOD_CUSTOM = 'custom'; + public const PERIOD_24_HOURS = '24h'; + public const PERIOD_7_DAYS = '7d'; + public const PERIOD_1_MONTH = '1m'; + public const PERIOD_3_MONTHS = '3m'; + public const PERIOD_6_MONTHS = '6m'; + public const PERIOD_1_YEAR = '1y'; + public const PERIOD_2_YEARS = '2y'; + public const XML_PATH_REPORTS_ENABLED = 'reports/general/enabled'; protected $_moduleName = 'Mage_Reports'; 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 867ffd517af..64a0d4fb57e 100644 --- a/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php +++ b/app/code/core/Mage/Reports/Model/Resource/Order/Collection.php @@ -222,25 +222,25 @@ protected function _prepareSummaryAggregated($range, $customStart, $customEnd) /** * Get range expression * - * @param string $range + * @param Mage_Reports_Helper_Data::PERIOD_* $range * @return Zend_Db_Expr */ protected function _getRangeExpression($range) { switch ($range) { - case '24h': + case Mage_Reports_Helper_Data::PERIOD_24_HOURS: $expression = $this->getConnection()->getConcatSql([ $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d %H:'), $this->getConnection()->quote('00'), ]); break; - case '7d': - case '1m': + case Mage_Reports_Helper_Data::PERIOD_7_DAYS: + case Mage_Reports_Helper_Data::PERIOD_1_MONTH: $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m-%d'); break; - case '1y': - case '2y': - case 'custom': + case Mage_Reports_Helper_Data::PERIOD_1_YEAR: + case Mage_Reports_Helper_Data::PERIOD_2_YEARS: + case Mage_Reports_Helper_Data::PERIOD_CUSTOM: default: $expression = $this->getConnection()->getDateFormatSql('{{attribute}}', '%Y-%m'); break; @@ -306,7 +306,7 @@ protected function _getTZRangeExpressionForAttribute($range, $attribute, $tzFrom /** * Calculate From and To dates (or times) by given period * - * @param string $range + * @param Mage_Reports_Helper_Data::PERIOD_* $range * @param string $customStart * @param string $customEnd * @param bool $returnObjects @@ -327,30 +327,30 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects = $dateStart->setSecond(0); switch ($range) { - case '24h': + case Mage_Reports_Helper_Data::PERIOD_24_HOURS: $dateEnd = Mage::app()->getLocale()->date(); $dateEnd->addHour(1); $dateStart = clone $dateEnd; $dateStart->subDay(1); break; - case '7d': + case Mage_Reports_Helper_Data::PERIOD_7_DAYS: // subtract 6 days we need to include // only today and not the last one from range $dateStart->subDay(6); break; - case '1m': + case Mage_Reports_Helper_Data::PERIOD_1_MONTH: $dateStart->setDay(Mage::getStoreConfig('reports/dashboard/mtd_start')); break; - case 'custom': - $dateStart = $customStart ? $customStart : $dateEnd; - $dateEnd = $customEnd ? $customEnd : $dateEnd; + case Mage_Reports_Helper_Data::PERIOD_CUSTOM: + $dateStart = $customStart ?: $dateEnd; + $dateEnd = $customEnd ?: $dateEnd; break; - case '1y': - case '2y': + case Mage_Reports_Helper_Data::PERIOD_1_YEAR: + case Mage_Reports_Helper_Data::PERIOD_2_YEARS: $startMonthDay = explode(',', Mage::getStoreConfig('reports/dashboard/ytd_start')); $startMonth = isset($startMonthDay[0]) ? (int) $startMonthDay[0] : 1; $startDay = isset($startMonthDay[1]) ? (int) $startMonthDay[1] : 1; diff --git a/app/design/adminhtml/default/default/template/dashboard/graph.phtml b/app/design/adminhtml/default/default/template/dashboard/graph.phtml index dac97837c6f..4d72d519357 100644 --- a/app/design/adminhtml/default/default/template/dashboard/graph.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/graph.phtml @@ -1,16 +1,11 @@ __('Select Range') ?>:


- getWidth()}px;height:{$this->getHeight()}px; margin:0 auto;"; - ?> + getWidth()};height:{$this->getHeight()}; margin:0 auto;"; ?> getCount()): ?> -

chart

+ generateChart() ?> +
+ +
+

__('No Data Found') ?>

diff --git a/composer.json b/composer.json index 5a8632ae484..79f389019a5 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "flowjs/flowjs": "dev-master", "magento-hackathon/magento-composer-installer": "^3.1 || ^2.1 || ^4.0", "mklkj/tinymce-i18n": "^25.2", + "nnnick/chartjs": "^4.4.7", "openmage/composer-plugin": "^3.0", "pelago/emogrifier": "^7.0", "phpseclib/mcrypt_compat": "^2.0.3", diff --git a/composer.lock b/composer.lock index 93f6a632c84..42a4c45aa83 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "992538810d2699241a4b7525097ee91b", + "content-hash": "db13f706ae8852602f4561fd4dc5f89a", "packages": [ { "name": "colinmollenhour/cache-backend-redis", @@ -639,6 +639,51 @@ }, "time": "2025-02-03T10:42:25+00:00" }, + { + "name": "nnnick/chartjs", + "version": "v4.4.7", + "source": { + "type": "git", + "url": "https://github.com/chartjs/Chart.js.git", + "reference": "57b5c5b78fb2d8504f556bef6e4177735d9929ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/chartjs/Chart.js/zipball/57b5c5b78fb2d8504f556bef6e4177735d9929ea", + "reference": "57b5c5b78fb2d8504f556bef6e4177735d9929ea", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "release/2.0": "v2.0-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "NICK DOWNIE", + "email": "hello@nickdownie.com" + } + ], + "description": "Simple HTML5 charts using the canvas element.", + "homepage": "https://www.chartjs.org/", + "keywords": [ + "JS", + "chart" + ], + "support": { + "issues": "https://github.com/chartjs/Chart.js/issues", + "source": "https://github.com/chartjs/Chart.js/tree/v4.4.7" + }, + "time": "2024-12-01T16:35:13+00:00" + }, { "name": "openmage/composer-plugin", "version": "v3.0.0", @@ -3508,16 +3553,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.12.1", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" + "reference": "024473a478be9df5fdaca2c793f2232fe788e414" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", - "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/024473a478be9df5fdaca2c793f2232fe788e414", + "reference": "024473a478be9df5fdaca2c793f2232fe788e414", "shasum": "" }, "require": { @@ -3556,7 +3601,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.0" }, "funding": [ { @@ -3564,7 +3609,7 @@ "type": "tidelift" } ], - "time": "2024-11-08T17:47:46+00:00" + "time": "2025-02-12T12:17:51+00:00" }, { "name": "nikic/php-parser", @@ -7083,5 +7128,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/tests/unit/Base/DefaultConfigTest.php b/tests/unit/Base/DefaultConfigTest.php index c38e7ed783a..36735a2ed74 100644 --- a/tests/unit/Base/DefaultConfigTest.php +++ b/tests/unit/Base/DefaultConfigTest.php @@ -19,7 +19,7 @@ use Generator; use Mage; -use Mage_Adminhtml_Block_Dashboard; +use Mage_Adminhtml_Helper_Dashboard_Data; use PHPUnit\Framework\TestCase; class DefaultConfigTest extends TestCase @@ -37,9 +37,9 @@ public function testGetStoreConfig(string $expectedResult, string $path, $store public function provideGetStoreConfig(): Generator { - yield Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS => [ + yield Mage_Adminhtml_Helper_Dashboard_Data::XML_PATH_ENABLE_CHARTS => [ '1', - Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, + Mage_Adminhtml_Helper_Dashboard_Data::XML_PATH_ENABLE_CHARTS, ]; } }