src/Eccube/Controller/Block/SearchProductController.php line 51

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\Block;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\SearchProductBlockType;
  17. use Eccube\Repository\CategoryRepository;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\RequestStack;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. class SearchProductController extends AbstractController
  23. {
  24.     /**
  25.      * @var RequestStack
  26.      */
  27.     protected $requestStack;
  28.     /**
  29.      * @var CategoryRepository
  30.      */
  31.     protected $categoryRepository;
  32.     public function __construct(
  33.         RequestStack $requestStack,
  34.         CategoryRepository $categoryRepository
  35.     ) {
  36.         $this->requestStack $requestStack;
  37.         $this->categoryRepository $categoryRepository;
  38.     }
  39.     /**
  40.      * @Route("/block/search_product", name="block_search_product", methods={"GET"})
  41.      * @Route("/block/search_product_sp", name="block_search_product_sp", methods={"GET"})
  42.      * @Template("Block/search_product.twig")
  43.      */
  44.     public function index(Request $request)
  45.     {
  46.         $builder $this->formFactory
  47.             ->createNamedBuilder(''SearchProductBlockType::class)
  48.             ->setMethod('GET');
  49.         $event = new EventArgs(
  50.             [
  51.                 'builder' => $builder,
  52.             ],
  53.             $request
  54.         );
  55.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_BLOCK_SEARCH_PRODUCT_INDEX_INITIALIZE$event);
  56.         $request $this->requestStack->getMasterRequest();
  57.         $form $builder->getForm();
  58.         $form->handleRequest($request);
  59.         $Category $this->categoryRepository->getList();
  60.         foreach ($Category as $item)
  61.         {
  62.             if ($item->getName() == "カテゴリ")
  63.             {
  64.                 $Category $item;
  65.                 break;
  66.             }
  67.         }
  68.         $Category $Category->getChildren();
  69.         return [
  70.             'form' => $form->createView(),
  71.             'Category' => $Category,
  72.         ];
  73.     }
  74. }