custom/plugins/memoPostcodePlugin/src/Subscribers/AddressMappingSubscriber.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Memo\PostcodenlPlugin\Subscribers;
  3. use Shopware\Core\Checkout\Customer\CustomerEvents;
  4. use Shopware\Core\Framework\Event\DataMappingEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class AddressMappingSubscriber implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents()
  9.     {
  10.         return [
  11.             CustomerEvents::MAPPING_REGISTER_ADDRESS_BILLING => 'onMappingAddress',
  12.             CustomerEvents::MAPPING_REGISTER_ADDRESS_SHIPPING => 'onMappingAddress',
  13.             CustomerEvents::MAPPING_ADDRESS_CREATE => 'onMappingAddress',
  14.         ];
  15.     }
  16.     public function onMappingAddress(DataMappingEvent $event)
  17.     {
  18.         $inputData $event->getInput();
  19.         $outputData $event->getOutput();
  20.         $outputData['customFields'] = [
  21.             'postcodenl_street' => $inputData->get('postcodenl_street'""),
  22.             'postcodenl_housenumber' => $inputData->get('postcodenl_housenumber'""),
  23.             'postcodenl_housenumber_addition' => $inputData->get('postcodenl_housenumber_addition'""),
  24.             'postcodenl_zipcode' => $inputData->get('postcodenl_zipcode'""),
  25.             'postcodenl_city' => $inputData->get('postcodenl_city'""),
  26.             'postcodenl_autocomplete_address' => $inputData->get('autocomplete-address'""),
  27.         ];
  28.         $event->setOutput($outputData);
  29.         return true;
  30.     }
  31. }