app/Customize/Controller/PurchaseController.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 Customize\Service\MailService;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class PurchaseController 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("/purchase", name="purchase", methods={"GET", "POST"})
  50.      * @Route("/purchase", name="purchase_confirm", methods={"GET", "POST"})
  51.      * @Template("Purchase/index.twig")
  52.      */
  53.     public function index(Request $request)
  54.     {
  55.         $builder $this->formFactory->createBuilder(ContactType::class);
  56.         if ($this->isGranted('ROLE_USER')) {
  57.             /** @var Customer $user */
  58.             $user $this->getUser();
  59.             $builder->setData(
  60.                 [
  61.                     'name01' => $user->getName01(),
  62.                     'name02' => $user->getName02(),
  63.                     'kana01' => $user->getKana01(),
  64.                     'kana02' => $user->getKana02(),
  65.                     'postal_code' => $user->getPostalCode(),
  66.                     'pref' => $user->getPref(),
  67.                     'addr01' => $user->getAddr01(),
  68.                     'addr02' => $user->getAddr02(),
  69.                     'phone_number' => $user->getPhoneNumber(),
  70.                     'email' => $user->getEmail(),
  71.                 ]
  72.             );
  73.         }
  74.         // FRONT_CONTACT_INDEX_INITIALIZE
  75.         //$event = new EventArgs(
  76.         //    [
  77.         //        'builder' => $builder,
  78.         //    ],
  79.         //    $request
  80.         //);
  81.         //$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
  82.         $form $builder->getForm();
  83.         $form->handleRequest($request);
  84.         if ($form->isSubmitted() && $form->isValid()) {
  85.             switch ($request->get('mode')) {
  86.                 case 'confirm':
  87.                     return $this->render('Purchase/confirm.twig', [
  88.                         'form' => $form->createView(),
  89.                         'Page' => $this->pageRepository->getPageByRoute('purchase_confirm'),
  90.                     ]);
  91.                 case 'complete':
  92.                     $data $form->getData();
  93.                     $event = new EventArgs(
  94.                         [
  95.                             'form' => $form,
  96.                             'data' => $data,
  97.                         ],
  98.                         $request
  99.                     );
  100.                     //$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE);
  101.                     //$data = $event->getArgument('data');
  102.                     // メール送信
  103.                     $this->mailService->sendContactMail($data);
  104.                     return $this->redirect($this->generateUrl('purchase_complete'));
  105.             }
  106.         }
  107.         return [
  108.             'form' => $form->createView(),
  109.         ];
  110.     }
  111.     /**
  112.      * お問い合わせ完了画面.
  113.      *
  114.      * @Route("/purchase/complete", name="purchase_complete", methods={"GET"})
  115.      * @Template("Purchase/complete.twig")
  116.      */
  117.     public function complete()
  118.     {
  119.         return [];
  120.     }
  121. }