app/Plugin/CustomerSupportPro42/Event/CustomerEvent.php line 58

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the ContactManagement Plugin
  4.  *
  5.  * Copyright (C) 2020 Diezon.
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Plugin\CustomerSupportPro42\Event;
  11. use Eccube\Event\EventArgs;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Plugin\CustomerSupportPro42\Repository\ContactRepository;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. class CustomerEvent implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var ContactRepository
  19.      */
  20.     protected $contactRepository;
  21.     /**
  22.      * @var EntityManagerInterface
  23.      */
  24.     protected $entityManager;
  25.     /**
  26.      * CustomerEvent constructor.
  27.      *
  28.      * @param ContactRepository $contactRepository
  29.      * @param EntityManagerInterface $entityManager
  30.      */
  31.     public function __construct(
  32.         ContactRepository $contactRepository,
  33.         EntityManagerInterface $entityManager
  34.     ) {
  35.         $this->contactRepository $contactRepository;
  36.         $this->entityManager $entityManager;
  37.     }
  38.     /**
  39.      * @return array
  40.      */
  41.     public static function getSubscribedEvents()
  42.     {
  43.         return [
  44.             'admin.customer.edit.index.complete' => 'onAdminCustomerEditIndexComplete',
  45.         ];
  46.     }
  47.     /**
  48.      * 管理画面 -> 会員登録
  49.      */
  50.     public function onAdminCustomerEditIndexComplete(EventArgs $event)
  51.     {
  52.         $Customer $event->getArgument('Customer');
  53.         if ($Customer->getNote()) {
  54.             $Contacts $this->contactRepository->findBy(['Customer' => $Customer]);
  55.             if ($Contacts) {
  56.                 foreach ($Contacts as $Contact) {
  57.                     $Contact->setNote($Customer->getNote());
  58.                 }
  59.             }
  60.         }
  61.         $this->entityManager->flush();
  62.     }
  63. }