app/Customize/EventListener/ChainStoreCartSecurityListener.php line 65

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\EventListener;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Eccube\Entity\Customer;
  15. use Eccube\Entity\Member;
  16. use Eccube\Service\CartService;
  17. use Eccube\Service\OrderHelper;
  18. use Eccube\Service\PurchaseFlow\PurchaseContext;
  19. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. use Symfony\Component\HttpFoundation\RequestStack;
  22. use Symfony\Component\Security\Core\AuthenticationEvents;
  23. use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
  24. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  25. use Symfony\Component\Security\Http\SecurityEvents;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. use Symfony\Component\DependencyInjection\ContainerInterface;
  28. use Symfony\Component\HttpFoundation\RedirectResponse;
  29. class ChainStoreCartSecurityListener implements EventSubscriberInterface
  30. {
  31.     protected $em;
  32.     protected $cartService;
  33.     protected $purchaseFlow;
  34.     protected $requestStack;
  35.     protected $container;
  36.     protected $router;
  37.     public function __construct(
  38.         EntityManagerInterface $em,
  39.         CartService $cartService,
  40.         PurchaseFlow $cartPurchaseFlow,
  41.         RequestStack $requestStack,
  42.         ContainerInterface $container
  43.     ) {
  44.         $this->em $em;
  45.         $this->cartService $cartService;
  46.         $this->purchaseFlow $cartPurchaseFlow;
  47.         $this->requestStack $requestStack;
  48.         $this->container $container;
  49.         $this->router $this->container->get('router');
  50.     }
  51.     /**
  52.      * @param InteractiveLoginEvent $event
  53.      */
  54.     public function onInteractiveLogin(InteractiveLoginEvent $event)
  55.     {
  56.         $user $event
  57.             ->getAuthenticationToken()
  58.             ->getUser();
  59.         if ($user instanceof Customer) {
  60.             $ChainStore $user->getChainStore();
  61.             if(is_object($ChainStore)){
  62.                 $this->cartService->clear();
  63.                 //$url = $this->router->generate('shopping');
  64.                 //$response = new RedirectResponse($url);
  65.                 //return $response;
  66.             }
  67.         }
  68.     }
  69.     /**
  70.      * Returns an array of event names this subscriber wants to listen to.
  71.      *
  72.      * The array keys are event names and the value can be:
  73.      *
  74.      * * The method name to call (priority defaults to 0)
  75.      * * An array composed of the method name to call and the priority
  76.      * * An array of arrays composed of the method names to call and respective
  77.      *   priorities, or 0 if unset
  78.      *
  79.      * For instance:
  80.      *
  81.      * * array('eventName' => 'methodName')
  82.      * * array('eventName' => array('methodName', $priority))
  83.      * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
  84.      *
  85.      * @return array The event names to listen to
  86.      */
  87.     public static function getSubscribedEvents()
  88.     {
  89.         return [
  90.             SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
  91.         ];
  92.     }
  93. }