app/Plugin/CartUpRecommend/EventSubscriber/CartEventSubscriber.php line 51

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2020 SYSTEM_KD
  4.  * Date: 2020/03/24
  5.  */
  6. namespace Plugin\CartUpRecommend\EventSubscriber;
  7. use Eccube\Event\EventArgs;
  8. use Eccube\Event\TemplateEvent;
  9. use Plugin\CartUpRecommend\Service\TwigRenderService\EventSubscriber\TwigRenderTrait;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class CartEventSubscriber implements EventSubscriberInterface
  12. {
  13.     use TwigRenderTrait;
  14.     /**
  15.      * カート画面テンプレート
  16.      *
  17.      * @param TemplateEvent $event
  18.      */
  19.     public function onTemplateCartIndex(TemplateEvent $event)
  20.     {
  21.         $this->initRenderService($event);
  22.         $eachChild $this->twigRenderService
  23.             ->eachChildBuilder()
  24.             ->findThis()
  25.             ->targetFindAndIndexKey('.cart_up_recommend_''cartUpRecommendIndex')
  26.             ->setInsertModeAfter();
  27.         $this->twigRenderService
  28.             ->eachBuilder()
  29.             ->find('.ec-cartRow')
  30.             ->setEachIndexKey('cartUpRecommendIndex')
  31.             ->each($eachChild->build());
  32.         $this->addTwigRenderSnippet('@CartUpRecommend/default/Cart/index_ex.twig'nulltrue);
  33.         $event->addAsset('@CartUpRecommend/default/Cart/index_css.twig');
  34.     }
  35.     /**
  36.      * タイムセール連携
  37.      *
  38.      * @param EventArgs $event
  39.      */
  40.     public function onPinpointSaleHelperHookRoute(EventArgs $event)
  41.     {
  42.         $hookRoute $event->getArgument('hookRoute');
  43.         $hookRoute['car_up_recommend_up'] = 1;
  44.         $event->setArgument('hookRoute'$hookRoute);
  45.     }
  46.     /**
  47.      * @inheritDoc
  48.      */
  49.     public static function getSubscribedEvents()
  50.     {
  51.         return [
  52.             'Cart/index.twig' => ['onTemplateCartIndex', -100],
  53.             // タイムセール
  54.             'pinpoint_sale.helper.hook_route' => ['onPinpointSaleHelperHookRoute']
  55.         ];
  56.     }
  57. }