app/Plugin/SDream/Form/EventSubscriber/ProductBooleanSubscriber.php line 19

Open in your IDE?
  1. <?php
  2. namespace Plugin\SDream\Form\EventSubscriber;
  3. use Eccube\Entity\Product;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\Form\FormEvent;
  6. use Symfony\Component\Form\FormEvents;
  7. class ProductBooleanSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents(): array
  10.     {
  11.         return [
  12.             FormEvents::SUBMIT => 'onSubmit',
  13.         ];
  14.     }
  15.     public function onSubmit(FormEvent $event): void
  16.     {
  17.         $Product $event->getData();
  18.         if (!$Product instanceof Product) {
  19.             return;
  20.         }
  21.         $form $event->getForm();
  22.         // 不定貫商品
  23.         if ($form->has('firmvariableattribute')) {
  24.             $Product->setFirmVariableAttribute(
  25.                 $form->get('firmvariableattribute')->getData() ? 0
  26.             );
  27.         }
  28.         // 販売禁止
  29.         if ($form->has('preparation')) {
  30.             $Product->setPreparation(
  31.                 $form->get('preparation')->getData() ? 0
  32.             );
  33.         }
  34.         // 購入時間制限
  35.         if ($form->has('purchase_limit_time')) {
  36.             $Product->setPurchaseLimitTime(
  37.                 $form->get('purchase_limit_time')->getData() ? 0
  38.             );
  39.         }
  40.         // 表示限定顧客
  41.         if ($form->has('limited_ids')) {
  42.             $limitedIds trim((string) $form->get('limited_ids')->getData());
  43.             $Product->setLimitedIds($limitedIds !== '' $limitedIds null);
  44.         }
  45.         // 非表示限定顧客
  46.         if ($form->has('locked_ids')) {
  47.             $lockedIds trim((string) $form->get('locked_ids')->getData());
  48.             $Product->setLockedIds($lockedIds !== '' $lockedIds null);
  49.         }
  50.     }
  51. }