app/Customize/Controller/ContactController.php line 60

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 Eccube\Repository\PageRepository;
  19. use Eccube\Service\MailService;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class ContactController 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.      * お問い合わせ画面.
  48.      *
  49.      * @Route("/contact", name="contact", methods={"GET", "POST"})
  50.      * @Route("/contact", name="contact_confirm", methods={"GET", "POST"})
  51.      * @Template("Contact/index.twig")
  52.      */
  53.     public function index(Request $request)
  54.     {
  55.         $param $request->query->get('productCode');
  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.                     'company_name' => $user->getCompanyName(),
  64.                     'name01' => $user->getName01(),
  65.                     'name02' => $user->getName02(),
  66.                     'kana01' => $user->getKana01(),
  67.                     'kana02' => $user->getKana02(),
  68.                     'postal_code' => $user->getPostalCode(),
  69.                     'pref' => $user->getPref(),
  70.                     'addr01' => $user->getAddr01(),
  71.                     'addr02' => $user->getAddr02(),
  72.                     'phone_number' => $user->getPhoneNumber(),
  73.                     'email' => $user->getEmail(),
  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.             'productCode' => $param,
  113.             
  114.         ];
  115.     }
  116.     /**
  117.      * お問い合わせ完了画面.
  118.      *
  119.      * @Route("/contact/complete", name="contact_complete", methods={"GET"})
  120.      * @Template("Contact/complete.twig")
  121.      */
  122.     public function complete()
  123.     {
  124.         return [];
  125.     }
  126. }