app/Customize/Controller/CustomContactController.php line 100

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