<?php declare(strict_types=1);
namespace Memo\PostcodenlPlugin\Subscribers;
use Shopware\Core\Checkout\Customer\CustomerEvents;
use Shopware\Core\Framework\Event\DataMappingEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddressMappingSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
CustomerEvents::MAPPING_REGISTER_ADDRESS_BILLING => 'onMappingAddress',
CustomerEvents::MAPPING_REGISTER_ADDRESS_SHIPPING => 'onMappingAddress',
CustomerEvents::MAPPING_ADDRESS_CREATE => 'onMappingAddress',
];
}
public function onMappingAddress(DataMappingEvent $event)
{
$inputData = $event->getInput();
$outputData = $event->getOutput();
$outputData['customFields'] = [
'postcodenl_street' => $inputData->get('postcodenl_street', ""),
'postcodenl_housenumber' => $inputData->get('postcodenl_housenumber', ""),
'postcodenl_housenumber_addition' => $inputData->get('postcodenl_housenumber_addition', ""),
'postcodenl_zipcode' => $inputData->get('postcodenl_zipcode', ""),
'postcodenl_city' => $inputData->get('postcodenl_city', ""),
'postcodenl_autocomplete_address' => $inputData->get('autocomplete-address', ""),
];
$event->setOutput($outputData);
return true;
}
}