app/Customize/Controller/SearchBoxController.php line 44

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\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Eccube\Form\Type\SearchProductBlockType;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\RequestStack;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Eccube\Form\Type\Master\ProductListMaxType;
  22. use Eccube\Form\Type\Master\ProductListOrderByType;
  23. class SearchBoxController extends AbstractController
  24. {
  25.     /**
  26.      * @var RequestStack
  27.      */
  28.     protected $requestStack;
  29.     public function __construct(RequestStack $requestStack
  30.     ) {
  31.         $this->requestStack $requestStack;
  32.     }
  33.     /**
  34.      * @Route("/block/search_box_sub", name="block_search_box_sub")
  35.      * @Template("Block/search_box_sub.twig")
  36.      */
  37.     public function subBox(Request $request)
  38.     {
  39.         return $this->index($request);
  40.     }
  41.     /**
  42.      * @Route("/block/search_box", name="block_search_box")
  43.      * @Template("Block/search_box.twig")
  44.      */
  45.     public function index()
  46.     {
  47.         global $request;
  48.         // 表示件数
  49.         $builder $this->formFactory->createNamedBuilder(
  50.             'disp_number',
  51.             ProductListMaxType::class,
  52.             null,
  53.             [
  54.                 'required' => false,
  55.                 'allow_extra_fields' => true,
  56.             ]
  57.         );
  58.         if ($request->getMethod() === 'GET') {
  59.             $builder->setMethod('GET');
  60.         }
  61.         $event = new EventArgs(
  62.             [
  63.                 'builder' => $builder,
  64.             ],
  65.             $request
  66.         );
  67.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_DISP$event);
  68.         $dispNumberForm $builder->getForm();
  69.         $dispNumberForm->handleRequest($request);
  70.         // ソート順
  71.         $builder $this->formFactory->createNamedBuilder(
  72.             'orderby',
  73.             ProductListOrderByType::class,
  74.             null,
  75.             [
  76.                 'required' => false,
  77.                 'allow_extra_fields' => true,
  78.             ]
  79.         );
  80.         if ($request->getMethod() === 'GET') {
  81.             $builder->setMethod('GET');
  82.         }
  83.         $event = new EventArgs(
  84.             [
  85.                 'builder' => $builder,
  86.             ],
  87.             $request
  88.         );
  89.         $this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_ORDER$event);
  90.         $orderByForm $builder->getForm();
  91.         $orderByForm->handleRequest($request);
  92.         $SearchCategories $this->getSearchCategories();
  93.         $Params $this->getParams();
  94.         if(isset($_GET['categories'])){
  95.             if(!empty($_GET['categories'])){
  96.                 foreach(explode(",",$_GET['categories']) as $key => $value){
  97.                     $Params['multi_category'][$value] = $value;
  98.                 }
  99.             }
  100.         }
  101.         // print_r($_GET['multi_category']);
  102.         return [
  103.             'disp_number_form_in_sbox' => $dispNumberForm->createView(),
  104.             'order_by_form_in_sbox' => $orderByForm->createView(),
  105.             'SearchCategories' => $SearchCategories,
  106.             'Params' => $Params
  107.         ];
  108.     }
  109.     private function getParams(){
  110.         // $Params = $_GET;
  111.         if(isset($_GET['category_id']) && !empty($_GET['category_id'])){
  112.           $_GET['multi_category'][$_GET['category_id']] = $_GET['category_id'];
  113.         }
  114.         if(isset($_GET['categories']) && !empty($_GET['categories'])){
  115.             $categories explode(',',$_GET['categories']);
  116.             foreach ($categories as $key => $category) {
  117.                 $_GET['multi_category'][$category] = $category;
  118.             }
  119.         }
  120.         return $_GET;
  121.     }
  122.     private function getSearchCategories(){
  123.         $qb $this->entityManager->createQueryBuilder([]);
  124.         $query $qb->select("c")
  125.             ->from("Eccube\\Entity\\Category","c")
  126.             ->getQuery();
  127.         $allCategories $query->getResult();
  128.         $SearchCategories = [];
  129.         foreach( $allCategories as $keyu => $category ){
  130.             if(in_array($category->getId(),[7,137,14,113,115,10])){
  131.                 if($category->getId() == 10){
  132.                     $other $category;
  133.                 }else{
  134.                     $SearchCategories['item'][$category->getId()] = $category;
  135.                 }
  136.             }elseif($category->getId() == 24){
  137.                 $SearchCategories['jewely'][$category->getId()] = $category;
  138.             }elseif($category->getId() == 44){
  139.                 $SearchCategories['birthStone'][$category->getId()] = $category;
  140.             }elseif($category->getId() == 12){
  141.                 $SearchCategories['color'][$category->getId()] = $category;
  142.             }elseif($category->getId() == 6){
  143.                 $SearchCategories['series'][$category->getId()] = $category;
  144.             }elseif($category->getId() == 41){
  145.                 $SearchCategories['material'][$category->getId()] = $category;
  146.             }
  147.         }
  148.         //ギフトラッピングだけ最後に追加
  149.         $SearchCategories['item'][$other->getId()] = $other;
  150.         return $SearchCategories;
  151.     }
  152. }