app/Plugin/PinpointSale/EventSubscriber/CartEventSubscriber.php line 47

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/08/18
  5.  */
  6. namespace Plugin\PinpointSale\EventSubscriber;
  7. use Eccube\Event\TemplateEvent;
  8. use Plugin\PinpointSale\Config\ConfigSetting;
  9. use Plugin\PinpointSale\Config\ConfigSupportTrait;
  10. use Plugin\PinpointSale\Service\PlgConfigService\ConfigService;
  11. use Plugin\PinpointSale\Service\TwigRenderService\TwigRenderService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class CartEventSubscriber implements EventSubscriberInterface
  14. {
  15.     /** @var TwigRenderService */
  16.     protected $twigRenderService;
  17.     /** @var ConfigService */
  18.     protected $configService;
  19.     use ConfigSupportTrait;
  20.     /**
  21.      * CartEventSubscriber constructor.
  22.      * @param TwigRenderService $twigRenderService
  23.      * @param ConfigService $configService
  24.      */
  25.     public function __construct(
  26.         TwigRenderService $twigRenderService,
  27.         ConfigService $configService
  28.     )
  29.     {
  30.         $this->twigRenderService $twigRenderService;
  31.         $this->configService $configService;
  32.     }
  33.     /**
  34.      * カートテンプレート
  35.      *
  36.      * @param TemplateEvent $event
  37.      */
  38.     public function onTemplateCartIndex(TemplateEvent $event)
  39.     {
  40.         // タイムセール名称設定
  41.         $this->setDiscountName($event);
  42.         if (!$this->configService->isKeyBool(ConfigSetting::SETTING_KEY_CART_VIEW)) {
  43.             return;
  44.         }
  45.         $this->twigRenderService->initRenderService($event);
  46.         $eachChild $this->twigRenderService
  47.             ->eachChildBuilder()
  48.             ->findThis()
  49.             ->targetFindAndIndexKey('#pinpoint_sale_price_''pinpointSaleIndex')
  50.             ->setInsertModeAppend();
  51.         $this->twigRenderService
  52.             ->eachBuilder()
  53.             ->find('.ec-cartRow')
  54.             ->find('.ec-cartRow__summary')
  55.             ->setEachIndexKey('pinpointSaleIndex')
  56.             ->each($eachChild->build());
  57.         $this->twigRenderService->addSupportSnippet(
  58.             '@PinpointSale/default/Cart/index_ex.twig'
  59.         );
  60.     }
  61.     /**
  62.      * Returns an array of event names this subscriber wants to listen to.
  63.      *
  64.      * The array keys are event names and the value can be:
  65.      *
  66.      *  * The method name to call (priority defaults to 0)
  67.      *  * An array composed of the method name to call and the priority
  68.      *  * An array of arrays composed of the method names to call and respective
  69.      *    priorities, or 0 if unset
  70.      *
  71.      * For instance:
  72.      *
  73.      *  * ['eventName' => 'methodName']
  74.      *  * ['eventName' => ['methodName', $priority]]
  75.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  76.      *
  77.      * @return array The event names to listen to
  78.      */
  79.     public static function getSubscribedEvents()
  80.     {
  81.         return [
  82.             'Cart/index.twig' => ['onTemplateCartIndex'],
  83.         ];
  84.     }
  85. }