custom/plugins/Itptheme/src/Subscriber/CustomerRegistrationValidationSubscriber.php line 30

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Itptheme\Subscriber;
  3. use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
  4. use Shopware\Core\Framework\Validation\BuildValidationEvent;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Validator\Constraints\NotBlank;
  8. /**
  9.  * CIO-AI-Driven: Add additional validation for customer registration.
  10.  */
  11. class CustomerRegistrationValidationSubscriber implements EventSubscriberInterface
  12. {
  13.     private SystemConfigService $systemConfigService;
  14.     public function __construct(SystemConfigService $systemConfigService)
  15.     {
  16.         $this->systemConfigService = $systemConfigService;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             'framework.validation.customer.create' => 'onCustomerCreateValidation',
  22.         ];
  23.     }
  24.     public function onCustomerCreateValidation(BuildValidationEvent $event): void
  25.     {
  26.         $source = $event->getContext()->getSource();
  27.         if (!$source instanceof SalesChannelApiSource) {
  28.             return;
  29.         }
  30.         $salesChannelId = $source->getSalesChannelId();
  31.         $isDataProtectionCheckboxRequired = (bool) $this->systemConfigService->get(
  32.             'core.loginRegistration.requireDataProtectionCheckbox',
  33.             $salesChannelId
  34.         );
  35.         if (!$isDataProtectionCheckboxRequired) {
  36.             return;
  37.         }
  38.         // Separate required checkbox for AGB/TOS in registration.
  39.         $event->getDefinition()->add('acceptedTos', new NotBlank());
  40.     }
  41. }