app/Plugin/Paid4/EventSubscriber/AdminOrderEventSubscriber.php line 170

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2020 RACCOON HOLDINGS, Inc. All rights reserved.
  4.  * https://paid.jp/
  5.  */
  6. namespace Plugin\Paid4\EventSubscriber;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Eccube\Common\EccubeConfig;
  9. use Eccube\Entity\Order;
  10. use Eccube\Event\TemplateEvent;
  11. use Plugin\Paid4\Service\Payment\Method\PaidMethod;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Form\FormView;
  14. //use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  15. use Symfony\Component\HttpKernel\Event\ResponseEvent// ここを修正
  16. use Symfony\Component\HttpKernel\KernelEvents;
  17. class AdminOrderEventSubscriber implements EventSubscriberInterface
  18. {
  19.     /**
  20.      * 未決済ステータス
  21.      * @var mixed
  22.      */
  23.     protected $unsettled;
  24.     /**
  25.      * 決済完了ステータス
  26.      * @var mixed
  27.      */
  28.     protected $complete;
  29.     /**
  30.      * キャンセルステータス
  31.      * @var mixed
  32.      */
  33.     protected $cancel;
  34.     /**
  35.      * @var EntityManagerInterface
  36.      */
  37.     protected $entityManager;
  38.     /**
  39.      * OrderEditIndexCompleteListener constructor.
  40.      *
  41.      * @param EccubeConfig $eccubeConfig
  42.      * @param EntityManagerInterface $entityManager
  43.      */
  44.     public function __construct(
  45.         EccubeConfig $eccubeConfig,
  46.         EntityManagerInterface $entityManager
  47.     )
  48.     {
  49.         $this->entityManager $entityManager;
  50.         // 未決済
  51.         $this->unsettled $eccubeConfig['paid4.settlement.unsettled'];
  52.         // 決済完了
  53.         $this->complete $eccubeConfig['paid4.settlement.complete'];
  54.         // キャンセル
  55.         $this->cancel $eccubeConfig['paid4.settlement.cancel'];
  56.     }
  57.     public function onResponse(ResponseEvent $event)
  58.     {
  59.     }
  60.     /**
  61.      * @return array
  62.      */
  63.     public static function getSubscribedEvents(): array
  64.     {
  65.         return [
  66.             KernelEvents::RESPONSE => ['onResponse'],
  67.             '@admin/Order/edit.twig' => 'onAdminOrderEditTwig',
  68.             '@admin/Order/index.twig' => 'onAdminOrderIndexTwig',
  69.         ];
  70.     }
  71.     /**
  72.      * 管理画面 -> 受注一覧 
  73.      */
  74.     public function onAdminOrderIndexTwig(TemplateEvent $event)
  75.     {
  76.         $event->addSnippet('@Paid4/admin/Order/index.twig');
  77.         $pagination $event->getParameter('pagination');
  78.         $PaidOrder = array();
  79.         /** @var Order $Order */
  80.         foreach ($pagination as $Order) {
  81.             $isPaidEntry false;
  82.             if ($Order instanceof Order) {
  83.                 foreach ($Order->getShippings() as $Shipping) {
  84.                     if (!is_null($Order->getPaidOrder())) {
  85.                         $isPaidEntry true;
  86.                         $PaidOrder[$Shipping->getId()]['data'] = $Order->getPaidOrder();
  87.                     } else {
  88.                         $isPaidEntry false;
  89.                         $PaidOrder[$Shipping->getId()]['data'] = null;
  90.                     }
  91.                     $PaidOrder[$Shipping->getId()]['view'] = $isPaidEntry;
  92.                 }
  93.             }
  94.         }
  95.         $event->setParameter('paid_order'$PaidOrder);
  96.     }
  97.     /**
  98.      * 管理画面 -> 受注詳細
  99.      */
  100.     public function onAdminOrderEditTwig(TemplateEvent $event)
  101.     {
  102.         /** @var FormView $form */
  103.         $form $event->getParameter('form');
  104.         /** @var Order $Order */
  105.         $Order $event->getParameter('Order');
  106.         // 管理画面->新規受注登録で作成した受注はpaid支払を選択できないようにする
  107.         if (is_null($Order->getId()) || is_null($Order->getPaidOrder())) {
  108.             foreach ($form->children as $key => $children) {
  109.                 if ($key === 'Payment') {
  110.                     foreach ($children->vars['choices'] as $choice) {
  111.                         if ($choice->data['method_class'] == PaidMethod::class) {
  112.                             $choice->value '';
  113.                             $choice->attr array_merge($choice->attr, ['disabled' => 'disabled']);
  114.                             $choice->attr array_merge($choice->attr, ['class' => 'option-background-color']);
  115.                             break;
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.             $event->addAsset('@Paid4/admin/Order/edit_css.twig');
  121.             $event->setParameter('form'$form);
  122.         }
  123.     }
  124. }