app/Plugin/PointEx/EventSubscriber/ShoppingEventSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/07/27
  5.  */
  6. namespace Plugin\PointEx\EventSubscriber;
  7. use Eccube\Entity\Order;
  8. use Eccube\Event\TemplateEvent;
  9. use Plugin\PointEx\Config\ConfigSetting;
  10. use Plugin\PointEx\Service\PlgConfigService\ConfigService;
  11. use Plugin\PointEx\Service\PointExHelper;
  12. use Plugin\PointEx\Service\TwigRenderService\TwigRenderService;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. class ShoppingEventSubscriber implements EventSubscriberInterface
  15. {
  16.     /** @var TwigRenderService */
  17.     protected $twigRenderService;
  18.     /** @var ConfigService */
  19.     protected $configService;
  20.     /** @var PointExHelper */
  21.     protected $pointExHelper;
  22.     public function __construct(
  23.         TwigRenderService $twigRenderService,
  24.         ConfigService $configService,
  25.         PointExHelper $pointExHelper
  26.     )
  27.     {
  28.         $this->twigRenderService $twigRenderService;
  29.         $this->configService $configService;
  30.         $this->pointExHelper $pointExHelper;
  31.     }
  32.     /**
  33.      * ご注文手続きテンプレート
  34.      *
  35.      * @param TemplateEvent $event
  36.      */
  37.     public function onTemplateShopping(TemplateEvent $event)
  38.     {
  39.         if (!$this->pointExHelper->isPointUse()) {
  40.             // ポイント利用が無効の場合表示しない
  41.             return;
  42.         }
  43.         if ($this->configService->isKeyBool(ConfigSetting::KEY_SHOPPING_VIEW)) {
  44.             $this->viewBonusPoint($event);
  45.         }
  46.     }
  47.     /**
  48.      * ご注文確認テンプレート
  49.      *
  50.      * @param TemplateEvent $event
  51.      */
  52.     public function onTemplateShoppingConfirm(TemplateEvent $event)
  53.     {
  54.         if (!$this->pointExHelper->isPointUse()) {
  55.             // ポイント利用が無効の場合表示しない
  56.             return;
  57.         }
  58.         if ($this->configService->isKeyBool(ConfigSetting::KEY_CONFIRM_VIEW)) {
  59.             $this->viewBonusPoint($event);
  60.         }
  61.     }
  62.     private function viewBonusPoint(TemplateEvent $event)
  63.     {
  64.         /** @var Order $order */
  65.         $order $event->getParameter('Order');
  66.         if (!$order->getCustomer()) {
  67.             // 会員購入でない場合
  68.             return;
  69.         }
  70.         $this->twigRenderService->initRenderService($event);
  71.         $child $this->twigRenderService
  72.             ->eachChildBuilder()
  73.             ->findThis()
  74.             ->targetFindAndIndexKey('#point_ex_bonus_point_''pexIndex')
  75.             ->setInsertModeAppend();
  76.         $this->twigRenderService
  77.             ->eachBuilder()
  78.             ->find('.ec-orderDelivery__item')
  79.             ->find('.ec-imageGrid')
  80.             ->find('.ec-imageGrid__content')
  81.             ->setEachIndexKey('pexIndex')
  82.             ->each($child->build());
  83.         $this->twigRenderService->addSupportSnippet('@PointEx/default/Shopping/index_ex.twig');
  84.     }
  85.     /**
  86.      * Returns an array of event names this subscriber wants to listen to.
  87.      *
  88.      * The array keys are event names and the value can be:
  89.      *
  90.      *  * The method name to call (priority defaults to 0)
  91.      *  * An array composed of the method name to call and the priority
  92.      *  * An array of arrays composed of the method names to call and respective
  93.      *    priorities, or 0 if unset
  94.      *
  95.      * For instance:
  96.      *
  97.      *  * ['eventName' => 'methodName']
  98.      *  * ['eventName' => ['methodName', $priority]]
  99.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  100.      *
  101.      * @return array The event names to listen to
  102.      */
  103.     public static function getSubscribedEvents()
  104.     {
  105.         return [
  106.             'Shopping/index.twig' => ['onTemplateShopping'10],
  107.             'Shopping/confirm.twig' => ['onTemplateShoppingConfirm'10],
  108.         ];
  109.     }
  110. }