app/Customize/Controller/BuyController.php line 58

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\Entity\Customer;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\Front\ContactType;
  17. use Eccube\Repository\PageRepository;
  18. use Eccube\Service\MailService;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Eccube\Controller\AbstractController;
  23. class BuyController extends AbstractController
  24. {
  25.     /**
  26.      * @var MailService
  27.      */
  28.     protected $mailService;
  29.     /**
  30.      * @var PageRepository
  31.      */
  32.     private $pageRepository;
  33.     /**
  34.      * ContactController constructor.
  35.      *
  36.      * @param MailService $mailService
  37.      * @param PageRepository $pageRepository
  38.      */
  39.     public function __construct(
  40.         MailService $mailService,
  41.         PageRepository $pageRepository)
  42.     {
  43.         $this->mailService $mailService;
  44.         $this->pageRepository $pageRepository;
  45.     }
  46.     /**
  47.      * @Route("/buy", name="buy", methods={"GET", "POST"})
  48.           * @Route("/contact", name="contact_confirm", methods={"GET", "POST"})
  49.      * @Template("@user_data/buy.twig")
  50.      */
  51.  public function buy(Request $request)
  52.     {
  53.         $builder $this->formFactory->createBuilder(ContactType::class);
  54.         if ($this->isGranted('ROLE_USER')) {
  55.             /** @var Customer $user */
  56.             $user $this->getUser();
  57.             $builder->setData(
  58.                 [
  59.                     'name01' => $user->getName01(),
  60.                     'name02' => $user->getName02(),
  61.                     'kana01' => $user->getKana01(),
  62.                     'kana02' => $user->getKana02(),
  63.                     'postal_code' => $user->getPostalCode(),
  64.                     'pref' => $user->getPref(),
  65.                     'addr01' => $user->getAddr01(),
  66.                     'addr02' => $user->getAddr02(),
  67.                     'phone_number' => $user->getPhoneNumber(),
  68.                     'email' => $user->getEmail(),
  69.                 ]
  70.             );
  71.         }
  72.         // FRONT_CONTACT_INDEX_INITIALIZE
  73.         $event = new EventArgs(
  74.             [
  75.                 'builder' => $builder,
  76.             ],
  77.             $request
  78.         );
  79.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  80.         $form $builder->getForm();
  81.         $form->handleRequest($request);
  82.         if ($form->isSubmitted() && $form->isValid()) {
  83.             switch ($request->get('mode')) {
  84.                 case 'confirm':
  85.                     return $this->render('Contact/confirm.twig', [
  86.                         'form' => $form->createView(),
  87.                         'Page' => $this->pageRepository->getPageByRoute('contact_confirm'),
  88.                     ]);
  89.                 case 'complete':
  90.                     $data $form->getData();
  91.                     $event = new EventArgs(
  92.                         [
  93.                             'form' => $form,
  94.                             'data' => $data,
  95.                         ],
  96.                         $request
  97.                     );
  98.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  99.                     $data $event->getArgument('data');
  100.                     // メール送信
  101.                     $this->mailService->sendContactMail($data);
  102.                     return $this->redirect($this->generateUrl('contact_complete'));
  103.             }
  104.         }
  105.         return [
  106.             'form' => $form->createView(),
  107.         ];
  108.     }
  109.     /**
  110.      * お問い合わせ完了画面.
  111.      *
  112.      * @Route("/contact/complete", name="contact_complete", methods={"GET"})
  113.      * @Template("Contact/complete.twig")
  114.      */
  115.     public function complete()
  116.     {
  117.         return [];
  118.     }
  119. }