<?php
namespace Plugin\TeikiOrder42\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Eccube\Service\CartService;
use Eccube\Service\OrderHelper;
class RequiredMemberListener implements EventSubscriberInterface
{
/** @var RouterInterface */
protected $router;
protected $cartService;
protected $orderHelper;
/**
* constructor.
* @param RouterInterface $router
* @param OrderHelper $orderHelper
*/
public function __construct(
RouterInterface $router,
CartService $cartService,
OrderHelper $orderHelper
) {
$this->router = $router;
$this->cartService = $cartService;
$this->orderHelper = $orderHelper;
}
public function checkTeikiProductClass(ControllerEvent $event)
{
$controllers = $event->getController();
//if(
// get_class($controllers[0]) == "Eccube\Controller\NonMemberShoppingController"
//) {
//
// $Cart = $this->cartService->getCart();
// $required_member_flg = false;
// if($Cart) {
// foreach ($Cart->getCartItems() as $CartItem) {
// if ($CartItem->isProduct()) {
// if ($CartItem->getProductClass()->getSaleType()->getId() == 4) {
// $required_member_flg = true;
// break;
// }
// }
// }
// }
// if($required_member_flg == true) {
// $event->setController(function() {
//
// $url = $this->router->generate("shopping_login");
// return new RedirectResponse($url);
// });
// }
//}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => 'checkTeikiProductClass',
];
}
}