app/Plugin/PointExpired42/Event/FrontEvent.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : PointExpired
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.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\PointExpired42\Event;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Event\EccubeEvents;
  14. use Eccube\Event\EventArgs;
  15. use Plugin\PointExpired42\Repository\ConfigRepository;
  16. use Plugin\PointExpired42\Service\PointExpiredService;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. class FrontEvent implements EventSubscriberInterface
  19. {
  20.     private $entityManager;
  21.     private $configRepository;
  22.     public function __construct(
  23.             EntityManagerInterface $entityManager,
  24.             ConfigRepository $configRepository
  25.             )
  26.     {
  27.         $this->entityManager $entityManager;
  28.         $this->configRepository $configRepository;
  29.     }
  30.     /**
  31.      * @return array
  32.      */
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'hookFrontEntryIndexComplete',
  37.                 ];
  38.     }
  39.     public function hookFrontEntryIndexComplete(EventArgs $event)
  40.     {
  41.         $Customer $event->getArgument('Customer');
  42.         $config $this->configRepository->findOneBy(['name' => 'period']);
  43.         if($config){
  44.             $period $config->getValue();
  45.             $Customer->setExtensionPeriod($period);
  46.             $this->entityManager->persist($Customer);
  47.             $this->entityManager->flush($Customer);
  48.         }
  49.     }
  50. }