Skip to content

Commit

Permalink
Made subscribers shop context aware so that Criteo is only triggered …
Browse files Browse the repository at this point in the history
…in the shop context
  • Loading branch information
loevgaard committed Nov 4, 2019
1 parent aa785cf commit 23ab001
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
21 changes: 4 additions & 17 deletions src/EventListener/TagSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/Resources/config/services/event_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<argument type="service" id="setono_tag_bag.tag_bag"/>
<argument type="service" id="setono_sylius_criteo.context.account"/>
<argument type="service" id="setono_sylius_criteo.resolver.site_type"/>
<argument type="service" id="request_stack" on-invalid="null"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="security.firewall.map"/>
<tag name="kernel.event_subscriber"/>
</service>
Expand All @@ -18,7 +18,7 @@
<argument type="service" id="setono_tag_bag.tag_bag"/>
<argument type="service" id="setono_sylius_criteo.context.account"/>
<argument>%setono_sylius_criteo.routes.home%</argument>
<argument type="service" id="request_stack" on-invalid="null"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="security.firewall.map"/>
<tag name="kernel.event_subscriber"/>
</service>
Expand All @@ -28,7 +28,7 @@
<argument type="service" id="setono_tag_bag.tag_bag"/>
<argument type="service" id="setono_sylius_criteo.context.account"/>
<argument type="service" id="setono_sylius_criteo.resolver.product_id"/>
<argument type="service" id="request_stack" on-invalid="null"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="security.firewall.map"/>
<tag name="kernel.event_subscriber"/>
</service>
Expand All @@ -38,7 +38,7 @@
<argument type="service" id="setono_tag_bag.tag_bag"/>
<argument type="service" id="setono_sylius_criteo.context.account"/>
<argument type="service" id="setono_sylius_criteo.resolver.product_id"/>
<argument type="service" id="request_stack" on-invalid="null"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="security.firewall.map"/>
<tag name="kernel.event_subscriber"/>
</service>
Expand All @@ -49,7 +49,7 @@
<argument type="service" id="setono_sylius_criteo.context.account"/>
<argument>%setono_sylius_criteo.routes.cart%</argument>
<argument type="service" id="sylius.context.cart.composite"/>
<argument type="service" id="request_stack" on-invalid="null"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="security.firewall.map"/>
<tag name="kernel.event_subscriber"/>
</service>
Expand All @@ -58,7 +58,7 @@
class="Setono\SyliusCriteoPlugin\EventListener\TrackTransactionSubscriber">
<argument type="service" id="setono_tag_bag.tag_bag"/>
<argument type="service" id="setono_sylius_criteo.context.account"/>
<argument type="service" id="request_stack" on-invalid="null"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="security.firewall.map"/>
<tag name="kernel.event_subscriber"/>
</service>
Expand Down

0 comments on commit 23ab001

Please sign in to comment.