<?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\SearchProductBlockType;
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 SearchProductBlockExtension 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',
'label' => trans('maker.admin.maker'),
'multiple' => true,
'expanded' => true,
'required' => false,
'mapped' => false,
'placeholder' => 'common.select__all_makers',
]);
}
$builder
->add('pmin', Type\NumberType::class, [
'required' => false,
])
->add('pmax', Type\NumberType::class, [
'required' => false,
])
->add('instock', Type\CheckboxType::class, [
'label' => trans('searchplus.block.label.instock'),
'required' => false,
])
->add('tag_id', EntityType::class, [
'class' => 'Eccube\Entity\Tag',
'query_builder' => function ($er) {
return $er->createQueryBuilder('t')
->orderBy('t.sort_no', 'DESC');
},
'label' => trans('admin.product.tag'),
'multiple' => true,
'expanded' => true,
'required' => false,
'mapped' => false,
]);
}
public static function getExtendedTypes(): iterable
{
return [SearchProductBlockType::class];
}
}