app/Customize/Controller/CustomizeEntryController.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.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 Customize\Controller;
  13. use Eccube\Controller\EntryController;
  14. use Eccube\Entity\BaseInfo;
  15. use Eccube\Entity\Master\CustomerStatus;
  16. use Eccube\Event\EccubeEvents;
  17. use Eccube\Event\EventArgs;
  18. use Eccube\Form\Type\Front\EntryType;
  19. use Eccube\Repository\CustomerRepository;
  20. use Eccube\Repository\PageRepository;
  21. use Eccube\Service\MailService;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  26. use Symfony\Component\Validator\Constraints as Assert;
  27. class CustomizeEntryController extends EntryController
  28. {
  29.     /**
  30.      * 会員登録画面.
  31.      *
  32.      * @Route("/entry", name="entry", methods={"GET", "POST"})
  33.      * @Route("/entry", name="entry_confirm", methods={"GET", "POST"})
  34.      * @Template("Entry/index.twig")
  35.      */
  36.     public function index(Request $request)
  37.     {
  38.         if ($this->isGranted('ROLE_USER')) {
  39.             log_info('認証済のためログイン処理をスキップ');
  40.             return $this->redirectToRoute('mypage');
  41.         }
  42.         /** @var $Customer \Eccube\Entity\Customer */
  43.         $Customer $this->customerRepository->newCustomer();
  44.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  45.         $builder $this->formFactory->createBuilder(EntryType::class, $Customer);
  46.         $event = new EventArgs(
  47.             [
  48.                 'builder' => $builder,
  49.                 'Customer' => $Customer,
  50.             ],
  51.             $request
  52.         );
  53.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_INITIALIZE);
  54.         /* @var $form \Symfony\Component\Form\FormInterface */
  55.         $form $builder->getForm();
  56.         $form->handleRequest($request);
  57.         if ($form->isSubmitted() && $form->isValid()) {
  58.             switch ($request->get('mode')) {
  59.                 case 'confirm':
  60.                     log_info('会員登録確認開始');
  61.                     log_info('会員登録確認完了');
  62.                     return $this->render(
  63.                         'Entry/confirm.twig',
  64.                         [
  65.                             'form' => $form->createView(),
  66.                             'Page' => $this->pageRepository->getPageByRoute('entry_confirm'),
  67.                         ]
  68.                     );
  69.                 case 'complete':
  70.                     log_info('会員登録開始');
  71.                     $encoder $this->encoderFactory->getEncoder($Customer);
  72.                     $salt $encoder->createSalt();
  73.                     $password $encoder->encodePassword($Customer->getPlainPassword(), $salt);
  74.                     $secretKey $this->customerRepository->getUniqueSecretKey();
  75.                     $Customer
  76.                         ->setSalt($salt)
  77.                         ->setPassword($password)
  78.                         ->setSecretKey($secretKey)
  79.                         ->setPoint(0);
  80.                     $this->entityManager->persist($Customer);
  81.                     $this->entityManager->flush();
  82.                     log_info('会員登録完了');
  83.                     $event = new EventArgs(
  84.                         [
  85.                             'form' => $form,
  86.                             'Customer' => $Customer,
  87.                         ],
  88.                         $request
  89.                     );
  90.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_INDEX_COMPLETE);
  91.                     $activateFlg $this->BaseInfo->isOptionCustomerActivate();
  92.                     // 仮会員設定が有効な場合は、確認メールを送信し完了画面表示.
  93.                     if ($activateFlg) {
  94.                         $activateUrl $this->generateUrl('entry_activate', ['secret_key' => $Customer->getSecretKey()], UrlGeneratorInterface::ABSOLUTE_URL);
  95.                         // メール送信
  96.                         $this->mailService->sendCustomerConfirmMail($Customer$activateUrl);
  97.                         if ($event->hasResponse()) {
  98.                             return $event->getResponse();
  99.                         }
  100.                         log_info('仮会員登録完了画面へリダイレクト');
  101.                         return $this->redirectToRoute('entry_complete');
  102.                     } else {
  103.                         // 仮会員設定が無効な場合は、会員登録を完了させる.
  104.                         $qtyInCart $this->entryActivate($request$Customer->getSecretKey());
  105.                         // URLを変更するため完了画面にリダイレクト
  106.                         return $this->redirectToRoute('entry_activate', [
  107.                             'secret_key' => $Customer->getSecretKey(),
  108.                             'qtyInCart' => $qtyInCart,
  109.                         ]);
  110.                     }
  111.             }
  112.         }
  113.         // 紹介者取得
  114.         $getMember $request->query->get('collaboration');
  115.         if($getMember) {
  116.             $menber '';
  117.             if($getMember == 'ishida') {
  118.                 $menber '石田';
  119.             } elseif($getMember == 'nishida') {
  120.                 $menber '西田';
  121.             }
  122.             $form->get('customerplus_1')->setData($menber);
  123.         }
  124.         return $this->render(
  125.             'Entry/index.twig',
  126.             [
  127.                 'form' => $form->createView(),
  128.                 'member' => 'test',
  129.             ]
  130.         );
  131.     }
  132.     /**
  133.      * 会員登録処理を行う
  134.      *
  135.      * @param Request $request
  136.      * @param $secret_key
  137.      *
  138.      * @return \Eccube\Entity\Cart|mixed
  139.      */
  140.     private function entryActivate(Request $request$secret_key)
  141.     {
  142.         log_info('本会員登録開始');
  143.         $Customer $this->customerRepository->getProvisionalCustomerBySecretKey($secret_key);
  144.         if (is_null($Customer)) {
  145.             throw new HttpException\NotFoundHttpException();
  146.         }
  147.         $CustomerStatus $this->customerStatusRepository->find(CustomerStatus::REGULAR);
  148.         $Customer->setStatus($CustomerStatus);
  149.         $this->entityManager->persist($Customer);
  150.         $this->entityManager->flush();
  151.         log_info('本会員登録完了');
  152.         $event = new EventArgs(
  153.             [
  154.                 'Customer' => $Customer,
  155.             ],
  156.             $request
  157.         );
  158.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_ENTRY_ACTIVATE_COMPLETE);
  159.         // メール送信
  160.         $this->mailService->sendCustomerCompleteMail($Customer);
  161.         // Assign session carts into customer carts
  162.         $Carts $this->cartService->getCarts();
  163.         $qtyInCart 0;
  164.         foreach ($Carts as $Cart) {
  165.             $qtyInCart += $Cart->getTotalQuantity();
  166.         }
  167.         if ($qtyInCart) {
  168.             $this->cartService->save();
  169.         }
  170.         return $qtyInCart;
  171.     }
  172. }