<?php declare(strict_types=1);
namespace CoeRechnungsMailSw6\Subscriber;
use CoeRechnungsMailSw6\CoeRechnungsMailSw6;
use Shopware\Core\Checkout\Customer\CustomerEvents;
use Shopware\Core\Framework\Event\DataMappingEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
/**
* Class CustomerSubscriber
* This subscriber subscribes to events which deals with the registration-process of the customer.
* Like adding fields to the database during the registration.
* @package CoeRechnungsMailSw6\Subscriber
* @author Jeffry Block <jeffry.block@codeenterprise.de>
*/
Class CustomerSubscriber implements EventSubscriberInterface{
/** @var SystemConfigService $systemConfigService*/
private $systemConfigService;
/**
* CustomerSubscriber constructor.
* @param SystemConfigService $systemConfigService
*/
function __construct(SystemConfigService $systemConfigService)
{
$this -> systemConfigService = $systemConfigService;
}
/**
* @return array
* @author Jeffry Block <jeffry.block@codeenterprise.de>
*/
public static function getSubscribedEvents(): array
{
return [
CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'onMapCustomerRegistrationData',
CustomerEvents::MAPPING_CUSTOMER_PROFILE_SAVE => 'onMapCustomerRegistrationData',
];
}
/**
* @param DataMappingEvent $event
* @author Jeffry Block <jeffry.block@codeenterprise.de>
*/
public function onMapCustomerRegistrationData(DataMappingEvent $event): void
{
$documentMail = $event->getInput()->get("documentMail", "");
$output = $event -> getOutput();
$output["customFields"] = [
CoeRechnungsMailSw6::$field_name_mail => $documentMail,
CoeRechnungsMailSw6::$field_name_active => str_contains($documentMail, "@")
];
$event-> setOutput($output);
}
}