app/Plugin/JoolenPointsForMemberRegistration4/Event.php line 76

Open in your IDE?
  1. <?php
  2. /*
  3.  * Plugin Name: JoolenPointsForMemberRegistration4
  4.  *
  5.  * Copyright(c) joolen inc. All Rights Reserved.
  6.  *
  7.  * https://www.joolen.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\JoolenPointsForMemberRegistration4;
  13. use Eccube\Entity\BaseInfo;
  14. use Eccube\Entity\Customer;
  15. use Eccube\Event\EccubeEvents;
  16. use Eccube\Event\EventArgs;
  17. use Eccube\Event\TemplateEvent;
  18. use Eccube\Repository\BaseInfoRepository;
  19. use Exception;
  20. use Plugin\JoolenPointsForMemberRegistration4\Service\Main\PointsForMemberRegistrationService;
  21. use Plugin\JoolenPointsForMemberRegistration4\Service\Main\PointsForMemberRegistrationSetUpValue;
  22. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  23. class Event implements EventSubscriberInterface
  24. {
  25.     /**
  26.      * @var BaseInfo
  27.      */
  28.     private $baseInfo;
  29.     /**
  30.      * @var PointsForMemberRegistrationService
  31.      */
  32.     private $pointsForMemberRegistrationService;
  33.     /**
  34.      * Event constructor.
  35.      *
  36.      * @param BaseInfoRepository $baseInfoRepository
  37.      * @param PointsForMemberRegistrationService $pointsForMemberRegistrationService
  38.      * @throws Exception
  39.      */
  40.     public function __construct(
  41.         BaseInfoRepository $baseInfoRepository,
  42.         PointsForMemberRegistrationService $pointsForMemberRegistrationService
  43.     )
  44.     {
  45.         $this->baseInfo $baseInfoRepository->get();
  46.         $this->pointsForMemberRegistrationService $pointsForMemberRegistrationService;
  47.     }
  48.     /**
  49.      * @return array
  50.      */
  51.     public static function getSubscribedEvents(): array
  52.     {
  53.         return [
  54.             // --------------
  55.             // Admin
  56.             // --------------
  57.             '@admin/Setting/Shop/shop_master.twig' => 'onRenderShopMaster',
  58.             //---------------
  59.             // Front
  60.             // --------------
  61.             EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE => 'onEntryActivateComplete',
  62.         ];
  63.     }
  64.     /**
  65.      * [管理]設定>店舗設定>基本設定画面の表示
  66.      */
  67.     public function onRenderShopMaster(TemplateEvent $event)
  68.     {
  69.         $twig '@JoolenPointsForMemberRegistration4/admin/Setting/Shop/shop_master.twig';
  70.         $event->addSnippet($twig);
  71.     }
  72.     /**
  73.      * [フロント]メール認証時
  74.      * 仮会員機能が無効の場合、EntryController内でentryActivateの処理を実行するため「FRONT_ENTRY_ACTIVATE_COMPLETE」イベントに該当する
  75.      *       〃 が有効な場合、メールにて送信されたURLにアクセスすることで「FRONT_ENTRY_ACTIVATE_COMPLETE」イベントが実行される
  76.      */
  77.     public function onEntryActivateComplete(EventArgs $EventArgs)
  78.     {
  79.         /** @var Customer $Customer */
  80.         $Customer $EventArgs->getArgument('Customer');
  81.         // 店舗情報から設定値を取得する
  82.         $setUpValue PointsForMemberRegistrationSetUpValue::fromBaseInfo($this->baseInfo);
  83.         // 必要に応じて「ポイント(常時付与設定)」を付与する
  84.         $this->pointsForMemberRegistrationService->grantAlwaysPointIfNeeded($setUpValue$Customer);
  85.         // 必要に応じて「ポイント(期間中のみ付与設定)」を付与する
  86.         $this->pointsForMemberRegistrationService->grantPointDuringPeriodIfNeeded($setUpValue$Customer);
  87.     }
  88. }