app/Plugin/EccubePaymentLite4/EventListener/EventSubscriber/Front/Shopping/RemoveRegCreditRadioBtnWhenGuest.php line 32

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite4\EventListener\EventSubscriber\Front\Shopping;
  3. use Eccube\Entity\Order;
  4. use Eccube\Event\TemplateEvent;
  5. use Eccube\Repository\PaymentRepository;
  6. use Plugin\EccubePaymentLite4\Service\Method\Reg_Credit;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Form\FormView;
  9. class RemoveRegCreditRadioBtnWhenGuest implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var PaymentRepository
  13.      */
  14.     private $paymentRepository;
  15.     public function __construct(
  16.         PaymentRepository $paymentRepository
  17.     ) {
  18.         $this->paymentRepository $paymentRepository;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             'Shopping/index.twig' => 'index',
  24.         ];
  25.     }
  26.     public function index(TemplateEvent $templateEvent)
  27.     {
  28.         /** @var Order $Order */
  29.         $Order $templateEvent->getParameter('Order');
  30.         // ゲスト購入の場合は登録済みのクレジットカードのラジオボタンを表示しない
  31.         if (is_null($Order->getCustomer())) {
  32.             $RegCreditPayment $this->paymentRepository->findOneBy([
  33.                 'method_class' => Reg_Credit::class,
  34.             ]);
  35.             /** @var FormView $paymentFormView */
  36.             $paymentFormView $templateEvent->getParameter('form')['Payment'];
  37.             if (!is_null($RegCreditPayment) && !is_null($RegCreditPayment->getId())) {
  38.                 $paymentFormView->offsetUnset((string) $RegCreditPayment->getId());
  39.             }
  40.             return;
  41.         }
  42.     }
  43. }