app/Plugin/NZCustomPlugin/EventListener/RegistrationEventListener.php line 61

Open in your IDE?
  1. <?php
  2. namespace Plugin\NZCustomPlugin\EventListener;
  3. use Eccube\Event\EccubeEvents;
  4. use Eccube\Event\EventArgs;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\RedirectResponse;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  10. use Symfony\Component\HttpKernel\KernelEvents;
  11. class RegistrationEventListener implements EventSubscriberInterface
  12. {
  13.     private $session;
  14.     private $router;
  15.     public function __construct(
  16.         SessionInterface $session,
  17.         RouterInterface $router
  18.     ) {
  19.         $this->session $session;
  20.         $this->router $router;
  21.     }
  22.     public static function getSubscribedEvents()
  23.     {
  24.         return [
  25.             EccubeEvents::FRONT_ENTRY_INDEX_COMPLETE => 'onRegistrationComplete',
  26.             'kernel.response' => 'onKernelResponse',
  27.         ];
  28.     }
  29.     /**
  30.      * 会員登録完了時の処理
  31.      */
  32.     public function onRegistrationComplete(EventArgs $event)
  33.     {
  34.         // セッションからリダイレクト先フォームキーを取得
  35.         $formKey $this->session->get('redirect_to_form');
  36.         
  37.         if ($formKey) {
  38.             // 仮登録完了フラグを設定
  39.             $this->session->set('eccube.front.entry.complete'true);
  40.             
  41.             // リダイレクトURLを生成(フォームの説明画面へ)
  42.             $redirectUrl $this->router->generate('nzcustomplugin_form_display', ['key' => $formKey]);
  43.             
  44.             // レスポンスをリダイレクトに変更
  45.             $response = new RedirectResponse($redirectUrl);
  46.             $event->setResponse($response);
  47.         }
  48.     }
  49.     
  50.     /**
  51.      * 会員登録完了ページからのリダイレクト処理
  52.      */
  53.     public function onKernelResponse(ResponseEvent $event)
  54.     {
  55.         if (!$event->isMasterRequest()) {
  56.             return;
  57.         }
  58.         
  59.         $request $event->getRequest();
  60.         $route $request->attributes->get('_route');
  61.         
  62.         // 会員登録完了ページの場合
  63.         if ($route === 'entry_complete') {
  64.             $formKey $this->session->get('redirect_to_form');
  65.             
  66.             if ($formKey) {
  67.                 // 仮登録完了フラグを設定
  68.                 $this->session->set('eccube.front.entry.complete'true);
  69.                 
  70.                 // フォーム画面へリダイレクト
  71.                 $redirectUrl $this->router->generate('nzcustomplugin_form_display', ['key' => $formKey]);
  72.                 $response = new RedirectResponse($redirectUrl);
  73.                 $event->setResponse($response);
  74.             }
  75.         }
  76.     }
  77. }