custom/plugins/ProcWegReg/src/Subscriber/CustomerRegistrationEventSubscriber.php line 50

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Proc\ProcWegReg\Subscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Shopware\Core\Checkout\Customer\CustomerEvents;
  6. use Shopware\Core\Framework\Event\DataMappingEvent;
  7. use Shopware\Core\Framework\Validation\DataBag\DataBag;
  8. class CustomerRegistrationEventSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents(): array
  11.     {
  12.         return [
  13.             CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'onCustomerUpdateMapping',
  14.             CustomerEvents::MAPPING_REGISTER_ADDRESS_BILLING => 'onCustomerUpdateMappingAddress'
  15.         ];
  16.     }
  17.     public function onCustomerUpdateMapping(DataMappingEvent $event)
  18.     {
  19.         $data $event->getInput();
  20.         $customer $event->getOutput();
  21.         $allowedData = [
  22.             "personalFirmenWebseite" => "personal_firmen_webseite",
  23.             "registrationComment" => "registration_comment",
  24.             "personalKooperation" => "personal_kooperation",
  25.             "sapCustomerNumber" => "sap_customer_number",
  26.             "alreadyCustomerCheckbox" => "already_customer_checkbox"
  27.         ];
  28.         foreach ($allowedData as $key => $customFieldName  ) {
  29.             if ($data->has($key)) {  
  30.                 $value $data->get($key);
  31.                 if($key == 'alreadyCustomerCheckbox') {
  32.                     $value = (bool) $value;
  33.                 }
  34.                 $customer['customFields']['additional_custom_customer_'$customFieldName] = $value;
  35.             }
  36.         }
  37.         return $event->setOutput($customer);
  38.     }
  39.     public function onCustomerUpdateMappingAddress (DataMappingEvent $event) {
  40.         $data $event->getInput();
  41.         $address $event->getOutput();
  42.         $allowedData = [
  43.             "handyNummer" => "handy_nummer"
  44.         ];
  45.         foreach ($allowedData as $key => $customFieldName  ) {
  46.             if ($data->has($key)) {  
  47.                 $value $data->get($key);
  48.                 $address['customFields']['custom_address_data_'$customFieldName] = $value;
  49.             }
  50.         }
  51.         return $event->setOutput($address);
  52.     }
  53. }