Skip to content

Commit

Permalink
Merge pull request #12 from gillesbourgeat/feature/login-logout
Browse files Browse the repository at this point in the history
Add case when login and logout
  • Loading branch information
gillesbourgeat authored Dec 9, 2016
2 parents 2294cac + 01efd11 commit 3255ab7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
24 changes: 6 additions & 18 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@
<loop name="wishlist" class="WishList\Loop\WishList" />
</loops>

<forms>
<!--
<form name="MyFormName" class="MyModule\Form\MySuperForm" />
-->
</forms>

<commands>
<!--
<command class="MyModule\Command\MySuperCommand" />
-->
</commands>

<templateDirectives>
<!-- Sample definition
<templateDirectives class="MyModule\Directive\MyTemplateDirective" name="my_filter"/>
-->
</templateDirectives>

<services>
<service id="wishList.smarty.plugin" class="WishList\Smarty\Plugins\WishList" scope="request">
<argument type="service" id="request"/>
Expand All @@ -35,5 +17,11 @@
<service id="wishList.action" class="WishList\Action\WishList">
<tag name="kernel.event_subscriber"/>
</service>

<service id="wishList.customer.listener" class="WishList\EventListener\CustomerListener">
<argument type="service" id="request_stack"/>
<argument type="service" id="thelia.securityContext"/>
<tag name="kernel.event_subscriber"/>
</service>
</services>
</config>
6 changes: 4 additions & 2 deletions Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<descriptive locale="en_US">
<title>Wish list</title>
</descriptive>
<version>1.1.0</version>
<version>1.2.0</version>
<author>
<name>Michaël Espeche</name>
<email>mespeche@openstudio.fr</email>
<name>Gilles Bourgeat</name>
<email>gbourgeat@openstudio.fr</email>
</author>
<type>classic</type>
<thelia>2.1.0</thelia>
<thelia>2.3.0</thelia>
<stability>prod</stability>
</module>
51 changes: 51 additions & 0 deletions EventListener/CustomerListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace WishList\EventListener;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\SecurityContext;
use WishList\Controller\Front\WishListController;
use WishList\Model\WishListQuery;

/**
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
*/
class CustomerListener implements EventSubscriberInterface
{
/** @var RequestStack */
protected $requestStack;

/** @var SecurityContext */
protected $securityContext;

public function __construct(RequestStack $requestStack, SecurityContext $securityContext)
{
$this->requestStack = $requestStack;
$this->securityContext = $securityContext;
}

public function customerLogout(Event $event)
{
$this->requestStack->getCurrentRequest()->getSession()->set(WishListController::SESSION_NAME, []);
}

public function customerLogin(Event $event)
{
if ($this->securityContext->hasCustomerUser()) {
$ids = WishListQuery::create()->filterByCustomerId($this->securityContext->getCustomerUser()->getId())->select('id')->find()->toArray();

$this->requestStack->getCurrentRequest()->getSession()->set(WishListController::SESSION_NAME, $ids);
}
}

public static function getSubscribedEvents()
{
return array(
TheliaEvents::CUSTOMER_LOGOUT => array("customerLogout", 128),
TheliaEvents::CUSTOMER_LOGIN => array("customerLogin", 64)
);
}
}

0 comments on commit 3255ab7

Please sign in to comment.