app/Plugin/ASJPayment/ASJPaymentEvent.php line 165

Open in your IDE?
  1. <?php
  2. namespace Plugin\ASJPayment;
  3. use Eccube\Event\EventArgs;
  4. use Eccube\Event\EccubeEvents;
  5. use Eccube\Event\TemplateEvent;
  6. use Eccube\Repository\OrderRepository;
  7. use Eccube\Service\CartService;
  8. use Eccube\Service\PurchaseFlow\PurchaseContext;
  9. use Psr\Container\ContainerInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Eccube\Repository\PaymentRepository;
  13. class ASJPaymentEvent implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var OrderRepository
  17.      */
  18.     protected $orderRepository;
  19.     /**
  20.      * @var CartService
  21.      */
  22.     protected $cartService;
  23.     /**
  24.      * @var RequestStack
  25.      */
  26.     protected $requestStack;
  27.     /**
  28.      * @var PaymentRepository
  29.      */
  30.     protected $paymentRepository;
  31.     /**
  32.      * @var array
  33.      */
  34.     private $chargeTypes = [
  35.         'Plugin\ASJPayment\Service\Method\Credit' => 1,
  36.         'Plugin\ASJPayment\Service\Method\Cvs' => 2,
  37.         'Plugin\ASJPayment\Service\Method\Cvs2' => 3,
  38.         'Plugin\ASJPayment\Service\Method\Atodene' => 4,
  39.         'Plugin\ASJPayment\Service\Method\Atobarai' => 7,
  40.     ];
  41.     /**
  42.      * ASJPaymentEvent constructor.
  43.      *
  44.      * @param OrderRepository $orderRepository
  45.      * @param CartService $cartService
  46.      * @param RequestStack $requestStack
  47.      * @param PaymentRepository $paymentRepository
  48.      */
  49.     public function __construct(
  50.         OrderRepository $orderRepository,
  51.         CartService $cartService,
  52.         RequestStack $requestStack,
  53.         PaymentRepository $paymentRepository
  54.     ) {
  55.         $this->orderRepository $orderRepository;
  56.         $this->cartService $cartService;
  57.         $this->requestStack $requestStack;
  58.         $this->paymentRepository $paymentRepository;
  59.     }
  60.     /**
  61.      * @return array
  62.      */
  63.     public static function getSubscribedEvents()
  64.     {
  65.         return [
  66.         'Shopping/index.twig' => 'onShoppingIndex',
  67.             'Shopping/confirm.twig' => 'onShoppingConfirm',
  68.             'Shopping/complete.twig' => 'onShoppingComplete',
  69.             '@admin/Order/index.twig' => 'adminOrderIndexTwig'// 受注一覧
  70.             '@admin/Order/edit.twig' => 'adminOrderEditTwig'    // 受注登録
  71.         ];
  72.     }
  73.     /**
  74.      * @param TemplateEvent $event
  75.      */
  76.     public function onShoppingConfirm(TemplateEvent $event)
  77.     {
  78.         $source $event->getSource();
  79.         $preOrderId $this->cartService->getPreOrderId();
  80.         if (!$preOrderId) {
  81.             return;
  82.         }
  83.         $Order $this->orderRepository->findOneBy(['pre_order_id' => $preOrderId]);
  84.         $methodClass $Order->getPayment()->getMethodClass();
  85.         $chargeType = isset($this->chargeTypes[$methodClass]) ? $this->chargeTypes[$methodClass] : 0;
  86.         if (!$chargeType) {
  87.             return;
  88.         }
  89.         if ($chargeType == || $chargeType == 7) {
  90.             $old '<button type="submit" class="ec-blockBtn--action">{{ \'注文する\'|trans }}</button>';
  91.             if ($chargeType == && count($Order->getShippings()) > 1) {
  92.                 $new '<button type="submit" class="ec-blockBtn--action" disabled="disabled" style="font-size:14px;line-height:18px;">お届け先を複数にする場合は<br>他のお支払方法をご利用ください。</button>';
  93.             } else {
  94.                 $new '<button type="submit" class="ec-blockBtn--action">{{ \'決済手続きに進む\'|trans }}</button>';
  95.             }
  96.             $source str_replace($old$new$source);
  97.             $event->setSource($source);
  98.         }
  99.     }
  100.     /**
  101.      * @param TemplateEvent $event
  102.      */
  103.     public function onShoppingComplete(TemplateEvent $event)
  104.     {
  105.         $session $this->requestStack->getSession();
  106.         $source $event->getSource();
  107.         if ($session->get('pre_order_id')) {
  108.             $old '<div class="ec-off3Grid__cell">';
  109.             $new '<div class="ec-off3Grid__cell" style="width:60%;margin-left:20%;">';
  110.             $source str_replace($old$new$source);
  111.             $old '<div class="ec-off4Grid">';
  112.             $new '<p class="ec-reportDescription" style="color:#ff0000;">'.
  113.                 '【注意】注文は確定していません。<br>'.
  114.                 '「決済手続きへ」をクリックして手続きを行ってください。<br>'.
  115.                 '決済方法を選択した後、払込票等が表示されますので代金をお支払いください。<br>'.
  116.                 'なお、払込票等の画面の印刷等が済みましたら、その画面を閉じてください。<br>'.
  117.                 '</p>'.
  118.                 '<div class="ec-off4Grid">'.
  119.                 '<div class="ec-off4Grid__cell">'.
  120.                 '<a class="ec-blockBtn--action" href="ASJPayment/cvs" target="_blank">決済手続きへ</a><br>'.
  121.                 '</div>'.
  122.                 '</div>'.
  123.                 '<div class="ec-off4Grid">';
  124.             $source str_replace($old$new$source);
  125.             $event->setSource($source);
  126.         } else if ($session->get('uncomp_atodene')) {
  127.             $session->remove('uncomp_atodene');
  128.             $old '<div class="ec-off4Grid">';
  129.             $new '<p class="ec-reportDescription" style="color:#ff0000;">'.
  130.                 '【注意】現在、後払い決済の利用についての審査結果を確認しております。<br>'.
  131.                 '結果が判明しましたら、改めてご連絡いたします。<br>'.
  132.                 'しばらくお待ちください。<br>'.
  133.                 '</p>'.
  134.                 '<div class="ec-off4Grid">';
  135.             $source str_replace($old$new$source);
  136.             $event->setSource($source);
  137.         } else if ($session->get('uncomp_atobarai')) {
  138.             $session->remove('uncomp_atobarai');
  139.             $old '<div class="ec-off4Grid">';
  140.             $new '<p class="ec-reportDescription" style="color:#ff0000;">'.
  141.                 '【注意】現在、後払い決済の利用についての審査結果を確認しております。<br>'.
  142.                 '結果が判明しましたら、改めてご連絡いたします。<br>'.
  143.                 'しばらくお待ちください。<br>'.
  144.                 '</p>'.
  145.                 '<div class="ec-off4Grid">';
  146.             $source str_replace($old$new$source);
  147.             $event->setSource($source);
  148.         }
  149.     }
  150.     /**
  151.      * @param TemplateEvent $event
  152.      */
  153.     public function onShoppingIndex(TemplateEvent $event)
  154.     {
  155.         $session $this->requestStack->getSession();
  156.         $session->remove('pre_order_id');
  157.     }
  158.     /**
  159.      * 管理受注一覧に ASJペイメントの操作追加
  160.      * @param TemplateEvent $event
  161.      */
  162.     public function adminOrderIndexTwig(TemplateEvent $event)
  163.     {
  164.         $event->addSnippet('@ASJPayment/admin/Order/asjpayment_order_index_form.twig');
  165.     }
  166.     /**
  167.      * 管理. 管理受注編集に ASJペイメント売上 / 取消 追加
  168.      * @param TemplateEvent $event
  169.      */
  170.     public function adminOrderEditTwig(TemplateEvent $event)
  171.     {
  172.         $Payments $this->paymentRepository->findBy([], ['sort_no' => 'ASC']);
  173.         $asj_credit_id "";
  174.         foreach($Payments as $Payment) {
  175.             if($Payment->getMethodClass() === 'Plugin\ASJPayment\Service\Method\Credit') {
  176.                 $asj_credit_id $Payment->getId();
  177.                 break;
  178.             }
  179.         }
  180.         $event->addSnippet('@ASJPayment/admin/Order/asjpayment_order_edit_form.twig');
  181.         $parameters $event->getParameters();
  182.         $parameters['ASJ_CREDIT_ID'] = $asj_credit_id;
  183.         $event->setParameters($parameters);
  184.     }
  185. }