app/Plugin/PinpointSale/EventSubscriber/ProductDetailEventSubscriber.php line 54

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/08/25
  5.  */
  6. namespace Plugin\PinpointSale\EventSubscriber;
  7. use Eccube\Entity\Product;
  8. use Eccube\Event\TemplateEvent;
  9. use Plugin\PinpointSale\Config\ConfigSetting;
  10. use Plugin\PinpointSale\Config\ConfigSupportTrait;
  11. use Plugin\PinpointSale\Service\PinpointSaleService;
  12. use Plugin\PinpointSale\Service\PlgConfigService\ConfigService;
  13. use Plugin\PinpointSale\Service\TwigRenderService\TwigRenderService;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class ProductDetailEventSubscriber implements EventSubscriberInterface
  16. {
  17.     /** @var TwigRenderService */
  18.     protected $twigRenderService;
  19.     /** @var ConfigService */
  20.     protected $configService;
  21.     /** @var PinpointSaleService */
  22.     protected $pinpointSaleService;
  23.     use ConfigSupportTrait;
  24.     /**
  25.      * ProductDetailEventSubscriber constructor.
  26.      * @param TwigRenderService $twigRenderService
  27.      * @param ConfigService $configService
  28.      * @param PinpointSaleService $pinpointSaleService
  29.      */
  30.     public function __construct(
  31.         TwigRenderService $twigRenderService,
  32.         ConfigService $configService,
  33.         PinpointSaleService $pinpointSaleService
  34.     )
  35.     {
  36.         $this->twigRenderService $twigRenderService;
  37.         $this->configService $configService;
  38.         $this->pinpointSaleService $pinpointSaleService;
  39.     }
  40.     /**
  41.      * 商品詳細 テンプレート
  42.      *
  43.      * @param TemplateEvent $event
  44.      */
  45.     public function onTemplateProductDetail(TemplateEvent $event)
  46.     {
  47.         // タイムセール名称設定
  48.         $this->setDiscountName($event);
  49.         $this->twigRenderService->initRenderService($event);
  50.         /** @var Product $Product */
  51.         $Product $event->getParameter('Product');
  52.         $viewFile null;
  53.         $jsFile null;
  54.         // 表示追加判定
  55.         if ($this->configService->isKeyBool(ConfigSetting::SETTING_KEY_PRODUCE_DETAIL_VIEW)) {
  56.             // 表示場所調整
  57.             if ($Product->getPrice01Min()) {
  58.                 if ($Product->getPrice01Max()) {
  59.                     $findKey '.ec-productRole__priceRegularTax';
  60.                 } else {
  61.                     $findKey '.ec-productRole__priceRegular';
  62.                 }
  63.             } else {
  64.                 $findKey '.ec-productRole__tags';
  65.             }
  66.             $this->twigRenderService
  67.                 ->insertBuilder()
  68.                 ->find($findKey)
  69.                 ->eq(0)
  70.                 ->setTargetId('ec-productRole__pinpoint_sale')
  71.                 ->setInsertModeAfter();
  72.             $viewFile '@PinpointSale/default/Product/detail_add.twig';
  73.         }
  74.         // jS追加判定
  75.         if ($this->configService->isKeyBool(ConfigSetting::SETTING_KEY_PRODUCT_DETAIL_JS)) {
  76.             $jsFile '@PinpointSale/default/Product/detail_add_js.twig';
  77.         }
  78.         $this->twigRenderService->addSupportSnippet($viewFile$jsFile);
  79.     }
  80.     /**
  81.      * Returns an array of event names this subscriber wants to listen to.
  82.      *
  83.      * The array keys are event names and the value can be:
  84.      *
  85.      *  * The method name to call (priority defaults to 0)
  86.      *  * An array composed of the method name to call and the priority
  87.      *  * An array of arrays composed of the method names to call and respective
  88.      *    priorities, or 0 if unset
  89.      *
  90.      * For instance:
  91.      *
  92.      *  * ['eventName' => 'methodName']
  93.      *  * ['eventName' => ['methodName', $priority]]
  94.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  95.      *
  96.      * @return array The event names to listen to
  97.      */
  98.     public static function getSubscribedEvents()
  99.     {
  100.         return [
  101.             "Product/detail.twig" => ['onTemplateProductDetail'],
  102.         ];
  103.     }
  104. }