app/Plugin/PointNewCustomer42/Event.php line 56

Open in your IDE?
  1. <?php
  2. namespace Plugin\PointNewCustomer42;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Eccube\Event\EccubeEvents;
  5. use Eccube\Event\EventArgs;
  6. use Eccube\Event\TemplateEvent;
  7. use Eccube\Repository\BaseInfoRepository;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class Event implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var EntityManagerInterface
  13.      */
  14.     private $entityManager;
  15.     /**
  16.      * @var BaseInfoRepository
  17.      */
  18.     private $baseInfoRepository;
  19.     public function __construct(
  20.         EntityManagerInterface $entityManager,
  21.         BaseInfoRepository $baseInfoRepository
  22.     ) {
  23.         $this->entityManager $entityManager;
  24.         $this->baseInfoRepository $baseInfoRepository;
  25.     }
  26.     /**
  27.      * @return array
  28.      */
  29.     public static function getSubscribedEvents()
  30.     {
  31.         return [
  32.             EccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE => 'onFrontEntryActivateComplete',
  33.             '@admin/Setting/Shop/shop_master.twig' => 'onAdminSettingShopMasterTwig',
  34.         ];
  35.     }
  36.     public function onFrontEntryActivateComplete(EventArgs $events)
  37.     {
  38.         $BaseInfo $this->baseInfoRepository->get();
  39.         if ($BaseInfo && $BaseInfo->isOptionPoint() && $BaseInfo->getCustomerRegistrationPoint()) {
  40.             $Customer $events->getArgument('Customer');
  41.             $Customer->setPoint($BaseInfo->getCustomerRegistrationPoint());
  42.             $this->entityManager->flush();
  43.         }
  44.     }
  45.     /**
  46.      * @param TemplateEvent $event
  47.      */
  48.     public function onAdminSettingShopMasterTwig(TemplateEvent $event)
  49.     {
  50.         $event->addSnippet('@PointNewCustomer42/admin/Setting/Shop/shop_master_point.twig');
  51.     }
  52. }