app/Plugin/TeikiOrder42/EventListener/RequiredMemberListener.php line 36

Open in your IDE?
  1. <?php
  2. namespace Plugin\TeikiOrder42\EventListener;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use Symfony\Component\Routing\RouterInterface;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Eccube\Service\CartService;
  9. use Eccube\Service\OrderHelper;
  10. class RequiredMemberListener implements EventSubscriberInterface
  11. {
  12.     /** @var RouterInterface */
  13.     protected $router;
  14.     protected $cartService;
  15.     protected $orderHelper;
  16.     /**
  17.      * constructor.
  18.      * @param RouterInterface $router
  19.      * @param OrderHelper $orderHelper
  20.      */
  21.     public function __construct(
  22.         RouterInterface $router,
  23.         CartService $cartService,
  24.         OrderHelper $orderHelper
  25.     ) {
  26.         $this->router $router;
  27.         $this->cartService $cartService;
  28.         $this->orderHelper $orderHelper;
  29.     }
  30.     public function checkTeikiProductClass(ControllerEvent $event)
  31.     {
  32.         $controllers $event->getController();
  33.         //if(
  34.         //    get_class($controllers[0]) == "Eccube\Controller\NonMemberShoppingController"
  35.         //) {
  36. //
  37.         //    $Cart = $this->cartService->getCart();
  38.         //    $required_member_flg = false;
  39.         //    if($Cart) {
  40.         //        foreach ($Cart->getCartItems() as $CartItem) {
  41.         //            if ($CartItem->isProduct()) {
  42.         //                if ($CartItem->getProductClass()->getSaleType()->getId() == 4) {
  43.         //                    $required_member_flg = true;
  44.         //                    break;
  45.         //                }
  46.         //            }
  47.         //        }
  48.         //    }
  49.         //    if($required_member_flg == true) {
  50.         //        $event->setController(function() {
  51. //
  52.         //            $url = $this->router->generate("shopping_login");
  53.         //            return new RedirectResponse($url);
  54.         //        });
  55.         //    }
  56.         //}
  57.     }
  58.     public static function getSubscribedEvents()
  59.     {
  60.         return [
  61.             KernelEvents::CONTROLLER => 'checkTeikiProductClass',
  62.         ];
  63.     }
  64. }