custom/plugins/WbfkExtensions/src/Subscriber/OrderCreateValidationSubscriber.php line 25

Open in your IDE?
  1. <?php
  2. namespace WbfkExtensions\Subscriber;
  3. use Shopware\Core\Framework\Validation\BuildValidationEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\RequestStack;
  6. use Symfony\Component\Validator\Constraints\NotBlank;
  7. class OrderCreateValidationSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct(
  10.         private readonly RequestStack $requestStack
  11.     ) {
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             'framework.validation.order.create' => 'addProductTosValidations',
  17.         ];
  18.     }
  19.     public function addProductTosValidations(BuildValidationEvent $event)
  20.     {
  21.         $productTermsAndConditions $this->requestStack->getSession()->get('productTermsAndConditions');
  22.         foreach ($productTermsAndConditions as $productId => $termsAndConditionsSet) {
  23.             $termsKey "product_tos_$productId";
  24.             $event->getDefinition()->add($termsKey, new NotBlank());
  25.         }
  26.     }
  27. }