app/Plugin/PointExDx/EventSubscriber/EntryEventSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright(c) 2022 SYSTEM_KD
  4.  * Date: 2022/06/04
  5.  */
  6. namespace Plugin\PointExDx\EventSubscriber;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Eccube\Entity\Customer;
  9. use Eccube\Event\EccubeEvents;
  10. use Eccube\Event\EventArgs;
  11. use Plugin\PointExDx\Service\PointExDxService;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. /**
  14.  * EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE がなくなったため廃止
  15.  *
  16.  * @deprecated
  17.  */
  18. class EntryEventSubscriber implements EventSubscriberInterface
  19. {
  20.     /** @var EntityManagerInterface */
  21.     private $entityManager;
  22.     /** @var PointExDxService */
  23.     protected $pointExService;
  24.     public function __construct(
  25.         EntityManagerInterface $entityManager,
  26.         PointExDxService       $pointExService
  27.     )
  28.     {
  29.         $this->entityManager $entityManager;
  30.         $this->pointExService $pointExService;
  31.     }
  32.     /**
  33.      * 本会員登録完了時
  34.      *
  35.      * @param EventArgs $event
  36.      * @return void
  37.      */
  38.     public function onFrontEntryActivateComplete(EventArgs $event)
  39.     {
  40.         if ($this->pointExService->isEntryAddPoint()) {
  41.             $addPoint $this->pointExService->getEntryAddPoint();
  42.             /** @var Customer $customer */
  43.             $customer $event->getArgument("Customer");
  44.             $point = (int)$customer->getPoint() + $addPoint;
  45.             $customer->setPoint($point);
  46.             $this->entityManager->persist($customer);
  47.             $this->entityManager->flush();
  48.         }
  49.     }
  50.     /**
  51.      * Returns an array of event names this subscriber wants to listen to.
  52.      *
  53.      * The array keys are event names and the value can be:
  54.      *
  55.      * * The method name to call (priority defaults to 0)
  56.      * * An array composed of the method name to call and the priority
  57.      * * An array of arrays composed of the method names to call and respective
  58.      *   priorities, or 0 if unset
  59.      *
  60.      * For instance:
  61.      *
  62.      * * array('eventName' => 'methodName')
  63.      * * array('eventName' => array('methodName', $priority))
  64.      * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
  65.      *
  66.      */
  67.     public static function getSubscribedEvents()
  68.     {
  69.         return [
  70.             EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE => 'onFrontEntryActivateComplete'
  71.         ];
  72.     }
  73. }