<?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\Form\Extension;
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Form\Type\SearchProductType;
use Plugin\SearchPlus42\Service\SearchPlusService;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\FormBuilderInterface;
class SearchProductExtension extends AbstractTypeExtension
{
private $entityManager;
private $searchPlusService;
public function __construct(
EntityManagerInterface $entityManager,
SearchPlusService $searchPlusService
)
{
$this->entityManager = $entityManager;
$this->searchPlusService = $searchPlusService;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
if($this->searchPlusService->checkInstallPlugin('ProductPlus42')){
$productItemRepository = $this->entityManager->getRepository('Plugin\ProductPlus42\Entity\ProductItem');
$ProductItems = $productItemRepository->findAll();
$builder = $this->searchPlusService->createBuilder($builder, $ProductItems);
}
if(method_exists('Eccube\Entity\Product','getMaker')){
$builder
->add('maker_id', EntityType::class, [
'class' => 'Plugin\Maker42\Entity\Maker',
'query_builder' => function ($er) {
return $er->createQueryBuilder('m')
->orderBy('m.sort_no', 'DESC');
},
'choice_label' => 'name',
'multiple' => true,
'expanded' => true,
'required' => false,
]);
}
$builder
->add('pmin', Type\HiddenType::class, [
'required' => false,
])
->add('pmax', Type\HiddenType::class, [
'required' => false,
])
->add('hmin', Type\HiddenType::class, [
'required' => false,
])
->add('hmax', Type\HiddenType::class, [
'required' => false,
])
->add('wmin', Type\HiddenType::class, [
'required' => false,
])
->add('wmax', Type\HiddenType::class, [
'required' => false,
])
->add('instock', Type\HiddenType::class, [
'required' => false,
])
->add('tag_id', EntityType::class, [
'class' => 'Eccube\Entity\Tag',
'query_builder' => function ($er) {
return $er->createQueryBuilder('t')
->orderBy('t.sort_no', 'DESC');
},
'multiple' => true,
'expanded' => true,
'required' => false,
]);
}
public static function getExtendedTypes(): iterable
{
return [SearchProductType::class];
}
}