app/Plugin/PinpointSale/EventSubscriber/ShoppingEventSubscriber.php line 62

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 ShoppingEventSubscriber implements EventSubscriberInterface
  14. {
  15.     /** @var TwigRenderService */
  16.     protected $twigRenderService;
  17.     /** @var ConfigService */
  18.     protected $configService;
  19.     use ConfigSupportTrait;
  20.     /**
  21.      * ShoppingEventSubscriber 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 onTemplateShopping(TemplateEvent $event)
  39.     {
  40.         // タイムセール名称設定
  41.         $this->setDiscountName($event);
  42.         if ($this->configService->isKeyBool(ConfigSetting::SETTING_KEY_SHOPPING_VIEW)) {
  43.             $this->viewPinpointSale($event);
  44.         }
  45.     }
  46.     /**
  47.      * ご注文確認テンプレート
  48.      *
  49.      * @param TemplateEvent $event
  50.      */
  51.     public function onTemplateShoppingConfirm(TemplateEvent $event)
  52.     {
  53.         // タイムセール名称設定
  54.         $this->setDiscountName($event);
  55.         if ($this->configService->isKeyBool(ConfigSetting::SETTING_KEY_CONFIRM_VIEW)) {
  56.             $this->viewPinpointSale($event);
  57.         }
  58.     }
  59.     /**
  60.      * タイムセール表示追加
  61.      *
  62.      * @param TemplateEvent $event
  63.      */
  64.     private function viewPinpointSale(TemplateEvent $event)
  65.     {
  66.         $this->twigRenderService->initRenderService($event);
  67.         $child $this->twigRenderService
  68.             ->eachChildBuilder()
  69.             ->findThis()
  70.             ->targetFindAndIndexKey('#pinpoint_sale_price_''pinpointSaleIndex')
  71.             ->setInsertModeAppend();
  72.         $this->twigRenderService
  73.             ->eachBuilder()
  74.             ->find('.ec-orderDelivery__item')
  75.             ->find('.ec-imageGrid')
  76.             ->find('.ec-imageGrid__content')
  77.             ->setEachIndexKey('pinpointSaleIndex')
  78.             ->each($child->build());
  79.         $this->twigRenderService->addSupportSnippet('@PinpointSale/default/Shopping/index_ex.twig');
  80.     }
  81.     /**
  82.      * Returns an array of event names this subscriber wants to listen to.
  83.      *
  84.      * The array keys are event names and the value can be:
  85.      *
  86.      *  * The method name to call (priority defaults to 0)
  87.      *  * An array composed of the method name to call and the priority
  88.      *  * An array of arrays composed of the method names to call and respective
  89.      *    priorities, or 0 if unset
  90.      *
  91.      * For instance:
  92.      *
  93.      *  * ['eventName' => 'methodName']
  94.      *  * ['eventName' => ['methodName', $priority]]
  95.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  96.      *
  97.      * @return array The event names to listen to
  98.      */
  99.     public static function getSubscribedEvents()
  100.     {
  101.         return [
  102.             'Shopping/index.twig' => ['onTemplateShopping'],
  103.             'Shopping/confirm.twig' => ['onTemplateShoppingConfirm'],
  104.         ];
  105.     }
  106. }