app/Plugin/PointEx/EventSubscriber/CartEventSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/07/26
  5.  */
  6. namespace Plugin\PointEx\EventSubscriber;
  7. use Eccube\Event\TemplateEvent;
  8. use Plugin\PointEx\Config\ConfigSetting;
  9. use Plugin\PointEx\Service\PlgConfigService\ConfigService;
  10. use Plugin\PointEx\Service\PointExHelper;
  11. use Plugin\PointEx\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.     /** @var PointExHelper */
  20.     protected $pointExHelper;
  21.     public function __construct(
  22.         TwigRenderService $twigRenderService,
  23.         ConfigService $configService,
  24.         PointExHelper $pointExHelper
  25.     )
  26.     {
  27.         $this->twigRenderService $twigRenderService;
  28.         $this->configService $configService;
  29.         $this->pointExHelper $pointExHelper;
  30.     }
  31.     /**
  32.      * カートテンプレート
  33.      *
  34.      * @param TemplateEvent $event
  35.      */
  36.     public function onTemplateCartIndex(TemplateEvent $event)
  37.     {
  38.         if (!$this->pointExHelper->isPointUse()) {
  39.             // ポイント利用が無効の場合表示しない
  40.             return;
  41.         }
  42.         if ($this->configService->isKeyBool(ConfigSetting::KEY_CART_VIEW)) {
  43.             $this->twigRenderService->initRenderService($event);
  44.             $eachChild $this->twigRenderService
  45.                 ->eachChildBuilder()
  46.                 ->findThis()
  47.                 ->targetFindAndIndexKey('#point_ex_bonus_point_''pexIndex')
  48.                 ->setInsertModeAppend();
  49.             $this->twigRenderService
  50.                 ->eachBuilder()
  51.                 ->find('.ec-cartRow')
  52.                 ->find('.ec-cartRow__summary')
  53.                 ->setEachIndexKey('pexIndex')
  54.                 ->each($eachChild->build());
  55.             $this->twigRenderService->addSupportSnippet(
  56.                 '@PointEx/default/Cart/index_ex.twig'
  57.             );
  58.         }
  59.     }
  60.     /**
  61.      * Returns an array of event names this subscriber wants to listen to.
  62.      *
  63.      * The array keys are event names and the value can be:
  64.      *
  65.      *  * The method name to call (priority defaults to 0)
  66.      *  * An array composed of the method name to call and the priority
  67.      *  * An array of arrays composed of the method names to call and respective
  68.      *    priorities, or 0 if unset
  69.      *
  70.      * For instance:
  71.      *
  72.      *  * ['eventName' => 'methodName']
  73.      *  * ['eventName' => ['methodName', $priority]]
  74.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  75.      *
  76.      * @return array The event names to listen to
  77.      */
  78.     public static function getSubscribedEvents()
  79.     {
  80.         return [
  81.             'Cart/index.twig' => ['onTemplateCartIndex'10]
  82.         ];
  83.     }
  84. }