app/Plugin/SearchPlus42/Form/Extension/SearchProductExtension.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : SearchPlus
  4. *
  5. * Copyright (C) BraTech Co., Ltd. All Rights Reserved.
  6. * http://www.bratech.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\SearchPlus42\Form\Extension;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use Eccube\Form\Type\SearchProductType;
  14. use Plugin\SearchPlus42\Service\SearchPlusService;
  15. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  16. use Symfony\Component\Form\AbstractTypeExtension;
  17. use Symfony\Component\Form\Extension\Core\Type;
  18. use Symfony\Component\Form\FormBuilderInterface;
  19. class SearchProductExtension extends AbstractTypeExtension
  20. {
  21.     private $entityManager;
  22.     private $searchPlusService;
  23.     public function __construct(
  24.             EntityManagerInterface $entityManager,
  25.             SearchPlusService $searchPlusService
  26.             )
  27.     {
  28.         $this->entityManager $entityManager;
  29.         $this->searchPlusService $searchPlusService;
  30.     }
  31.     public function buildForm(FormBuilderInterface $builder, array $options)
  32.     {
  33.         if($this->searchPlusService->checkInstallPlugin('ProductPlus42')){
  34.             $productItemRepository $this->entityManager->getRepository('Plugin\ProductPlus42\Entity\ProductItem');
  35.             $ProductItems $productItemRepository->findAll();
  36.             $builder $this->searchPlusService->createBuilder($builder$ProductItems);
  37.         }
  38.         if(method_exists('Eccube\Entity\Product','getMaker')){
  39.             $builder
  40.                 ->add('maker_id'EntityType::class, [
  41.                     'class' => 'Plugin\Maker42\Entity\Maker',
  42.                     'query_builder' => function ($er) {
  43.                         return $er->createQueryBuilder('m')
  44.                         ->orderBy('m.sort_no''DESC');
  45.                     },
  46.                     'choice_label' => 'name',
  47.                     'multiple' => true,
  48.                     'expanded' => true,
  49.                     'required' => false,
  50.                 ]);
  51.         }
  52.         $builder
  53.                 ->add('pmin'Type\HiddenType::class, [
  54.                     'required' => false,
  55.                     ])
  56.                 ->add('pmax'Type\HiddenType::class, [
  57.                     'required' => false,
  58.                     ])
  59.                 ->add('hmin'Type\HiddenType::class, [
  60.                     'required' => false,
  61.                 ])
  62.                 ->add('hmax'Type\HiddenType::class, [
  63.                     'required' => false,
  64.                 ])
  65.                 ->add('wmin'Type\HiddenType::class, [
  66.                     'required' => false,
  67.                 ])
  68.                 ->add('wmax'Type\HiddenType::class, [
  69.                     'required' => false,
  70.                 ])
  71.                 ->add('instock'Type\HiddenType::class, [
  72.                     'required' => false,
  73.                     ])
  74.                 ->add('tag_id'EntityType::class, [
  75.                     'class' => 'Eccube\Entity\Tag',
  76.                     'query_builder' => function ($er) {
  77.                         return $er->createQueryBuilder('t')
  78.                         ->orderBy('t.sort_no''DESC');
  79.                     },
  80.                     'multiple' => true,
  81.                     'expanded' => true,
  82.                     'required' => false,
  83.                     ]);
  84.     }
  85.     public static function getExtendedTypes(): iterable
  86.     {
  87.         return [SearchProductType::class];
  88.     }
  89. }