<?php
/*
* Plugin Name : SearchPlus
*
* Copyright (C) BraTech Co., Ltd. All Rights Reserved.
* http://www.bratech.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\SearchPlus42\Controller\Block;
use Eccube\Controller\AbstractController;
use Eccube\Form\Type\SearchProductBlockType;
use Eccube\Form\Type\SearchProductType;
use Plugin\SearchPlus42\Service\SearchPlusService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
class SearchDetailController extends AbstractController
{
protected $requestStack;
private $searchPlusService;
public function __construct(
RequestStack $requestStack,
SearchPlusService $searchPlusService
)
{
$this->searchPlusService = $searchPlusService;
$this->requestStack = $requestStack;
}
/**
* @Route("/block/search_detail", name="block_search_detail")
* @Template("Block/search_detail.twig")
*/
public function index(Request $request)
{
$ProductItems = [];
if($this->searchPlusService->checkInstallPlugin('ProductPlus42')){
$productItemRepository = $this->entityManager->getRepository('Plugin\ProductPlus42\Entity\ProductItem');
$request = $this->requestStack->getMasterRequest();
$category_id = $request->query->get('category_id');
$criteria = ['search_flg' => true];
//カテゴリごとの検索項目出力を連想配列に格納
$categoryItemsMap = [
10 => [1, 5, 6, 7],//ソファ
11 => [8],//チェア
12 => [],//スツール
13 => [],//ベンチ
15 => [9, 6, 7],//テーブル
16 => [10, 6, 7],//サイドテーブル
17 => [11, 6, 7],//ダイニング
18 => [12, 13, 6, 7],//デスク
19 => [14, 15],//テレビボード
20 => [16, 6, 7],//収納家具
21 => [17],//キッチン収納・食器棚
22 => [18],//ベッド
23 => [28],//マットレス
24 => [19],//寝具
25 => [20, 21, 22],//ラグ
26 => [23],//キッズ
27 => [6, 7],//カーテン
28 => [24],//オフィス
29 => [25],//アウトドア
30 => [6, 7],//ガーデンファニチャー
31 => [26],//クッション
32 => [27],//時計
33 => [6, 7],//インテリア雑貨
];
if (array_key_exists($category_id, $categoryItemsMap)) {
$criteria['id'] = $categoryItemsMap[$category_id];
} else {
$criteria['id'] = [];
}
$ProductItems = $productItemRepository->findBy($criteria, ['sort_no' => 'DESC']);
}
$builder = $this->formFactory
->createNamedBuilder('', SearchProductBlockType::class)
->setMethod('GET');
$form = $builder->getForm();
$form->handleRequest($request);
/* @var $searchForm \Symfony\Component\Form\FormInterface */
$searchForm = $builder->getForm();
$searchForm->handleRequest($request);
$Category = $searchForm->get('category_id')->getData();
//商品カテゴリとブランドの判定
$category_result = false;
$brand_result = false;
if ($Category) {
$Parent = $Category->getParent();
if ($Parent) {
if ($Parent->getId() == 7) {
$category_result = true;
} elseif ($Parent->getId() == 34) {
$brand_result = true;
}
}
}
$searchData = [
'hmin' => $request->query->get('hmin'),
'hmax' => $request->query->get('hmax'),
'wmin' => $request->query->get('wmin'),
'wmax' => $request->query->get('wmax'),
];
// searchForm
/* @var $builder \Symfony\Component\Form\FormBuilderInterface */
$builder = $this->formFactory->createNamedBuilder('', SearchProductType::class);
$builder->setMethod('GET');
$searchForm = $builder->getForm();
$searchForm->handleRequest($request);
return [
'ProductItems' => $ProductItems,
'form' => $form->createView(),
'search_form' => $searchForm->createView(),
'Category' => $Category,
'CategoryResult' => $category_result,
'BrandResult' => $brand_result,
'searchData' => $searchData,
];
}
}