From 4958644fd4fcd3c9c9d6950adadda01d915b819c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 17 Sep 2026 15:54:26 +0200 Subject: [PATCH 1/6] Feed the Symfony dashboard's Zone Two hook with a sales chart --- config.xml | 6 +-- dashtrends.php | 64 +++++++++++++++++++++++- upgrade/index.php | 34 +++++++++++++ upgrade/upgrade-2.2.0.php | 33 ++++++++++++ views/templates/admin/index.php | 34 +++++++++++++ views/templates/admin/zone_two.html.twig | 14 ++++++ 6 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 upgrade/index.php create mode 100644 upgrade/upgrade-2.2.0.php create mode 100644 views/templates/admin/index.php create mode 100644 views/templates/admin/zone_two.html.twig diff --git a/config.xml b/config.xml index 48ad885..973ac6b 100644 --- a/config.xml +++ b/config.xml @@ -2,10 +2,10 @@ dashtrends - - + + - + 0 1 diff --git a/dashtrends.php b/dashtrends.php index 3caff85..00b533c 100755 --- a/dashtrends.php +++ b/dashtrends.php @@ -23,6 +23,8 @@ * @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) */ +use Twig\Environment; + if (!defined('_PS_VERSION_')) { exit; } @@ -44,7 +46,7 @@ public function __construct() { $this->name = 'dashtrends'; $this->tab = 'administration'; - $this->version = '2.1.3'; + $this->version = '2.2.0'; $this->author = 'PrestaShop'; parent::__construct(); @@ -59,6 +61,8 @@ public function install() && $this->registerHook('dashboardZoneTwo') && $this->registerHook('dashboardData') && $this->registerHook('actionAdminControllerSetMedia') + // Modern counterpart of dashboardZoneTwo, registered alongside it (#41971). + && $this->registerHook('displayAdminDashboardZoneTwo') ; } @@ -78,6 +82,64 @@ public function hookDashboardZoneTwo($params) return $this->display(__FILE__, 'dashboard_zone_two.tpl'); } + /** + * Modern counterpart of hookDashboardZoneTwo() for the Symfony dashboard (#41971). + * No comparison-period overlay: the new hook isn't passed compare_from/compare_to. + */ + public function hookDisplayAdminDashboardZoneTwo(array $params) + { + $tmp_data = $this->getData($params['date_from'], $params['date_to']); + $dashboardData = $this->refineData($params['date_from'], $params['date_to'], $tmp_data); + + return $this->render('zone_two.html.twig', [ + 'title' => $this->trans('Sales trend', [], 'Modules.Dashtrends.Admin'), + 'chartId' => 'dashtrends-sales', + 'chartConfig' => $this->getSalesChartConfig($dashboardData), + ]); + } + + private function render(string $template, array $params = []): string + { + $twig = $this->get('twig'); + if (!$twig instanceof Environment) { + return ''; + } + + return $twig->render('@Modules/dashtrends/views/templates/admin/' . $template, $params); + } + + /** + * Plain Chart.js config, no dataset color (auto-applied by the core psColors plugin). + */ + private function getSalesChartConfig(array $dashboardData): array + { + $labels = []; + $data = []; + foreach ($dashboardData['sales'] as $timestamp => $value) { + $labels[] = Tools::displayDate(date('Y-m-d', (int) $timestamp)); + $data[] = round((float) $value, 2); + } + + return [ + 'type' => 'line', + 'data' => [ + 'labels' => $labels, + 'datasets' => [ + [ + 'label' => $this->trans('Sales', [], 'Admin.Global'), + 'data' => $data, + 'fill' => true, + 'tension' => 0.3, + ], + ], + ], + 'options' => [ + 'plugins' => ['legend' => ['position' => 'bottom']], + 'scales' => ['y' => ['beginAtZero' => true]], + ], + ]; + } + protected function getData($date_from, $date_to) { // We need the following figures to calculate our stats diff --git a/upgrade/index.php b/upgrade/index.php new file mode 100644 index 0000000..45df26c --- /dev/null +++ b/upgrade/index.php @@ -0,0 +1,34 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/upgrade/upgrade-2.2.0.php b/upgrade/upgrade-2.2.0.php new file mode 100644 index 0000000..0deae3e --- /dev/null +++ b/upgrade/upgrade-2.2.0.php @@ -0,0 +1,33 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_2_2_0($object) +{ + return $object->registerHook('displayAdminDashboardZoneTwo'); +} diff --git a/views/templates/admin/index.php b/views/templates/admin/index.php new file mode 100644 index 0000000..45df26c --- /dev/null +++ b/views/templates/admin/index.php @@ -0,0 +1,34 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/views/templates/admin/zone_two.html.twig b/views/templates/admin/zone_two.html.twig new file mode 100644 index 0000000..cf8fd00 --- /dev/null +++ b/views/templates/admin/zone_two.html.twig @@ -0,0 +1,14 @@ +{# + # For the full copyright and license information, please view the + # docs/licenses/LICENSE.txt file that was distributed with this source code. + #} +{% import '@PrestaShop/Admin/Dashboard/_partials/chart.html.twig' as dashboard %} + +
+
+

{{ title }}

+
+
+ {{ dashboard.renderChart(chartId, chartConfig, {height: 300, label: title}) }} +
+
From 958d8eae08b7cc788249e8123ec0c8d3ebb6c248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 17 Sep 2026 16:08:39 +0200 Subject: [PATCH 2/6] Reuse the shared card-header macro instead of hand-rolling one --- views/templates/admin/zone_two.html.twig | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/views/templates/admin/zone_two.html.twig b/views/templates/admin/zone_two.html.twig index cf8fd00..59f4149 100644 --- a/views/templates/admin/zone_two.html.twig +++ b/views/templates/admin/zone_two.html.twig @@ -2,13 +2,12 @@ # For the full copyright and license information, please view the # docs/licenses/LICENSE.txt file that was distributed with this source code. #} -{% import '@PrestaShop/Admin/Dashboard/_partials/chart.html.twig' as dashboard %} +{% import '@PrestaShop/Admin/Dashboard/_partials/card_header.html.twig' as dashboard %} +{% import '@PrestaShop/Admin/Dashboard/_partials/chart.html.twig' as chart %}
-
-

{{ title }}

-
+ {{ dashboard.renderCardHeader(title, 'show_chart', null) }}
- {{ dashboard.renderChart(chartId, chartConfig, {height: 300, label: title}) }} + {{ chart.renderChart(chartId, chartConfig, {height: 300, label: title}) }}
From d75ac7ef7c0dc5b52fbdf18dec90ca2703df3081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 17 Sep 2026 16:35:01 +0200 Subject: [PATCH 3/6] Reset phpVersion in PHPStan config to avoid crashing on CI's PHP 8.5 injection --- tests/php/phpstan/phpstan.neon | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/php/phpstan/phpstan.neon b/tests/php/phpstan/phpstan.neon index 018ab98..0cb7f98 100644 --- a/tests/php/phpstan/phpstan.neon +++ b/tests/php/phpstan/phpstan.neon @@ -1,2 +1,10 @@ # Base PHPStan configuration for the module - # This file is included by version-specific configs \ No newline at end of file + # This file is included by version-specific configs + +parameters: + # Reset to auto-detection: the shared CI action injects a phpVersion computed from the + # matrix's php-version input, which some older PrestaShop releases' pinned PHPStan can't + # parse once that input reaches a version newer than its own release date (PHPStan's + # phpVersion schema is capped at whatever PHP existed when that PHPStan version shipped). + # Included last, so this wins over the injected value (see PrestaShop/.github#phpstan). + phpVersion: null From d84d4a7e0fa20d4c23e1135d5cb2c29efb4f81e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 18 Sep 2026 14:28:30 +0200 Subject: [PATCH 4/6] Use the ChartCard Twig component instead of the chart partial --- views/templates/admin/zone_two.html.twig | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/views/templates/admin/zone_two.html.twig b/views/templates/admin/zone_two.html.twig index 59f4149..494bd01 100644 --- a/views/templates/admin/zone_two.html.twig +++ b/views/templates/admin/zone_two.html.twig @@ -2,12 +2,10 @@ # For the full copyright and license information, please view the # docs/licenses/LICENSE.txt file that was distributed with this source code. #} -{% import '@PrestaShop/Admin/Dashboard/_partials/card_header.html.twig' as dashboard %} -{% import '@PrestaShop/Admin/Dashboard/_partials/chart.html.twig' as chart %} - -
- {{ dashboard.renderCardHeader(title, 'show_chart', null) }} -
- {{ chart.renderChart(chartId, chartConfig, {height: 300, label: title}) }} -
-
+{{ component('ChartCard', { + chartId: chartId, + config: chartConfig, + height: 300, + title: title, + icon: 'show_chart', +}) }} From 4d7eaf4f56ee6a54cb36f67720a65414ca573298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 24 Sep 2026 14:56:15 +0200 Subject: [PATCH 5/6] Bump to 3.0.0 --- config.xml | 2 +- dashtrends.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.xml b/config.xml index 973ac6b..8f03f49 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ dashtrends - + diff --git a/dashtrends.php b/dashtrends.php index 00b533c..dd32c11 100755 --- a/dashtrends.php +++ b/dashtrends.php @@ -46,7 +46,7 @@ public function __construct() { $this->name = 'dashtrends'; $this->tab = 'administration'; - $this->version = '2.2.0'; + $this->version = '3.0.0'; $this->author = 'PrestaShop'; parent::__construct(); From 6fee4ddf35eb4af6038032b6b3cd183eb8069abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 24 Sep 2026 15:03:38 +0200 Subject: [PATCH 6/6] Fix composer.lock content-hash colliding with dashgoals' autoloader class --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 7e4d321..9542059 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": "2a1537ad42941ad4b196ca2faf6aeacd", + "content-hash": "777bb014c5dd195f95f328928c880106", "packages": [], "packages-dev": [ { @@ -936,12 +936,12 @@ "version": "3.6.2", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", "shasum": "" }, @@ -2245,12 +2245,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=5.4" }, - "platform-dev": [], - "plugin-api-version": "2.2.0" + "platform-dev": {}, + "plugin-api-version": "2.9.0" }