From 23ab001a69dc8f396c75c77bcd3e405cdbce628b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Mon, 4 Nov 2019 11:08:08 +0100 Subject: [PATCH] Made subscribers shop context aware so that Criteo is only triggered in the shop context --- src/EventListener/TagSubscriber.php | 21 ++++--------------- .../config/services/event_listener.xml | 12 +++++------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/EventListener/TagSubscriber.php b/src/EventListener/TagSubscriber.php index 562be8f..7e9df85 100644 --- a/src/EventListener/TagSubscriber.php +++ b/src/EventListener/TagSubscriber.php @@ -12,7 +12,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Security\Http\FirewallMapInterface; abstract class TagSubscriber implements EventSubscriberInterface { @@ -37,20 +36,20 @@ abstract class TagSubscriber implements EventSubscriberInterface private $hasAccount; /** - * @var RequestStack|null + * @var RequestStack */ private $requestStack; /** - * @var FirewallMapInterface|null + * @var FirewallMap */ private $firewallMap; public function __construct( TagBagInterface $tagBag, AccountContextInterface $accountContext, - RequestStack $requestStack = null, - FirewallMapInterface $firewallMap = null + RequestStack $requestStack, + FirewallMap $firewallMap ) { $this->tagBag = $tagBag; $this->accountContext = $accountContext; @@ -95,19 +94,7 @@ protected function getAccount(): AccountInterface protected function isShopContext(Request $request = null): bool { - if (null === $this->firewallMap) { - return true; - } - - if (!$this->firewallMap instanceof FirewallMap) { - return true; - } - if (null === $request) { - if (null === $this->requestStack) { - return true; - } - $request = $this->requestStack->getCurrentRequest(); if (null === $request) { return true; diff --git a/src/Resources/config/services/event_listener.xml b/src/Resources/config/services/event_listener.xml index 6790152..c1d50b5 100644 --- a/src/Resources/config/services/event_listener.xml +++ b/src/Resources/config/services/event_listener.xml @@ -8,7 +8,7 @@ - + @@ -18,7 +18,7 @@ %setono_sylius_criteo.routes.home% - + @@ -28,7 +28,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -49,7 +49,7 @@ %setono_sylius_criteo.routes.cart% - + @@ -58,7 +58,7 @@ class="Setono\SyliusCriteoPlugin\EventListener\TrackTransactionSubscriber"> - +