app/Plugin/YamatoPayment42/YamatoPaymentEvent.php line 270

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\YamatoPayment42;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Event\TemplateEvent;
  15. use Eccube\Repository\ProductRepository;
  16. use Eccube\Repository\OrderRepository;
  17. use Eccube\Repository\PaymentRepository;
  18. use Eccube\Repository\OrderItemRepository;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. use Symfony\Component\Routing\RouterInterface;
  21. use Symfony\Component\HttpFoundation\RequestStack;
  22. use Plugin\YamatoPayment42\Repository\ConfigRepository;
  23. use Plugin\YamatoPayment42\Repository\YamatoOrderRepository;
  24. use Plugin\YamatoPayment42\Repository\YamatoPaymentMethodRepository;
  25. use Plugin\YamatoPayment42\Service\Client\CreditClientService;
  26. use Plugin\YamatoPayment42\Service\Client\CvsClientService;
  27. use Plugin\YamatoPayment42\Service\Method AS YamatoMethod;
  28. class YamatoPaymentEvent implements EventSubscriberInterface
  29. {
  30.     protected $eccubeConfig;
  31.     protected $paymentRepository;
  32.     protected $yamatoPluginRepository;
  33.     protected $yamatoPaymentMethodRepository;
  34.     protected $yamatoOrderRepository;
  35.     protected $productRepository;
  36.     protected $customerRepository;
  37.     protected $router;
  38.     protected $client;
  39.     public function __construct(
  40.         EccubeConfig $eccubeConfig,
  41.         ProductRepository $productRepository,
  42.         OrderRepository $orderRepository,
  43.         OrderItemRepository $orderItemRepository,
  44.         PaymentRepository $paymentRepository,
  45.         ConfigRepository $yamatoPluginRepository,
  46.         YamatoPaymentMethodRepository $yamatoPaymentMethodRepository,
  47.         YamatoOrderRepository $yamatoOrderRepository,
  48.         RouterInterface $router,
  49.         RequestStack $requestStack
  50.     ) {
  51.         $this->eccubeConfig $eccubeConfig;
  52.         $this->productRepository $productRepository;
  53.         $this->orderRepository $orderRepository;
  54.         $this->paymentRepository $paymentRepository;
  55.         $this->yamatoPluginRepository $yamatoPluginRepository;
  56.         $this->yamatoPaymentMethodRepository $yamatoPaymentMethodRepository;
  57.         $this->yamatoOrderRepository $yamatoOrderRepository;
  58.         $this->router $router;
  59.         $this->requestStack $requestStack;
  60.         $this->client = new CreditClientService(
  61.             $this->eccubeConfig,
  62.             $this->productRepository,
  63.             $this->orderRepository,
  64.             $orderItemRepository,
  65.             $this->yamatoPluginRepository,
  66.             $this->yamatoPaymentMethodRepository,
  67.             $this->yamatoOrderRepository,
  68.             $this->router
  69.         );
  70.     }
  71.     /**
  72.      * リッスンしたいサブスクライバのイベント名の配列を返します。
  73.      * 配列のキーはイベント名、値は以下のどれかをしてします。
  74.      * - 呼び出すメソッド名
  75.      * - 呼び出すメソッド名と優先度の配列
  76.      * - 呼び出すメソッド名と優先度の配列の配列
  77.      * 優先度を省略した場合は0
  78.      *
  79.      * 例:
  80.      * - ['eventName' => 'methodName']
  81.      * - ['eventName' => ['methodName', $priority]]
  82.      * - ['eventName' => [['methodName1', $priority], ['methodName2']]]
  83.      *
  84.      * {@inheritdoc}
  85.      */
  86.     public static function getSubscribedEvents()
  87.     {
  88.         return [
  89.             '@admin/Setting/Shop/payment_edit.twig' => 'onAdminSettingShopPaymentEditTwig',
  90.             '@admin/Product/product.twig' => 'onAdminProductProductTwig',
  91.             'Shopping/index.twig' => 'onShoppingIndexTwig',
  92.             'Shopping/confirm.twig' => 'onShoppingConfirmTwig',
  93.             'Mypage/index.twig' => 'onMypageNaviTwig',
  94.             'Mypage/favorite.twig' => 'onMypageNaviTwig',
  95.             'Mypage/change.twig' => 'onMypageNaviTwig',
  96.             'Mypage/withdraw.twig' => 'onMypageNaviTwig',
  97.             'Mypage/delivery.twig' => 'onMypageNaviTwig',
  98.             'Mypage/delivery_edit.twig' => 'onMypageNaviTwig',
  99.             '@YamatoPayment42/mypage/credit.twig' => 'onMypageNaviTwig',
  100.             '@IplPeriodicPurchase42/mypage/index.twig' => 'onMypageNaviTwig',
  101.             '@IplPeriodicPurchase42/mypage/history.twig' => 'onMypageNaviTwig',
  102.             '@IplPeriodicPurchase42/mypage/cycle.twig' => 'onMypageNaviTwig',
  103.             '@IplPeriodicPurchase42/mypage/next_shipping.twig' => 'onMypageNaviTwig',
  104.             '@IplPeriodicPurchase42/mypage/shipping.twig' => 'onMypageNaviTwig',
  105.             '@IplPeriodicPurchase42/mypage/products.twig' => 'onMypageNaviTwig',
  106.             '@IplPeriodicPurchase42/mypage/skip.twig' => 'onMypageNaviTwig',
  107.             '@IplPeriodicPurchase42/mypage/suspend.twig' => 'onMypageNaviTwig',
  108.             '@IplPeriodicPurchase42/mypage/resume.twig' => 'onMypageNaviTwig',
  109.             '@IplPeriodicPurchase42/mypage/cancel.twig' => 'onMypageNaviTwig',
  110.             '@IplPeriodicPurchase42/mypage/complete.twig' => 'onMypageNaviTwig',
  111.         ];
  112.     }
  113.     public function onAdminSettingShopPaymentEditTwig(TemplateEvent $event)
  114.     {
  115.         $event->addSnippet('@YamatoPayment42/admin/payment_register.twig');
  116.         $moduleSettings $this->client->getUserSettings();
  117.         $event->setParameter('moduleSettings'$moduleSettings);
  118.     }
  119.     public function onAdminProductProductTwig(TemplateEvent $event)
  120.     {
  121.         /* 予約商品出荷予定日項目追加 */
  122.         $snipet file_get_contents(__DIR__ '/Resource/template/admin/Product/product_edit.twig');
  123.         // HTML の書き換え
  124.         $search '{# エンティティ拡張の自動出力 #}';
  125.         $replace $snipet $search;
  126.         $source $event->getSource();
  127.         $source str_replace($search$replace$source);
  128.         $event->setSource($source);
  129.         /* パラメータの追加 */
  130.         $parameters $event->getParameters();
  131.         // 追加パラメータを取得
  132.         $moduleSettings $this->client->getUserSettings();
  133.         $addParams = [
  134.             'use_option' => $moduleSettings['use_option'],
  135.             'advance_sale' => $moduleSettings['advance_sale']
  136.         ];
  137.         // パラメータ追加
  138.         $parameters array_merge($parameters$addParams);
  139.         $event->setParameters($parameters);
  140.     }
  141.     public function onShoppingIndexTwig(TemplateEvent $event) {
  142.         $moduleSettings "";
  143.         $creditCardList "";
  144.         $Order $event->getParameter('Order');
  145.         if (!empty($this->eccubeConfig['SALE_TYPE_ID_PERIODIC'])) {
  146.             if ($Order->getSaleTypes()[0]->getId() === $this->eccubeConfig['SALE_TYPE_ID_PERIODIC']) {
  147.                 $event->setParameter('isPeriodic'true);
  148.             } else {
  149.                 $event->setParameter('isPeriodic'false);
  150.             }
  151.         } else {
  152.             $event->setParameter('isPeriodic'false);
  153.         }
  154.         $Payment $Order->getPayment();
  155.         // 配送方法を変えると支払方法が未設定になるケースがある.
  156.         if($Payment === null) return;
  157.         /**
  158.          * 購入フローからの遷移時に 選択された決済方法 を$eventからうまく受け取れないため、
  159.          * requestStackを混ぜた無理矢理な記述になっている。
  160.          * 購入フローからの遷移時(confirm, redirect_to)にelseに入り、requestStackから決済方法を受け取る。
  161.          */
  162.         $request $this->requestStack->getCurrentRequest();
  163.         $dataBag $request->request->get('_shopping_order');
  164.         if($dataBag === null || !array_key_exists('Payment'$dataBag)) {
  165.             $paymentId $Payment->getId();
  166.         } else {
  167.             $paymentId $dataBag['Payment'];
  168.         }
  169.         // クレジットカード決済
  170.         $Credit $this->paymentRepository->findOneBy(['method_class' => YamatoMethod\Credit::class]);
  171.         if (($Credit !== null) && ($paymentId == $Credit->getId())) {
  172.             $this->client->setSetting($Order);
  173.             $moduleSettings $this->client->getModuleSetting();
  174.             if($Order->getCustomer()) {
  175.                 $result $this->client->doGetCard($Order->getCustomer()->getId());
  176.                 if($result) {
  177.                     $creditCardList $this->client::getArrCardInfo($this->client->results);
  178.                 }
  179.             }
  180.             if($creditCardList == "") {
  181.                 $creditCardList = ['cardData' => [], 'cardUnit' => '0'];
  182.             }
  183.             /*
  184.              * 予約商品販売機能の使用有無を判定する
  185.              *     設定ファイルの「予約販売」の利用の有無を取得
  186.              *     カート内商品が「予約販売対象商品」か判定する
  187.              */
  188.             //予約商品存在確認
  189.             $tpl_is_reserv_service $this->client->isReservedOrder($Order);
  190.         
  191.             $yamatoPaymentMethod $this->yamatoPaymentMethodRepository->findOneBy(['Payment' => $Payment]);
  192.             $methodParam $yamatoPaymentMethod->getMemo05();
  193.             $event->addSnippet('@YamatoPayment42/credit.twig');
  194.             $event->setParameter('creditCardList'$creditCardList);
  195.             $event->setParameter('moduleSettings'$moduleSettings);
  196.             $event->setParameter('autoRegist'$methodParam['autoRegist']);
  197.             $event->setParameter('reservService'$tpl_is_reserv_service);
  198.             $event->addSnippet('@YamatoPayment42/kuronekoToken.twig');
  199.         }
  200.         // クロネコ代金後払いサービス(スマホタイプ)
  201.         $DeferredSms $this->paymentRepository->findOneBy(['method_class' => YamatoMethod\DeferredSms::class]);
  202.         if(($DeferredSms !== null) && ($paymentId == $DeferredSms->getId())) {
  203.             $event->addSnippet('@YamatoPayment42/shopping/deferred/sms/deferred_sms.twig');
  204.         }
  205.         // コンビニ決済
  206.         $Cvs $this->paymentRepository->findOneBy(['method_class' => YamatoMethod\Cvs::class]);
  207.         if ($Cvs !== null && $paymentId == $Cvs->getId()) {
  208.             $client = new CvsClientService(
  209.                 $this->eccubeConfig,
  210.                 $this->yamatoPluginRepository,
  211.                 $this->yamatoPaymentMethodRepository,
  212.                 $this->yamatoOrderRepository,
  213.                 $this->router
  214.             );
  215.             $client->setSetting($Order);
  216.             $yamatoPaymentMethod $this->yamatoPaymentMethodRepository->findOneBy(['Payment' => $Payment]);
  217.             $methodParam $yamatoPaymentMethod->getMemo05();
  218.             $event->addSnippet('@YamatoPayment42/cvs.twig');
  219.             $event->addSnippet('@YamatoPayment42/kuronekoToken.twig');
  220.         }
  221.     }
  222.     public function onShoppingConfirmTwig(TemplateEvent $event)
  223.     {
  224.         $Order $event->getParameter('Order');
  225.         if($Order->getPayment()->getMethodClass() === YamatoMethod\Credit::class) {
  226.             $event->addSnippet('@YamatoPayment42/credit_confirm.twig');
  227.         }
  228.         if($Order->getPayment()->getMethodClass() === YamatoMethod\DeferredSms::class) {
  229.             $event->addSnippet('@YamatoPayment42/shopping/deferred/sms/deferred_sms_confirm.twig');
  230.             $event->addSnippet('@YamatoPayment42/shopping/deferred/sms/sms_confirm_button.twig');
  231.         }
  232.         if($Order->getPayment()->getMethodClass() === YamatoMethod\Cvs::class) {
  233.             $event->addSnippet('@YamatoPayment42/cvs_confirm.twig');
  234.         }
  235.     }
  236.     public function onMypageNaviTwig(TemplateEvent $event)
  237.     {
  238.         $setting $this->client->getUserSettings();
  239.         if($setting['use_option'] == '0') {
  240.             // オプションサービス契約時のみ
  241.             $event->addSnippet('@YamatoPayment42/mypage/add_navi.twig');
  242.         }
  243.     }
  244. }