<?php
namespace WbfkExtensions\Subscriber;
use Shopware\Core\Framework\Validation\BuildValidationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Validator\Constraints\NotBlank;
class OrderCreateValidationSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly RequestStack $requestStack
) {
}
public static function getSubscribedEvents(): array
{
return [
'framework.validation.order.create' => 'addProductTosValidations',
];
}
public function addProductTosValidations(BuildValidationEvent $event)
{
$productTermsAndConditions = $this->requestStack->getSession()->get('productTermsAndConditions');
foreach ($productTermsAndConditions as $productId => $termsAndConditionsSet) {
$termsKey = "product_tos_$productId";
$event->getDefinition()->add($termsKey, new NotBlank());
}
}
}