<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Eccube\Controller\AbstractController;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Form\Type\SearchProductBlockType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Form\Type\Master\ProductListMaxType;
use Eccube\Form\Type\Master\ProductListOrderByType;
class SearchBoxController extends AbstractController
{
/**
* @var RequestStack
*/
protected $requestStack;
public function __construct(RequestStack $requestStack
) {
$this->requestStack = $requestStack;
}
/**
* @Route("/block/search_box_sub", name="block_search_box_sub")
* @Template("Block/search_box_sub.twig")
*/
public function subBox(Request $request)
{
return $this->index($request);
}
/**
* @Route("/block/search_box", name="block_search_box")
* @Template("Block/search_box.twig")
*/
public function index()
{
global $request;
// 表示件数
$builder = $this->formFactory->createNamedBuilder(
'disp_number',
ProductListMaxType::class,
null,
[
'required' => false,
'allow_extra_fields' => true,
]
);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_DISP, $event);
$dispNumberForm = $builder->getForm();
$dispNumberForm->handleRequest($request);
// ソート順
$builder = $this->formFactory->createNamedBuilder(
'orderby',
ProductListOrderByType::class,
null,
[
'required' => false,
'allow_extra_fields' => true,
]
);
if ($request->getMethod() === 'GET') {
$builder->setMethod('GET');
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::FRONT_PRODUCT_INDEX_ORDER, $event);
$orderByForm = $builder->getForm();
$orderByForm->handleRequest($request);
$SearchCategories = $this->getSearchCategories();
$Params = $this->getParams();
if(isset($_GET['categories'])){
if(!empty($_GET['categories'])){
foreach(explode(",",$_GET['categories']) as $key => $value){
$Params['multi_category'][$value] = $value;
}
}
}
// print_r($_GET['multi_category']);
return [
'disp_number_form_in_sbox' => $dispNumberForm->createView(),
'order_by_form_in_sbox' => $orderByForm->createView(),
'SearchCategories' => $SearchCategories,
'Params' => $Params
];
}
private function getParams(){
// $Params = $_GET;
if(isset($_GET['category_id']) && !empty($_GET['category_id'])){
$_GET['multi_category'][$_GET['category_id']] = $_GET['category_id'];
}
if(isset($_GET['categories']) && !empty($_GET['categories'])){
$categories = explode(',',$_GET['categories']);
foreach ($categories as $key => $category) {
$_GET['multi_category'][$category] = $category;
}
}
return $_GET;
}
private function getSearchCategories(){
$qb = $this->entityManager->createQueryBuilder([]);
$query = $qb->select("c")
->from("Eccube\\Entity\\Category","c")
->getQuery();
$allCategories = $query->getResult();
$SearchCategories = [];
foreach( $allCategories as $keyu => $category ){
if(in_array($category->getId(),[7,137,14,113,115,10])){
if($category->getId() == 10){
$other = $category;
}else{
$SearchCategories['item'][$category->getId()] = $category;
}
}elseif($category->getId() == 24){
$SearchCategories['jewely'][$category->getId()] = $category;
}elseif($category->getId() == 44){
$SearchCategories['birthStone'][$category->getId()] = $category;
}elseif($category->getId() == 12){
$SearchCategories['color'][$category->getId()] = $category;
}elseif($category->getId() == 6){
$SearchCategories['series'][$category->getId()] = $category;
}elseif($category->getId() == 41){
$SearchCategories['material'][$category->getId()] = $category;
}
}
//ギフトラッピングだけ最後に追加
$SearchCategories['item'][$other->getId()] = $other;
return $SearchCategories;
}
}