<?php
/**
* Copyright(c) 2020 SYSTEM_KD
* Date: 2020/03/24
*/
namespace Plugin\CartUpRecommend\EventSubscriber;
use Eccube\Event\EventArgs;
use Eccube\Event\TemplateEvent;
use Plugin\CartUpRecommend\Service\TwigRenderService\EventSubscriber\TwigRenderTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CartEventSubscriber implements EventSubscriberInterface
{
use TwigRenderTrait;
/**
* カート画面テンプレート
*
* @param TemplateEvent $event
*/
public function onTemplateCartIndex(TemplateEvent $event)
{
$this->initRenderService($event);
$eachChild = $this->twigRenderService
->eachChildBuilder()
->findThis()
->targetFindAndIndexKey('.cart_up_recommend_', 'cartUpRecommendIndex')
->setInsertModeAfter();
$this->twigRenderService
->eachBuilder()
->find('.ec-cartRow')
->setEachIndexKey('cartUpRecommendIndex')
->each($eachChild->build());
$this->addTwigRenderSnippet('@CartUpRecommend/default/Cart/index_ex.twig', null, true);
$event->addAsset('@CartUpRecommend/default/Cart/index_css.twig');
}
/**
* タイムセール連携
*
* @param EventArgs $event
*/
public function onPinpointSaleHelperHookRoute(EventArgs $event)
{
$hookRoute = $event->getArgument('hookRoute');
$hookRoute['car_up_recommend_up'] = 1;
$event->setArgument('hookRoute', $hookRoute);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
'Cart/index.twig' => ['onTemplateCartIndex', -100],
// タイムセール
'pinpoint_sale.helper.hook_route' => ['onPinpointSaleHelperHookRoute']
];
}
}