app/Plugin/PointEx/EventSubscriber/AdminOrderEditEventSubscriber.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2019 SYSTEM_KD
  4.  * Date: 2019/06/30
  5.  */
  6. namespace Plugin\PointEx\EventSubscriber;
  7. use Eccube\Event\TemplateEvent;
  8. use Plugin\PointEx\Config\ConfigSetting;
  9. use Plugin\PointEx\Service\PlgConfigService\ConfigService;
  10. use Plugin\PointEx\Service\PointExHelper;
  11. use Plugin\PointEx\Service\TwigRenderService\TwigRenderService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class AdminOrderEditEventSubscriber implements EventSubscriberInterface
  14. {
  15.     /** @var TwigRenderService */
  16.     protected $twigRenderService;
  17.     /** @var ConfigService */
  18.     protected $configService;
  19.     /** @var PointExHelper */
  20.     protected $pointExHelper;
  21.     public function __construct(
  22.         TwigRenderService $twigRenderService,
  23.         ConfigService $configService,
  24.         PointExHelper $pointExHelper
  25.     )
  26.     {
  27.         $this->twigRenderService $twigRenderService;
  28.         $this->configService $configService;
  29.         $this->pointExHelper $pointExHelper;
  30.     }
  31.     /**
  32.      * 受注編集
  33.      *
  34.      * @param TemplateEvent $event
  35.      */
  36.     public function onTemplateAdminOrderEdit(TemplateEvent $event)
  37.     {
  38.         // 設定情報取得
  39.         $rateUse $this->configService->getKeyInteger(ConfigSetting::KEY_RATE_USE);
  40.         $event->setParameter('rate_use'$rateUse);
  41.         $this->twigRenderService->initRenderService($event);
  42.         $insertPosition 5;
  43.         // タイトル
  44.         $this->twigRenderService
  45.             ->insertBuilder()
  46.             ->find('#table-form-field')
  47.             ->find('thead > tr > th')
  48.             ->eq($insertPosition)
  49.             ->setTargetId("point_ex_bonus_title")
  50.             ->setInsertModeAfter();
  51.         // ボーナスポイント
  52.         $child $this->twigRenderService
  53.             ->eachChildBuilder()
  54.             ->findThis()
  55.             ->find('td')
  56.             ->eq($insertPosition)
  57.             ->targetFindAndIndexKey('#point_ex_bonus_''pointExIndex')
  58.             ->setInsertModeAfter();
  59.         $this->twigRenderService
  60.             ->eachBuilder()
  61.             ->find('#table-form-field')
  62.             ->find('tbody > tr')
  63.             ->setEachIndexKey('pointExIndex')
  64.             ->each($child->build());
  65.         // 購入時点のポイント付与率
  66.         $this->twigRenderService
  67.             ->insertBuilder()
  68.             ->find('.row.justify-content-end.mb-3')
  69.             ->eq(4)
  70.             ->setTargetId('point_ex_point_rate')
  71.             ->setInsertModeAfter();
  72.         $this->twigRenderService->addSupportSnippet(
  73.             '@PointEx/admin/Order/point_ex_order_edit.twig'
  74.         );
  75.     }
  76.     /**
  77.      * Returns an array of event names this subscriber wants to listen to.
  78.      *
  79.      * The array keys are event names and the value can be:
  80.      *
  81.      *  * The method name to call (priority defaults to 0)
  82.      *  * An array composed of the method name to call and the priority
  83.      *  * An array of arrays composed of the method names to call and respective
  84.      *    priorities, or 0 if unset
  85.      *
  86.      * For instance:
  87.      *
  88.      *  * ['eventName' => 'methodName']
  89.      *  * ['eventName' => ['methodName', $priority]]
  90.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  91.      *
  92.      * @return array The event names to listen to
  93.      */
  94.     public static function getSubscribedEvents()
  95.     {
  96.         return [
  97.             '@admin/Order/edit.twig' => 'onTemplateAdminOrderEdit',
  98.         ];
  99.     }
  100. }