app/Plugin/QuantityDiscountDx/EventSubscriber/ProductEventSubscriber.php line 51

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/04/02
  5.  */
  6. namespace Plugin\QuantityDiscountDx\EventSubscriber;
  7. use Eccube\Entity\Product;
  8. use Eccube\Event\TemplateEvent;
  9. use Plugin\QuantityDiscountDx\Service\ConfigService;
  10. use Plugin\QuantityDiscountDx\Service\QuantityDiscountService;
  11. use Plugin\QuantityDiscountDx\Service\TwigRenderService\TwigRenderService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /**
  14.  * まとめ買い値引リスト表示サポート
  15.  *
  16.  * Class ProductEventSubscriber
  17.  * @package Plugin\QuantityDiscountDx\EventSubscriber
  18.  */
  19. class ProductEventSubscriber implements EventSubscriberInterface
  20. {
  21.     /** @var QuantityDiscountService */
  22.     protected $quantityDiscountService;
  23.     /** @var TwigRenderService */
  24.     protected $twigRenderService;
  25.     /** @var ConfigService */
  26.     protected $configService;
  27.     public function __construct(
  28.         QuantityDiscountService $quantityDiscountService,
  29.         TwigRenderService $twigRenderService,
  30.         ConfigService $configService
  31.     )
  32.     {
  33.         $this->quantityDiscountService $quantityDiscountService;
  34.         $this->twigRenderService $twigRenderService;
  35.         $this->configService $configService;
  36.     }
  37.     /**
  38.      * 商品詳細 テンプレート
  39.      *
  40.      * @param TemplateEvent $event
  41.      */
  42.     public function onTemplateProductDetail(TemplateEvent $event)
  43.     {
  44.         if ($this->configService->isKeyBool(ConfigService::SETTING_KEY_DETAIL_LIST_VIEW)) {
  45.             // 一覧表示用CSS
  46.             $event->addAsset('@QuantityDiscountDx/default/Product/detail_ex_css.twig');
  47.             // 規格選択時のBold JS
  48.             $event->addSnippet('@QuantityDiscountDx/default/Product/detail_ex_js.twig');
  49.             // 一覧挿入
  50.             $this->twigRenderService->initRenderService($event);
  51.             $insertBuilder $this->twigRenderService->insertBuilder();
  52.             if($this->configService->getKeyInteger(ConfigService::SETTING_KEY_DETAIL_LIST_POSITION)
  53.                 == ConfigService::DISCOUNT_POSITION_DETAIL) {
  54.                 $insertBuilder
  55.                     ->find('.ec-productRole__profile')
  56.                     ->eq(0);
  57.             } else {
  58.                 $insertBuilder
  59.                     ->find('.ec-productRole__actions')
  60.                     ->eq(0);
  61.             }
  62.             $insertBuilder
  63.                 ->setTemplate("@QuantityDiscountDx/default/Product/detail_ex.twig")
  64.                 ->setTargetId("qd_list")
  65.                 ->setInsertModeAppend();
  66.             $this->twigRenderService->addSupportSnippet();
  67.         }
  68.     }
  69.     /**
  70.      * Returns an array of event names this subscriber wants to listen to.
  71.      *
  72.      * The array keys are event names and the value can be:
  73.      *
  74.      *  * The method name to call (priority defaults to 0)
  75.      *  * An array composed of the method name to call and the priority
  76.      *  * An array of arrays composed of the method names to call and respective
  77.      *    priorities, or 0 if unset
  78.      *
  79.      * For instance:
  80.      *
  81.      *  * ['eventName' => 'methodName']
  82.      *  * ['eventName' => ['methodName', $priority]]
  83.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  84.      *
  85.      * @return array The event names to listen to
  86.      */
  87.     public static function getSubscribedEvents()
  88.     {
  89.         return [
  90.             'Product/detail.twig' => ['onTemplateProductDetail']
  91.         ];
  92.     }
  93. }