<?php/** * Copyright(c) 2019 SYSTEM_KD * Date: 2019/07/20 */namespace Plugin\PointExDx\EventSubscriber;use Eccube\Entity\Product;use Eccube\Event\TemplateEvent;use Plugin\PointExDx\Config\ConfigSetting;use Plugin\PointExDx\Service\PlgConfigService\ConfigService;use Plugin\PointExDx\Service\PointExDxHelper;use Plugin\PointExDx\Service\TwigRenderService\TwigRenderService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class ProductDetailEventSubscriber implements EventSubscriberInterface{ /** @var TwigRenderService */ protected $twigRenderService; /** @var ConfigService */ protected $configService; /** @var PointExDxHelper */ protected $pointExHelper; public function __construct( TwigRenderService $twigRenderService, ConfigService $configService, PointExDxHelper $pointExHelper ) { $this->twigRenderService = $twigRenderService; $this->configService = $configService; $this->pointExHelper = $pointExHelper; } /** * 商品詳細テンプレート * * @param TemplateEvent $event */ public function onTemplateProductDetail(TemplateEvent $event) { if (!$this->pointExHelper->isPointUse()) { // ポイント利用が無効の場合表示しない return; } if ($this->configService->isKeyBool(ConfigSetting::KEY_DETAIL_VIEW)) { $this->twigRenderService->initRenderService($event); /** @var Product $Product */ $Product = $event->getParameter('Product'); if ($Product->getCodeMin()) { // 商品コード下にボーナスポイント表示追加 $findKey = '.ec-productRole__code'; } else { // 販売価格の下にボーナスポイント表示追加 $findKey = '.ec-productRole__price'; } $this->twigRenderService ->insertBuilder() ->find($findKey) ->eq(0) ->setTargetId('ec-productRole__bonus_point') ->setInsertModeAfter(); $this->twigRenderService->addSupportSnippet( '@PointExDx/default/Product/detail_add.twig', '@PointExDx/default/Product/detail_add_js.twig' ); $event->addAsset('@PointExDx/default/Product/detail_add_css.twig'); } } /** * Returns an array of event names this subscriber wants to listen to. * * The array keys are event names and the value can be: * * * The method name to call (priority defaults to 0) * * An array composed of the method name to call and the priority * * An array of arrays composed of the method names to call and respective * priorities, or 0 if unset * * For instance: * * * ['eventName' => 'methodName'] * * ['eventName' => ['methodName', $priority]] * * ['eventName' => [['methodName1', $priority], ['methodName2']]] * * @return array The event names to listen to */ public static function getSubscribedEvents() { return [ "Product/detail.twig" => ['onTemplateProductDetail'], ]; }}