src/Eccube/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 Eccube\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\Entity\Product;        //@##ADD 2021-10-07 upseek
  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. //@## CHG START 2021-10-07 upseek
  56. //        $builder = $this->formFactory->createBuilder(ContactType::class);
  57.         $product_id $request->get('product_id');
  58.         $product_name '';
  59.         if($product_id) {
  60.             $product $this->entityManager->getRepository('Eccube\Entity\Product')->find($product_id);
  61.             if($product) {
  62.                 $product_name $product->getName();
  63.             }
  64.         }
  65.         $builder $this->formFactory->createBuilder(ContactType::class, ['product_id' => $product_id'product_name' => $product_name]);
  66. //@## CHG END 2021-10-07 upseek
  67.         if ($this->isGranted('ROLE_USER')) {
  68.             /** @var Customer $user */
  69.             $user $this->getUser();
  70.             $builder->setData(
  71.                 [
  72.                     'name01' => $user->getName01(),
  73.                     'name02' => $user->getName02(),
  74.                     'kana01' => $user->getKana01(),
  75.                     'kana02' => $user->getKana02(),
  76.                     'postal_code' => $user->getPostalCode(),
  77.                     'pref' => $user->getPref(),
  78.                     'addr01' => $user->getAddr01(),
  79.                     'addr02' => $user->getAddr02(),
  80.                     'phone_number' => $user->getPhoneNumber(),
  81.                     'email' => $user->getEmail(),
  82. //@##ADD START 2022-07-07
  83.                     'product_id' => $product_id,
  84.                     'product_name' => $product_name,
  85. //@##ADD END
  86. //@##ADD START 2023-10-23
  87.                     'company_name' => $user->getCompanyName(),
  88. //@##ADD END
  89.                 ]
  90.             );
  91.         }
  92.         // FRONT_CONTACT_INDEX_INITIALIZE
  93.         $event = new EventArgs(
  94.             [
  95.                 'builder' => $builder,
  96.             ],
  97.             $request
  98.         );
  99.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  100.         $form $builder->getForm();
  101.         $form->handleRequest($request);
  102.         if ($form->isSubmitted() && $form->isValid()) {
  103.             switch ($request->get('mode')) {
  104.                 case 'confirm':
  105.                     return $this->render('Contact/confirm.twig', [
  106.                         'form' => $form->createView(),
  107.                         'Page' => $this->pageRepository->getPageByRoute('contact_confirm'),
  108.                     ]);
  109.                 case 'complete':
  110.                     $data $form->getData();
  111.                     $event = new EventArgs(
  112.                         [
  113.                             'form' => $form,
  114.                             'data' => $data,
  115.                         ],
  116.                         $request
  117.                     );
  118.                     $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  119.                     $data $event->getArgument('data');
  120.                     // メール送信
  121.                     $this->mailService->sendContactMail($data);
  122.                     return $this->redirect($this->generateUrl('contact_complete'));
  123.             }
  124.         }
  125.         return [
  126.             'form' => $form->createView(),
  127.         ];
  128.     }
  129.     /**
  130.      * お問い合わせ完了画面.
  131.      *
  132.      * @Route("/contact/complete", name="contact_complete", methods={"GET"})
  133.      * @Template("Contact/complete.twig")
  134.      */
  135.     public function complete()
  136.     {
  137.         return [];
  138.     }
  139. }