From 4ab5578ba1cd3dc6dfae0ec5449095f8db9395f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Wed, 7 Feb 2024 09:26:17 +0100 Subject: [PATCH 1/7] Remove ajaxDie --- controllers/admin/AdminGanalyticsAjax.php | 4 ++-- controllers/front/ajax.php | 4 ++-- tests/phpstan/phpstan-1.7.7.neon | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/controllers/admin/AdminGanalyticsAjax.php b/controllers/admin/AdminGanalyticsAjax.php index 2deb985..012d087 100644 --- a/controllers/admin/AdminGanalyticsAjax.php +++ b/controllers/admin/AdminGanalyticsAjax.php @@ -31,9 +31,9 @@ public function init() if (Validate::isLoadedObject($order) && (isset($this->context->employee->id) && $this->context->employee->id)) { (new GanalyticsRepository())->markOrderAsSent((int) $orderId); - $this->ajaxDie('OK'); + $this->ajaxRender('OK'); } - $this->ajaxDie('KO'); + $this->ajaxRender('KO'); } } diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 4c104e5..166a1f5 100644 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -35,11 +35,11 @@ public function initContent() $order = new Order($orderId); if (!Validate::isLoadedObject($order) || $order->id_customer != (int) Tools::getValue('customer')) { - $this->ajaxDie('KO'); + $this->ajaxRender('KO'); } (new GanalyticsRepository())->markOrderAsSent((int) $orderId); - $this->ajaxDie('OK'); + $this->ajaxRender('OK'); } } diff --git a/tests/phpstan/phpstan-1.7.7.neon b/tests/phpstan/phpstan-1.7.7.neon index 364a960..caca568 100644 --- a/tests/phpstan/phpstan-1.7.7.neon +++ b/tests/phpstan/phpstan-1.7.7.neon @@ -6,3 +6,4 @@ parameters: - '#PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler::uninstallModule\(\) calls parent::uninstall\(\) but PrestaShop\\Module\\Ps_Googleanalytics\\Handler\\ModuleHandler does not extend any class.#' - '#Access to an undefined property Cookie\:\:\$ga_admin_order.#' - '#Access to an undefined property Cookie\:\:\$ga_admin_refund.#' + - '#Parameter \#1 \$value of method ControllerCore::ajaxRender\(\) expects null, string given.#' From 548aad0b43dd47638c57d59d57bda88fc96e7677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Wed, 7 Feb 2024 15:20:10 +0100 Subject: [PATCH 2/7] Add exit command --- controllers/admin/AdminGanalyticsAjax.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/admin/AdminGanalyticsAjax.php b/controllers/admin/AdminGanalyticsAjax.php index 012d087..1ec6dbc 100644 --- a/controllers/admin/AdminGanalyticsAjax.php +++ b/controllers/admin/AdminGanalyticsAjax.php @@ -32,8 +32,10 @@ public function init() if (Validate::isLoadedObject($order) && (isset($this->context->employee->id) && $this->context->employee->id)) { (new GanalyticsRepository())->markOrderAsSent((int) $orderId); $this->ajaxRender('OK'); + exit; } $this->ajaxRender('KO'); + exit; } } From 08a413201e9b7b8573abfcd004902288b330d354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Wed, 7 Feb 2024 15:20:33 +0100 Subject: [PATCH 3/7] Update ajax.php --- controllers/front/ajax.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 166a1f5..c77698e 100644 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -36,10 +36,12 @@ public function initContent() if (!Validate::isLoadedObject($order) || $order->id_customer != (int) Tools::getValue('customer')) { $this->ajaxRender('KO'); + exit; } (new GanalyticsRepository())->markOrderAsSent((int) $orderId); $this->ajaxRender('OK'); + exit; } } From 6700f60785576b71f92876291d7543f79a07e096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Tue, 20 Feb 2024 15:12:20 +0100 Subject: [PATCH 4/7] Update ps_googleanalytics.php --- ps_googleanalytics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ps_googleanalytics.php b/ps_googleanalytics.php index 394f04c..bc9a711 100644 --- a/ps_googleanalytics.php +++ b/ps_googleanalytics.php @@ -47,7 +47,7 @@ public function __construct() { $this->name = 'ps_googleanalytics'; $this->tab = 'analytics_stats'; - $this->version = '5.0.0'; + $this->version = '5.0.1'; $this->ps_versions_compliancy = ['min' => '1.7.7', 'max' => _PS_VERSION_]; $this->author = 'PrestaShop'; $this->module_key = 'fd2aaefea84ac1bb512e6f1878d990b8'; From 8951fae583205538383c418a8bd9ba357ed4dcf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Tue, 20 Feb 2024 15:12:45 +0100 Subject: [PATCH 5/7] Update config.xml --- config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.xml b/config.xml index 1ff7523..9fc803a 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_googleanalytics - + From aa086ebca3295df631e1a3f5f84b38c51cec3c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hlav=C3=A1=C4=8Dek?= Date: Wed, 28 Feb 2024 16:21:58 +0100 Subject: [PATCH 6/7] Check if property exists on controller --- classes/Hook/HookActionValidateOrder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/Hook/HookActionValidateOrder.php b/classes/Hook/HookActionValidateOrder.php index 284a23e..e70c747 100644 --- a/classes/Hook/HookActionValidateOrder.php +++ b/classes/Hook/HookActionValidateOrder.php @@ -53,8 +53,9 @@ public function __construct(Ps_Googleanalytics $module, Context $context) */ public function run() { - // Check if we are creating backoffice order - if ($this->context->controller->controller_name != 'AdminOrders' && $this->context->controller->controller_name != 'Admin') { + // Check if we are creating backoffice order, we are only launching this hook when creating backoffice order + // For FO purposes, we use displayOrderConfirmation. + if (empty($this->context->controller->controller_name) || ($this->context->controller->controller_name != 'AdminOrders' && $this->context->controller->controller_name != 'Admin')) { return; } From d8bd75fcc22a1439dc686968241e52ee98997afe Mon Sep 17 00:00:00 2001 From: Matthieu Rolland Date: Wed, 28 Feb 2024 16:55:48 +0100 Subject: [PATCH 7/7] fix condition in order validation hook --- classes/Hook/HookActionValidateOrder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/Hook/HookActionValidateOrder.php b/classes/Hook/HookActionValidateOrder.php index e70c747..cd27092 100644 --- a/classes/Hook/HookActionValidateOrder.php +++ b/classes/Hook/HookActionValidateOrder.php @@ -55,7 +55,8 @@ public function run() { // Check if we are creating backoffice order, we are only launching this hook when creating backoffice order // For FO purposes, we use displayOrderConfirmation. - if (empty($this->context->controller->controller_name) || ($this->context->controller->controller_name != 'AdminOrders' && $this->context->controller->controller_name != 'Admin')) { + if (empty($this->context->controller->controller_name) + || !in_array($this->context->controller->controller_name, ['AdminOrders', 'Admin'])) { return; }