<?php
namespace Plugin\TeikiOrder42\EventSubscriber\Controller;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Common\EccubeConfig;
use Eccube\Event\TemplateEvent;
use Eccube\Event\EventArgs;
use Eccube\Event\EccubeEvents;
use Eccube\Entity\Product;
use Eccube\Service\CartService;
use Eccube\Util\StringUtil;
use Eccube\Repository\CartItemRepository;
class ProductControllerSubscriber implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var EccubeConfig
*/
private $eccubeConfig;
/**
* @var CartService
*/
private $cartService;
/**
* @var CartItemRepository
*/
private $cartItemRepository;
/**
* Event constructor.
* @param EntityManagerInterface $entityManager
* @param EccubeConfig $eccubeConfig
* @param CartService $cartService
* @param CartItemRepository $cartItemRepository
*/
public function __construct(
EntityManagerInterface $entityManager,
EccubeConfig $eccubeConfig,
CartService $cartService,
CartItemRepository $cartItemRepository
) {
$this->entityManager = $entityManager;
$this->eccubeConfig = $eccubeConfig;
$this->cartService = $cartService;
$this->cartItemRepository = $cartItemRepository;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'Product/list.twig' => ['DefaultProductList', 1],
EccubeEvents::FRONT_PRODUCT_CART_ADD_INITIALIZE => 'FrontProductCartAddInitialize',
];
}
/**
* @param TemplateEvent $event
*/
public function DefaultProductList(TemplateEvent $event)
{
//$event->addSnippet('@AddOnForProductOption42/default/Product/product_list.twig');
}
public function FrontProductCartAddInitialize(EventArgs $event)
{
$Product = $event->getArgument('Product');
$Cart = $this->cartService->getCart();
}
}