<?php declare(strict_types=1);
namespace Itptheme\Subscriber;
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
use Shopware\Core\Framework\Validation\BuildValidationEvent;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* CIO-AI-Driven: Add additional validation for customer registration.
*/
class CustomerRegistrationValidationSubscriber implements EventSubscriberInterface
{
private SystemConfigService $systemConfigService;
public function __construct(SystemConfigService $systemConfigService)
{
$this->systemConfigService = $systemConfigService;
}
public static function getSubscribedEvents(): array
{
return [
'framework.validation.customer.create' => 'onCustomerCreateValidation',
];
}
public function onCustomerCreateValidation(BuildValidationEvent $event): void
{
$source = $event->getContext()->getSource();
if (!$source instanceof SalesChannelApiSource) {
return;
}
$salesChannelId = $source->getSalesChannelId();
$isDataProtectionCheckboxRequired = (bool) $this->systemConfigService->get(
'core.loginRegistration.requireDataProtectionCheckbox',
$salesChannelId
);
if (!$isDataProtectionCheckboxRequired) {
return;
}
// Separate required checkbox for AGB/TOS in registration.
$event->getDefinition()->add('acceptedTos', new NotBlank());
}
}