<?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\SearchPlus\Controller\Block;
use Eccube\Controller\AbstractController;
use Eccube\Form\Type\SearchProductBlockType;
use Plugin\SearchPlus\Service\SearchPlusService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
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('ProductPlus')){
$productItemRepository = $this->entityManager->getRepository('Plugin\ProductPlus\Entity\ProductItem');
if(method_exists('Plugin\ProductPlus\Entity\ProductItem', 'setSearchFlg')){
$ProductItems = $productItemRepository->findBy(['search_flg' => true],['sort_no' => 'DESC']);
}else{
$ProductItems = $productItemRepository->findBy([],['sort_no' => 'DESC']);
}
}
$builder = $this->formFactory
->createNamedBuilder('', SearchProductBlockType::class)
->setMethod('GET');
$request = $this->requestStack->getMasterRequest();
$form = $builder->getForm();
$form->handleRequest($request);
return [
'ProductItems' => $ProductItems,
'form' => $form->createView(),
];
}
}