app/Customize/Controller/ContactController.php line 62

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