app/Plugin/ASJPayment/ASJPaymentEvent.php line 164

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 Symfony\Component\DependencyInjection\ContainerInterface;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  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 Session
  25.      */
  26.     protected $session;
  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 Session $session
  47.      * @param PaymentRepository $paymentRepository
  48.      */
  49.     public function __construct(
  50.         OrderRepository $orderRepository,
  51.         CartService $cartService,
  52.         SessionInterface $session,
  53.         PaymentRepository $paymentRepository
  54.     ) {
  55.         $this->orderRepository $orderRepository;
  56.         $this->cartService $cartService;
  57.         $this->session $session;
  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 == || $chargeType == 7) {
  90.             $old '<button type="submit" class="ec-blockBtn--action">{{ \'注文する\'|trans }}</button>';
  91.             if (($chargeType == || $chargeType == 7) && 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.         $source $event->getSource();
  106.         if ($this->session->get('pre_order_id')) {
  107.             $old '<div class="ec-off3Grid__cell">';
  108.             $new '<div class="ec-off3Grid__cell" style="width:60%;margin-left:20%;">';
  109.             $source str_replace($old$new$source);
  110.             $old '<div class="ec-off4Grid">';
  111.             $new '<p class="ec-reportDescription" style="color:#ff0000;">'.
  112.                 '【注意】注文は確定していません。<br>'.
  113.                 '「決済手続きへ」をクリックして手続きを行ってください。<br>'.
  114.                 '決済方法を選択した後、払込票等が表示されますので代金をお支払いください。<br>'.
  115.                 'なお、払込票等の画面の印刷等が済みましたら、その画面を閉じてください。<br>'.
  116.                 '</p>'.
  117.                 '<div class="ec-off4Grid">'.
  118.                 '<div class="ec-off4Grid__cell">'.
  119.                 '<a class="ec-blockBtn--action" href="ASJPayment/cvs" target="_blank">決済手続きへ</a><br>'.
  120.                 '</div>'.
  121.                 '</div>'.
  122.                 '<div class="ec-off4Grid">';
  123.             $source str_replace($old$new$source);
  124.             $event->setSource($source);
  125.         } else if ($this->session->get('uncomp_atodene')) {
  126.             $this->session->remove('uncomp_atodene');
  127.             $old '<div class="ec-off4Grid">';
  128.             $new '<p class="ec-reportDescription" style="color:#ff0000;">'.
  129.                 '【注意】現在、後払い決済の利用についての審査結果を確認しております。<br>'.
  130.                 '結果が判明しましたら、改めてご連絡いたします。<br>'.
  131.                 'しばらくお待ちください。<br>'.
  132.                 '</p>'.
  133.                 '<div class="ec-off4Grid">';
  134.             $source str_replace($old$new$source);
  135.             $event->setSource($source);
  136.         } else if ($this->session->get('uncomp_atobarai')) {
  137.             $this->session->remove('uncomp_atobarai');
  138.             $old '<div class="ec-off4Grid">';
  139.             $new '<p class="ec-reportDescription" style="color:#ff0000;">'.
  140.                 '【注意】現在、後払い決済の利用についての審査結果を確認しております。<br>'.
  141.                 '結果が判明しましたら、改めてご連絡いたします。<br>'.
  142.                 'しばらくお待ちください。<br>'.
  143.                 '</p>'.
  144.                 '<div class="ec-off4Grid">';
  145.             $source str_replace($old$new$source);
  146.             $event->setSource($source);
  147.         }
  148.     }
  149.     /**
  150.      * @param TemplateEvent $event
  151.      */
  152.     public function onShoppingIndex(TemplateEvent $event)
  153.     {
  154.         $this->session->remove('pre_order_id');
  155.     }
  156.     /**
  157.      * 管理受注一覧に ASJペイメントの操作追加
  158.      * @param TemplateEvent $event
  159.      */
  160.     public function adminOrderIndexTwig(TemplateEvent $event)
  161.     {
  162.         $event->addSnippet('@ASJPayment/admin/Order/asjpayment_order_index_form.twig');
  163.     }
  164.     /**
  165.      * 管理. 管理受注編集に ASJペイメント売上 / 取消 追加
  166.      * @param TemplateEvent $event
  167.      */
  168.     public function adminOrderEditTwig(TemplateEvent $event)
  169.     {
  170.         $Payments $this->paymentRepository->findBy([], ['sort_no' => 'ASC']);
  171.         $asj_credit_id "";
  172.         foreach($Payments as $Payment) {
  173.             if($Payment->getMethodClass() === 'Plugin\ASJPayment\Service\Method\Credit') {
  174.                 $asj_credit_id $Payment->getId();
  175.                 break;
  176.             }
  177.         }
  178.         $event->addSnippet('@ASJPayment/admin/Order/asjpayment_order_edit_form.twig');
  179.         $parameters $event->getParameters();
  180.         $parameters['ASJ_CREDIT_ID'] = $asj_credit_id;
  181.         $event->setParameters($parameters);
  182.     }
  183. }