vendor/store.shopware.com/rhiemextendedregistration/src/Subscriber/Frontend/Customer.php line 41

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace RhiemExtendedRegistration\Subscriber\Frontend;
  3. use RhiemExtendedRegistration\Components\Services\RegistrationGroupService;
  4. use Shopware\Core\Checkout\Customer\CustomerEvents;
  5. use Shopware\Core\Framework\Event\DataMappingEvent;
  6. use Shopware\Core\Framework\Validation\DataBag\DataBag;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class Customer implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var RegistrationGroupService
  12.      */
  13.     private RegistrationGroupService $registrationGroupService;
  14.     /**
  15.      * Customer constructor.
  16.      *
  17.      * @param RegistrationGroupService $registrationGroupService
  18.      */
  19.     public function __construct(RegistrationGroupService $registrationGroupService)
  20.     {
  21.         $this->registrationGroupService $registrationGroupService;
  22.     }
  23.     /**
  24.      * @return string[]
  25.      */
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'mapCustomerCustomFields'
  30.         ];
  31.     }
  32.     /**
  33.      * @param DataMappingEvent $event
  34.      */
  35.     public function mapCustomerCustomFields(DataMappingEvent $event): void
  36.     {
  37.         $data $event->getInput();
  38.         $customer $event->getOutput();
  39.         if($data instanceof DataBag && $data->has('Rhiem_Additional_Registration_Fields_Personal')){
  40.             $customer $this->setCustomerCustomFields($data$customer);
  41.         }
  42.         $event->setOutput($customer);
  43.     }
  44.     /**
  45.      * @param DataBag $data
  46.      * @param array|null $customer
  47.      *
  48.      * @return array
  49.      */
  50.     private function setCustomerCustomFields(DataBag $data, ?array $customer): array
  51.     {
  52.         return $this->registrationGroupService->setCustomerAttributes(
  53.             $customer,
  54.             $data->get('Rhiem_Additional_Registration_Fields_Personal')
  55.         );
  56.     }
  57. }