app/Customize/Event/EstimateEvents.php line 84

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 Customize\Event;
  11. use Customize\Entity\Master\EstimateStatus;
  12. use Customize\Repository\EstimateRepository;
  13. use Customize\Repository\Master\EstimateStatusRepository;
  14. use Customize\Repository\OrderRepository;
  15. use Customize\Service\EstimateHelper;
  16. use Eccube\Event\EventArgs;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Symfony\Component\HttpFoundation\Session\Session;
  20. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  21. class EstimateEvents implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @var Session
  25.      */
  26.     protected $session;
  27.     /**
  28.      * @var EntityManagerInterface
  29.      */
  30.     private $entityManager;
  31.     /**
  32.      * @var OrderRepository
  33.      */
  34.     private $orderRepository;
  35.     /**
  36.      * @var EstimateStatusRepository
  37.      */
  38.     private $estimateStatusRepository;
  39.     /**
  40.      * @var EstimateRepository
  41.      */
  42.     protected EstimateRepository $estimateRepository;
  43.     /**
  44.      * @param EntityManagerInterface $entityManager
  45.      * @param OrderRepository $orderRepository
  46.      */
  47.     public function __construct(
  48.         SessionInterface $session,
  49.         EntityManagerInterface $entityManager,
  50.         OrderRepository $orderRepository,
  51.         EstimateRepository $estimateRepository,
  52.         EstimateStatusRepository $estimateStatusRepository,
  53.     ) {
  54.         $this->session $session;
  55.         $this->entityManager $entityManager;
  56.         $this->orderRepository $orderRepository;
  57.         $this->estimateRepository $estimateRepository;
  58.         $this->estimateStatusRepository $estimateStatusRepository;
  59.     }
  60.     /**
  61.      * @return array
  62.      */
  63.     public static function getSubscribedEvents()
  64.     {
  65.         return [
  66.             'admin.estimate.edit.index.progress' => 'onAdminEstimateEditProgress',
  67.             'front.shopping.complete.initialize' => 'onFrontShoppingComplete',
  68.         ];
  69.     }
  70.     /**
  71.      * 管理画面 -> 見積管理 -> 見積登録時
  72.      */
  73.     public function onAdminEstimateEditProgress(EventArgs $event)
  74.     {
  75.         $TargetEstimate $event->getArgument('TargetEstimate');
  76.         $preEstimateId $TargetEstimate->getPreEstimateId();
  77.         $TargetOrder $this->orderRepository->findOneBy(['pre_order_id' => $preEstimateId]);
  78.         if ($preEstimateId && $TargetOrder) {
  79.             $TargetOrder->setPreOrderId(null);
  80.             $this->entityManager->persist($TargetOrder);
  81.         }
  82.         return;
  83.     }
  84.     /**
  85.      * 注文完了画面 表示時
  86.      */
  87.     public function onFrontShoppingComplete(EventArgs $event)
  88.     {
  89.         // 見積のステータスを「注文済み」に更新
  90.         if ( $estimateId $this->session->get(EstimateHelper::SESSION_ESTIMATE_ID) ) {
  91.             $Estimate $this->estimateRepository->find($estimateId);
  92.             $EstimateStatus $this->estimateStatusRepository->find(EstimateStatus::ORDERED);
  93.             $Estimate->setEstimateStatus($EstimateStatus);
  94.             $this->entityManager->flush();
  95.         }
  96.     }
  97. }