From a2d13ab3c1adfe4ace393a8eeb13cbe563a74d8a Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Thu, 16 Nov 2023 12:16:36 +0100 Subject: [PATCH] Fixed tracking code inclusion --- Config/config.xml | 1 + Config/module.xml | 2 +- Hook/HookManager.php | 53 +++++++++---------- .../default/tracking_script.html | 3 +- 4 files changed, 29 insertions(+), 30 deletions(-) rename templates/{backOffice => frontOffice}/default/tracking_script.html (84%) diff --git a/Config/config.xml b/Config/config.xml index 207c6f5..aa5a721 100644 --- a/Config/config.xml +++ b/Config/config.xml @@ -11,6 +11,7 @@ + diff --git a/Config/module.xml b/Config/module.xml index 766eec5..c7fb1d0 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 1.1.7 + 1.1.8 Chabreuil Antoine diff --git a/Hook/HookManager.php b/Hook/HookManager.php index 9eab824..0c6f333 100644 --- a/Hook/HookManager.php +++ b/Hook/HookManager.php @@ -1,14 +1,21 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* Copyright (c) OpenStudio */ +/* email : dev@thelia.net */ +/* web : http://www.thelia.net */ + +/* For the full copyright and license information, please view the LICENSE.txt */ +/* file that was distributed with this source code. */ namespace Brevo\Hook; @@ -18,14 +25,12 @@ use Thelia\Core\Event\Hook\HookRenderEvent; use Thelia\Core\Hook\BaseHook; use Thelia\Core\HttpFoundation\Request; -use Thelia\Core\Template\Assets\AssetResolverInterface; use Thelia\Model\ConfigQuery; use Thelia\Model\Customer; -use TheliaSmarty\Template\SmartyParser; class HookManager extends BaseHook { - /** @var Request */ + /** @var Request */ protected $request; public function __construct(RequestStack $requestStack, EventDispatcherInterface $eventDispatcher) @@ -35,30 +40,22 @@ public function __construct(RequestStack $requestStack, EventDispatcherInterface $this->request = $requestStack->getCurrentRequest(); } - public function onModuleConfiguration(HookRenderEvent $event) + public function onModuleConfiguration(HookRenderEvent $event): void { $event->add( - $this->render("brevo-configuration.html") + $this->render('brevo-configuration.html') ); } - public function onMainHeadTop(HookRenderEvent $event) + public function onMainHeadTop(HookRenderEvent $event): void { - $apiKey = ConfigQuery::read(Brevo::CONFIG_API_SECRET); - - //$this->get('thelia.customer_user'); /** @var Customer $customer */ - $customer = $this->request->getSession()->getCustomerUser(); - - $email = null; - if ($customer !== null) { - $email = $customer->getEmail(); - } + $customer = $this->request->getSession()?->getCustomerUser(); $event->add( - $this->render("tracking_script.html",[ - 'apiKey' => $apiKey, - 'email' => $email + $this->render('tracking_script.html', [ + 'marketingAutomationKey' => ConfigQuery::read(Brevo::CONFIG_AUTOMATION_KEY), + 'email' => $customer?->getEmail(), ]) ); } diff --git a/templates/backOffice/default/tracking_script.html b/templates/frontOffice/default/tracking_script.html similarity index 84% rename from templates/backOffice/default/tracking_script.html rename to templates/frontOffice/default/tracking_script.html index 6d5bc20..0707a13 100644 --- a/templates/backOffice/default/tracking_script.html +++ b/templates/frontOffice/default/tracking_script.html @@ -24,6 +24,7 @@ } var n = document.createElement("script"), i = document.getElementsByTagName("script")[0]; - n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?plugin=prestashop&key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page(); + n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?plugin=thelia&key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page(); + console.log('doner'); })();