<?php declare(strict_types=1);
namespace Okeonline\KejeDeliveryDatePicker\Storefront\Subscriber;
use Shopware\Core\Framework\Validation\BuildValidationEvent;
use Shopware\Core\Framework\Validation\DataValidationDefinition;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
class OrderCreateValidationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'framework.validation.order.create' => 'addValidationRules'
];
}
public function addValidationRules(BuildValidationEvent $event)
{
// add a NotBlank validation to the 'sub' oo_checkout_extra_data_, on the field 'ordered_by'
// request contains: oo_checkout_extra_data_[ordered_by]=something
// when something is missing, this redirects back to previous page, and flashes a error
$event->getDefinition()->addSub(
'oo_checkout_extra_data_',
(new DataValidationDefinition('oo_checkout_extra_data_'))->add('ordered_by', new NotBlank())
);
}
}