app/Plugin/EccubePaymentLite4/EventListener/EventSubscriber/Admin/Order/OrderIndexEventSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite4\EventListener\EventSubscriber\Admin\Order;
  3. use Eccube\Common\EccubeConfig;
  4. use Eccube\Entity\Order;
  5. use Eccube\Entity\Shipping;
  6. use Eccube\Event\TemplateEvent;
  7. use Eccube\Repository\OrderRepository;
  8. use Plugin\EccubePaymentLite4\Entity\PaymentStatus;
  9. use Plugin\EccubePaymentLite4\Repository\PaymentStatusRepository;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class OrderIndexEventSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var OrderRepository
  15.      */
  16.     private $orderRepository;
  17.     /**
  18.      * @var PaymentStatusRepository
  19.      */
  20.     private $paymentStatusRepository;
  21.     /**
  22.      * @var EccubeConfig
  23.      */
  24.     private $eccubeConfig;
  25.     public function __construct(
  26.         OrderRepository $orderRepository,
  27.         PaymentStatusRepository $paymentStatusRepository,
  28.         EccubeConfig $eccubeConfig
  29.     ) {
  30.         $this->orderRepository $orderRepository;
  31.         $this->paymentStatusRepository $paymentStatusRepository;
  32.         $this->eccubeConfig $eccubeConfig;
  33.     }
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return [
  37.             '@admin/Order/index.twig' => 'index',
  38.         ];
  39.     }
  40.     public function index(TemplateEvent $event)
  41.     {
  42.         $orderList $event->getParameter('pagination')->getItems();
  43.         $orders = [];
  44.         foreach ($orderList as $key => $Order) {
  45.             /* @var Order $Order */
  46.             $orders[$key] = $Order->toArray();
  47.             $orders[$key]['PaymentStatus'] = is_null($orders[$key]['PaymentStatus']) ? null $orders[$key]['PaymentStatus']->toArray();
  48.             $orders[$key]['Payment']['payment_method'] = is_null($orders[$key]['payment_method']) ? null $orders[$key]['payment_method'];
  49.             $orders[$key]['Shippings'] = is_null($orders[$key]['Shippings']) ? null $orders[$key]['Shippings']->toArray();
  50.             foreach ($Order->getShippings() as $index => $Shipping) {
  51.                 /* @var Shipping $Shipping */
  52.                 $orders[$key]['Shippings'][$index] = $Shipping->toArray();
  53.             }
  54.         }
  55.         $displayOrders = [];
  56.         foreach ($orders as $key => $order) {
  57.             $displayOrders[$key]['PaymentStatus'] = $order['PaymentStatus'];
  58.             $displayOrders[$key]['payment_method'] = $order['payment_method'];
  59.             foreach ($order['Shippings'] as $index => $shipping) {
  60.                 $displayOrders[$key]['Shippings'][$index] = ['id' => $shipping['id']];
  61.             }
  62.         }
  63.         $PaymentStatuses $this->paymentStatusRepository->findBy([
  64.             'id' => [
  65.                 PaymentStatus::CHARGED,
  66.                 PaymentStatus::SHIPPING_REGISTRATION,
  67.                 PaymentStatus::CANCEL,
  68.             ],
  69.         ], []);
  70.         $event->setParameter('PaymentStatuses'$PaymentStatuses);
  71.         $event->setParameter('orders'$displayOrders);
  72.         $event->setParameter('virtual_account'$this->eccubeConfig['gmo_epsilon']['pay_name']['virtual_account']);
  73.         $event->setParameter('payment_status_id'PaymentStatus::CHARGED);
  74.         $event->addSnippet('@EccubePaymentLite4/admin/Order/index.twig');
  75.     }
  76. }