app/Plugin/PointsOnSignUp/Event.php line 57

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : PointsOnSignUp
  4. *
  5. * Copyright (C) 2018 Subspire Inc. All Rights Reserved.
  6. * http://www.subspire.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\PointsOnSignUp;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Entity\Customer;
  14. use Eccube\Event\EventArgs;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Plugin\PointsOnSignUp\Repository\ConfigRepository;
  17. class Event implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * @var EntityManagerInterface
  21.      */
  22.     protected $entityManager;
  23.     /**
  24.      * @var ConfigRepository
  25.      */
  26.     protected $configRepository;
  27.     /**
  28.      * ConfigController constructor.
  29.      *
  30.      * @param EntityManagerInterface $entityManager
  31.      * @param ConfigRepository $configRepository
  32.      */
  33.     public function __construct(EntityManagerInterface $entityManager,ConfigRepository $configRepository)
  34.     {
  35.         $this->entityManager $entityManager;
  36.         $this->configRepository $configRepository;
  37.     }
  38.     /**
  39.      * @return array
  40.      */
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             'front.entry.activate.complete' => 'onFrontEntryActivateComplete'
  45.         ];
  46.     }
  47.     /**
  48.      * @param EventArgs $event
  49.      */
  50.     public function onFrontEntryActivateComplete(EventArgs $event)
  51.     {
  52.         $Config $this->configRepository->get();
  53.         $points_on_sign_up=0;
  54.         if($Config){
  55.             $points_on_sign_up=$Config->getPoints();
  56.         }
  57.         if($points_on_sign_up>0) {
  58.             $Customer $event->getArgument('Customer');
  59.             if ($Customer && $Customer->getId() > 0) {
  60.                 $CustomerId $Customer->getId();
  61.                 $Customer->setPoint($points_on_sign_up);
  62.                 $this->entityManager->persist($Customer);
  63.                 $this->entityManager->flush($Customer);
  64.                 log_info('Points added on to Customer id: '.$CustomerId." on signup.", ['status' => 'Success']);
  65.             }
  66.         }
  67.     }
  68. }