app/Plugin/SearchPlus42/Controller/Block/SearchDetailController.php line 129

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : SearchPlus
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\SearchPlus42\Controller\Block;
  12. use Eccube\Controller\AbstractController;
  13. use Eccube\Form\Type\SearchProductBlockType;
  14. use Eccube\Form\Type\SearchProductType;
  15. use Plugin\SearchPlus42\Service\SearchPlusService;
  16. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\RequestStack;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. class SearchDetailController extends AbstractController
  21. {
  22.     protected $requestStack;
  23.     private $searchPlusService;
  24.     public function __construct(
  25.             RequestStack $requestStack,
  26.             SearchPlusService $searchPlusService
  27.             )
  28.     {
  29.         $this->searchPlusService $searchPlusService;
  30.         $this->requestStack $requestStack;
  31.     }
  32.     /**
  33.      * @Route("/block/search_detail", name="block_search_detail")
  34.      * @Template("Block/search_detail.twig")
  35.      */
  36.     public function index(Request $request)
  37.     {
  38.         $ProductItems = [];
  39.         if($this->searchPlusService->checkInstallPlugin('ProductPlus42')){
  40.             $productItemRepository $this->entityManager->getRepository('Plugin\ProductPlus42\Entity\ProductItem');
  41.             $request $this->requestStack->getMasterRequest();
  42.             $category_id $request->query->get('category_id');
  43.             $criteria = ['search_flg' => true];
  44.             //カテゴリごとの検索項目出力を連想配列に格納
  45.             $categoryItemsMap = [
  46.                 10 => [1567],//ソファ
  47.                 11 => [8],//チェア
  48.                 12 => [],//スツール
  49.                 13 => [],//ベンチ
  50.                 15 => [967],//テーブル
  51.                 16 => [1067],//サイドテーブル
  52.                 17 => [1167],//ダイニング
  53.                 18 => [121367],//デスク
  54.                 19 => [1415],//テレビボード
  55.                 20 => [1667],//収納家具
  56.                 21 => [17],//キッチン収納・食器棚
  57.                 22 => [18],//ベッド
  58.                 23 => [28],//マットレス
  59.                 24 => [19],//寝具
  60.                 25 => [202122],//ラグ
  61.                 26 => [23],//キッズ
  62.                 27 => [67],//カーテン
  63.                 28 => [24],//オフィス
  64.                 29 => [25],//アウトドア
  65.                 30 => [67],//ガーデンファニチャー
  66.                 31 => [26],//クッション
  67.                 32 => [27],//時計
  68.                 33 => [67],//インテリア雑貨
  69.             ];
  70.             if (array_key_exists($category_id$categoryItemsMap)) {
  71.                 $criteria['id'] = $categoryItemsMap[$category_id];
  72.             } else {
  73.                 $criteria['id'] = [];
  74.             }
  75.             $ProductItems $productItemRepository->findBy($criteria, ['sort_no' => 'DESC']);
  76.         }
  77.         $builder $this->formFactory
  78.             ->createNamedBuilder(''SearchProductBlockType::class)
  79.             ->setMethod('GET');
  80.         $form $builder->getForm();
  81.         $form->handleRequest($request);
  82.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  83.         $searchForm $builder->getForm();
  84.         $searchForm->handleRequest($request);
  85.         $Category $searchForm->get('category_id')->getData();
  86.         //商品カテゴリとブランドの判定
  87.         $category_result false;
  88.         $brand_result false;
  89.         if ($Category) {
  90.             $Parent $Category->getParent();
  91.             if ($Parent) {
  92.                 if ($Parent->getId() == 7) {
  93.                     $category_result true;
  94.                 } elseif ($Parent->getId() == 34) {
  95.                     $brand_result true;
  96.                 }
  97.             }
  98.         }
  99.         $searchData = [
  100.             'hmin' => $request->query->get('hmin'),
  101.             'hmax' => $request->query->get('hmax'),
  102.             'wmin' => $request->query->get('wmin'),
  103.             'wmax' => $request->query->get('wmax'),
  104.         ];
  105.         // searchForm
  106.         /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
  107.         $builder $this->formFactory->createNamedBuilder(''SearchProductType::class);
  108.         $builder->setMethod('GET');
  109.         $searchForm $builder->getForm();
  110.         $searchForm->handleRequest($request);
  111.         return [
  112.             'ProductItems' => $ProductItems,
  113.             'form' => $form->createView(),
  114.             'search_form' => $searchForm->createView(),
  115.             'Category' => $Category,
  116.             'CategoryResult' => $category_result,
  117.             'BrandResult' => $brand_result,
  118.             'searchData' => $searchData,
  119.         ];
  120.     }
  121. }