app/Customize/EventSubscriber/EntryPointSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. namespace Customize\EventSubscriber;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Eccube\Entity\Customer;
  5. use Eccube\Event\EventArgs;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class EntryPointSubscriber implements EventSubscriberInterface
  8. {
  9.     /**
  10.      * @var EntityManagerInterface
  11.      */
  12.     private $entityManager;
  13.     public function __construct(EntityManagerInterface $entityManager)
  14.     {
  15.         $this->entityManager $entityManager;
  16.     }
  17.     public function onFrontEntryActivateComplete(EventArgs $event)
  18.     {
  19.         $Customer $event->getArgument("Customer");
  20.         if($Customer instanceof Customer) {
  21.             // 会員登録完了時に1000ポイント付与
  22.             $Customer->setPoint(1000);
  23.             $this->entityManager->persist($Customer);
  24.             $this->entityManager->flush();
  25.         }
  26.     }
  27.     public static function getSubscribedEvents()
  28.     {
  29.         return [
  30.            'front.entry.activate.complete' => 'onFrontEntryActivateComplete',
  31.         ];
  32.     }
  33. }