app/Plugin/CustomerRank42/Event/EntryEvent.php line 49

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : CustomerRank
  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\CustomerRank42\Event;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Event\EccubeEvents;
  14. use Eccube\Event\EventArgs;
  15. use Plugin\CustomerRank42\Repository\CustomerRankRepository;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. class EntryEvent implements EventSubscriberInterface
  18. {
  19.     private $entityManager;
  20.     private $customerRankRepository;
  21.     /**
  22.      * CustomerRankController constructor.
  23.      * @param CustomerRankRepository $customerRankRepository
  24.      */
  25.     public function __construct(
  26.             EntityManagerInterface $entityManager,
  27.             CustomerRankRepository $customerRankRepository
  28.             )
  29.     {
  30.         $this->entityManager $entityManager;
  31.         $this->customerRankRepository $customerRankRepository;
  32.     }
  33.     /**
  34.      * @return array
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'hookFrontEntryIndexComplete',
  40.         ];
  41.     }
  42.     public function hookFrontEntryIndexComplete(EventArgs $event)
  43.     {
  44.         $Customer $event->getArgument('Customer');
  45.         $CustomerRank $this->customerRankRepository->findOneBy(['initial_flg' => true]);
  46.         if(!is_null($CustomerRank)){
  47.             $Customer->setCustomerRank($CustomerRank);
  48.             $this->entityManager->persist($Customer);
  49.             $this->entityManager->flush($Customer);
  50.         }
  51.     }
  52. }