custom/plugins/AcrisTaxCS/src/Storefront/Subscriber/VatIdValidationSubscriber.php line 103

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\Tax\Storefront\Subscriber;
  3. use Acris\Tax\Components\Service\VatIdValidationService;
  4. use Acris\Tax\Core\Checkout\Customer\Validation\Constraint\CustomerVatId;
  5. use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressEntity;
  6. use Shopware\Core\Checkout\Customer\CustomerEntity;
  7. use Shopware\Core\Checkout\Customer\Event\CustomerLoginEvent;
  8. use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
  9. use Shopware\Core\Checkout\Customer\Event\GuestCustomerRegisterEvent;
  10. use Shopware\Core\Framework\Validation\BuildValidationEvent;
  11. use Shopware\Core\Framework\Validation\DataBag\DataBag;
  12. use Shopware\Core\Framework\Validation\DataValidationDefinition;
  13. use Shopware\Core\Framework\Validation\DataValidator;
  14. use Shopware\Core\PlatformRequest;
  15. use Shopware\Core\System\Country\CountryEntity;
  16. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceInterface;
  17. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextServiceParameters;
  18. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  19. use Shopware\Core\System\SalesChannel\SalesChannelEntity;
  20. use Shopware\Core\System\SystemConfig\SystemConfigService;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. use Symfony\Component\HttpFoundation\RequestStack;
  23. class VatIdValidationSubscriber implements EventSubscriberInterface
  24. {
  25.     public const CUSTOMER_LOGIN_CAUSE 'customer-login';
  26.     public const PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTION_ALWAYS 'always';
  27.     public const PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTION_IF_NOT_VALIDATED 'ifNotValidated';
  28.     public const PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTIONS = [
  29.         self::PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTION_ALWAYS,
  30.         self::PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTION_IF_NOT_VALIDATED
  31.     ];
  32.     /**
  33.      * @var SystemConfigService
  34.      */
  35.     private $systemConfigService;
  36.     /**
  37.      * @var RequestStack
  38.      */
  39.     private $requestStack;
  40.     /**
  41.      * @var VatIdValidationService
  42.      */
  43.     private $vatIdValidationService;
  44.     /**
  45.      * @var array
  46.      */
  47.     private $vatIds;
  48.     /**
  49.      * @var bool
  50.      */
  51.     private $addressAllowed;
  52.     /**
  53.      * @var SalesChannelContextServiceInterface
  54.      */
  55.     private $salesChannelContextService;
  56.     /**
  57.      * @var DataValidator
  58.      */
  59.     private $validator;
  60.     private int $count;
  61.     public function __construct(SystemConfigService $systemConfigServiceRequestStack $requestStackVatIdValidationService $vatIdValidationServiceSalesChannelContextServiceInterface $salesChannelContextServiceDataValidator $validator)
  62.     {
  63.         $this->systemConfigService $systemConfigService;
  64.         $this->requestStack $requestStack;
  65.         $this->vatIdValidationService $vatIdValidationService;
  66.         $this->salesChannelContextService $salesChannelContextService;
  67.         $this->validator $validator;
  68.         $this->vatIds = [];
  69.         $this->addressAllowed false;
  70.         $this->count 0;
  71.     }
  72.     public static function getSubscribedEvents(): array
  73.     {
  74.         return [
  75.             'framework.validation.customer.profile.update' => 'onValidateCustomerUpdate',
  76.             'framework.validation.customer.create' => 'onValidateCustomerCreate',
  77.             'framework.validation.address.create' => 'onValidateAddress',
  78.             'framework.validation.address.update' => 'onValidateAddress',
  79.             'framework.validation.order.update' => 'onValidateOrder',
  80.             'framework.validation.order.create' => 'onValidateOrder',
  81.             CustomerRegisterEvent::class => 'onCustomerRegister',
  82.             GuestCustomerRegisterEvent::class => 'onGuestCustomerRegister',
  83.             CustomerLoginEvent::class => 'onCustomerLogin'
  84.         ];
  85.     }
  86.     public function onValidateCustomerUpdate(BuildValidationEvent $event): void
  87.     {
  88.         if(empty($this->requestStack) === true || empty($request $this->requestStack->getCurrentRequest()) === true) {
  89.             return;
  90.         }
  91.         $salesChannelContext $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
  92.         $salesChannelId $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  93.         if(!$salesChannelContext instanceof SalesChannelContext || empty($salesChannelId) === true || empty($request->get('vatIds')) === true || !is_array($request->get('vatIds'))) {
  94.             return;
  95.         }
  96.         $customer $salesChannelContext->getCustomer();
  97.         if(!$customer instanceof CustomerEntity) {
  98.             return;
  99.         }
  100.         $billingAddress $customer->getDefaultBillingAddress();
  101.         if (empty($billingAddress) === true) {
  102.             return;
  103.         }
  104.         $billingAddressArray $this->convertAddress($billingAddress$customer->getId(), $customer->getCompany(), $event->getData());
  105.         if (empty($billingAddressArray) === true || !array_key_exists('company'$billingAddressArray) || empty($billingAddressArray['company'])) {
  106.             return;
  107.         }
  108.         $this->vatIdValidationService->checkVatIdsForCustomer($request->get('vatIds'), $customer$salesChannelContext);
  109.         $this->checkVatIdValidation($billingAddressArray$event$salesChannelId$salesChannelContext$request->get('vatIds'), 'customer-update'false'customerUpdate');
  110.     }
  111.     public function onValidateCustomerCreate(BuildValidationEvent $event): void
  112.     {
  113.         if(empty($this->requestStack) === true || empty($request $this->requestStack->getCurrentRequest()) === true) {
  114.             return;
  115.         }
  116.         $salesChannelContext $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
  117.         $salesChannelId $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  118.         if(!$salesChannelContext instanceof SalesChannelContext || empty($salesChannelId) === true || empty($request->get('vatIds')) === true || !is_array($request->get('vatIds'))) {
  119.             return;
  120.         }
  121.         $billingAddress $request->get('billingAddress');
  122.         if (empty($billingAddress) === true) {
  123.             $billingAddress $request->get('address');
  124.         }
  125.         if (empty($billingAddress) === true || !array_key_exists('company'$billingAddress) || empty($billingAddress['company'])) {
  126.             return;
  127.         }
  128.         $this->checkVatIdValidation($billingAddress$event$salesChannelId$salesChannelContext$request->get('vatIds'), 'customer-create'false'customerCreate');
  129.     }
  130.     public function onValidateAddress(BuildValidationEvent $event): void
  131.     {
  132.         $this->count++;
  133.         $currentAddress 'billingAddress';
  134.         if(empty($this->requestStack) === true || empty($request $this->requestStack->getCurrentRequest()) === true) {
  135.             return;
  136.         }
  137.         $salesChannelContext $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
  138.         $salesChannelId $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  139.         if(!$salesChannelContext instanceof SalesChannelContext || empty($salesChannelId) === true) {
  140.             return;
  141.         }
  142.         //check address
  143.         $address $request->get('shippingAddress');
  144.         if (!empty($address)) $currentAddress 'shippingAddress';
  145.         if ($this->addressAllowed !== true) {
  146.             $this->addressAllowed true;
  147.             if (!empty($address)) {
  148.                 return;
  149.             }
  150.         }
  151.         if (!empty($address)) {
  152.             if (!$request->request->has('differentShippingAddress') || boolval($request->request->get('differentShippingAddress')) !== true) {
  153.                 return;
  154.             }
  155.         }
  156.         if (empty($address) === true) {
  157.             $address $request->get('address');
  158.         }
  159.         if (empty($address) === true || !array_key_exists('company'$address) || empty($address['company'])) {
  160.             return;
  161.         }
  162.         if (!empty($address) && array_key_exists('customFields'$address) && !empty($address['customFields'])) {
  163.             $customFields $address['customFields'];
  164.             if (is_array($customFields) && array_key_exists('acris_address_vat_id'$customFields) && empty($customFields['acris_address_vat_id']) !== true) {
  165.                 $addressVatId $customFields['acris_address_vat_id'];
  166.                 if (empty($addressVatId) || !is_string($addressVatId) || in_array($addressVatId$this->vatIds)) return;
  167.                 $this->vatIds[] = $addressVatId;
  168.                 $this->checkVatIdValidation($address$event$salesChannelId$salesChannelContext, [$addressVatId], 'address-save-or-update'false$currentAddress);
  169.             }
  170.         }
  171.     }
  172.     public function onValidateOrder(BuildValidationEvent $event)
  173.     {
  174.         if(empty($this->requestStack) === true || empty($request $this->requestStack->getCurrentRequest()) === true) {
  175.             return;
  176.         }
  177.         $salesChannelContext $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
  178.         $salesChannelId $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);
  179.         if(!$salesChannelContext instanceof SalesChannelContext || empty($salesChannelId) === true) {
  180.             return;
  181.         }
  182.         if (!$this->systemConfigService->get('AcrisTaxCS.config.validateVatIDOnOrder'$salesChannelId)) {
  183.             return;
  184.         }
  185.         // validate personal data and billing address
  186.         if(empty($salesChannelContext->getCustomer()) !== true && !empty($salesChannelContext->getCustomer()->getDefaultBillingAddress())) {
  187.             $billingAddressVatId = !empty($salesChannelContext->getCustomer() && !empty($salesChannelContext->getCustomer()->getDefaultBillingAddress())) ? $this->getBillingAddressVatId($salesChannelContext->getCustomer()->getDefaultBillingAddress()) : null;
  188.             $billingAddressArray $this->convertAddress($salesChannelContext->getCustomer()->getDefaultBillingAddress(), $salesChannelContext->getCustomer()->getId(), $salesChannelContext->getCustomer()->getCompany());
  189.             if (empty($billingAddressArray) !== true) {
  190.                 if (!empty($salesChannelContext->getCustomer()->getVatIds()) && array_key_exists('company'$billingAddressArray) && !empty($billingAddressArray['company']) && is_array($salesChannelContext->getCustomer()->getVatIds())) {
  191.                     $billingAddressArray['vatIdValidationEntry'] = 'personalData';
  192.                     $this->checkVatIdValidation($billingAddressArray$event$salesChannelId$salesChannelContext$salesChannelContext->getCustomer()->getVatIds(), 'order-save-or-update'true'orderAddress');
  193.                 }
  194.                 if (!empty($billingAddressVatId) && array_key_exists('addressCompany'$billingAddressArray) && !empty($billingAddressArray['addressCompany']) && is_string($billingAddressVatId)) {
  195.                     $billingAddressArray['vatIdValidationEntry'] = 'billingAddress';
  196.                     $billingAddressArray['company'] = $billingAddressArray['addressCompany'];
  197.                     $this->checkVatIdValidation($billingAddressArray$event$salesChannelId$salesChannelContext, [$billingAddressVatId], 'order-save-or-update'true'orderAddress');
  198.                 }
  199.             }
  200.         }
  201.         // validate shipping address
  202.         if(empty($salesChannelContext->getCustomer()) !== true && !empty($salesChannelContext->getCustomer()->getDefaultShippingAddress())) {
  203.             $shippingAddressVatId = !empty($salesChannelContext->getCustomer() && !empty($salesChannelContext->getCustomer()->getDefaultShippingAddress())) ? $this->getBillingAddressVatId($salesChannelContext->getCustomer()->getDefaultShippingAddress()) : null;
  204.             $shippingAddressArray $this->convertAddress($salesChannelContext->getCustomer()->getDefaultShippingAddress(), $salesChannelContext->getCustomer()->getId(), $salesChannelContext->getCustomer()->getCompany());
  205.             if (empty($shippingAddressArray) !== true) {
  206.                 if (!empty($shippingAddressVatId) && array_key_exists('addressCompany'$shippingAddressArray) && !empty($shippingAddressArray['addressCompany']) && is_string($shippingAddressVatId)) {
  207.                     $shippingAddressArray['vatIdValidationEntry'] = 'shippingAddress';
  208.                     $shippingAddressArray['company'] = $shippingAddressArray['addressCompany'];
  209.                     $this->checkVatIdValidation($shippingAddressArray$event$salesChannelId$salesChannelContext, [$shippingAddressVatId], 'order-save-or-update'true'orderAddress');
  210.                 }
  211.             }
  212.         }
  213.     }
  214.     public function onCustomerLogin(CustomerLoginEvent $event): void
  215.     {
  216.         list($data$validation) = $this->checkForVatIdValidation($event);
  217.         if (empty($data) || !$data instanceof DataBag || empty($validation) || !$validation instanceof DataValidationDefinition) {
  218.             return;
  219.         }
  220.         $this->validator->validate($data->all(), $validation);
  221.     }
  222.     public function onCustomerRegister(CustomerRegisterEvent $event): void
  223.     {
  224.         if (empty($event->getCustomerId())) return;
  225.         $this->vatIdValidationService->assignTheCustomerToLogEntity($event->getCustomer(), $event->getSalesChannelContext());
  226.     }
  227.     public function onGuestCustomerRegister(GuestCustomerRegisterEvent $event): void
  228.     {
  229.         if (empty($event->getCustomerId())) return;
  230.         $this->vatIdValidationService->assignTheCustomerToLogEntity($event->getCustomer(), $event->getSalesChannelContext());
  231.     }
  232.     private function convertAddress(CustomerAddressEntity $addressEntitystring $customerId, ?string $company, ?DataBag $dataBag null): array
  233.     {
  234.         $addressData = [
  235.             'customerId' => $customerId,
  236.             'street' => $addressEntity->getStreet(),
  237.             'city' => $addressEntity->getCity(),
  238.             'zipcode' => $addressEntity->getZipcode(),
  239.             'countryId' => $addressEntity->getCountryId(),
  240.             'id' => $addressEntity->getId()
  241.         ];
  242.         if (!empty($addressEntity->getCompany())) $addressData['addressCompany'] = $addressEntity->getCompany();
  243.         if (!empty($company)) {
  244.             $addressData['company'] = $company;
  245.         }
  246.         if (!empty($dataBag) && !empty($dataBag->get('company'))) {
  247.             $addressData['company'] = $dataBag->get('company');
  248.         }
  249.         return $addressData;
  250.     }
  251.     private function validateVatIds($vatIds, array $billingAddressBuildValidationEvent $eventSalesChannelContext $salesChannelContext, ?CountryEntity $countrystring $causebool $checkOrderstring $currentAddress)
  252.     {
  253.         if(empty($vatIds)) {
  254.             return;
  255.         }
  256.         foreach ($vatIds as $vatId) {
  257.             if(empty($vatId)) {
  258.                 continue;
  259.             }
  260.             $options = [
  261.                 'address' => $billingAddress,
  262.                 'vatId' => $vatId,
  263.                 'context' => $event->getContext(),
  264.                 'salesChannelContext' => $salesChannelContext,
  265.                 'country' => $country,
  266.                 'cause' => $cause,
  267.                 'isCheckOrder' => $checkOrder,
  268.                 'currentAddress' => $currentAddress
  269.             ];
  270.             $properties $event->getDefinition()->getProperties();
  271.             if (!array_key_exists('vatIds'$properties) || $cause 'customer-update') {
  272.                 $event->getDefinition()->add('vatIds', new CustomerVatId($options));
  273.             }
  274.         }
  275.     }
  276.     private function checkVatIdValidation(array $address$eventstring $salesChannelIdSalesChannelContext $salesChannelContext, ?array $vatIdsstring $causebool $checkOrderstring $currentAddress): void
  277.     {
  278.         if (empty($vatIds)) return;
  279.         $countryId array_key_exists('countryId'$address) && !empty($address['countryId']) ? $address['countryId'] : null;
  280.         if (empty($countryId)) return;
  281.         $country $this->vatIdValidationService->getCountry($countryId$event->getContext());
  282.         $vatIdFormatValidation $this->systemConfigService->get('AcrisTaxCS.config.validateVatIDFormatAllEUCountries'$salesChannelId);
  283.         $vatIdApiServiceValidation $this->systemConfigService->get('AcrisTaxCS.config.VatIDAPIValidationAllEUCountries'$salesChannelId);
  284.         if ((!empty($vatIdFormatValidation) && ($vatIdFormatValidation === VatIdValidationService::DEFAULT_ENABLE_FORMAT_VAT_ID_ALL_EU_COUNTRIES || ($vatIdFormatValidation === VatIdValidationService::DEFAULT_OPTION_STANDARD && $this->vatIdValidationService->checkCountryFormatValidation($country))))
  285.             || (!empty($vatIdApiServiceValidation) && (($vatIdApiServiceValidation === VatIdValidationService::DEFAULT_ENABLE_VAT_ID_VALIDATION_API_SERVICE_ALL_EU_COUNTRIES || $vatIdApiServiceValidation === VatIdValidationService::DEFAULT_ENABLE_VAT_ID_COMPANY_VALIDATION_API_SERVICE_ALL_EU_COUNTRIES
  286.                         || $vatIdApiServiceValidation === VatIdValidationService::DEFAULT_ENABLE_VAT_ID_ADDRESS_VALIDATION_API_SERVICE_ALL_EU_COUNTRIES || $vatIdApiServiceValidation === VatIdValidationService::DEFAULT_ENABLE_VAT_ID_COMPANY_ADDRESS_VALIDATION_API_SERVICE_ALL_EU_COUNTRIES)
  287.                     || ($vatIdApiServiceValidation === VatIdValidationService::DEFAULT_OPTION_STANDARD && $this->vatIdValidationService->checkCountryVatIdValidationApiService($country))))) {
  288.             $this->validateVatIds($vatIds$address$event$salesChannelContext$country$cause$checkOrder$currentAddress);
  289.         }
  290.     }
  291.     private function getBillingAddressVatId(CustomerAddressEntity $address): ?string
  292.     {
  293.         if (empty($address->getCustomFields()) || !is_array($address->getCustomFields()) || !array_key_exists('acris_address_vat_id'$address->getCustomFields()) || empty($address->getCustomFields()['acris_address_vat_id'])) return null;
  294.         return $address->getCustomFields()['acris_address_vat_id'];
  295.     }
  296.     private function checkForVatIdValidation(CustomerLoginEvent $event): array
  297.     {
  298.         $context $event->getSalesChannelContext();
  299.         $salesChannelContext $this->salesChannelContextService->get(
  300.             new SalesChannelContextServiceParameters(
  301.                 $context->getSalesChannelId(),
  302.                 $event->getContextToken(),
  303.                 $context->getLanguageIdChain()[0],
  304.                 $context->getCurrencyId(),
  305.                 $context->getDomainId(),
  306.                 $context->getContext()
  307.             )
  308.         );
  309.         $salesChannelId = !empty($salesChannelContext) && !empty($salesChannelContext->getSalesChannel()) && $salesChannelContext->getSalesChannel() instanceof SalesChannelEntity $salesChannelContext->getSalesChannel()->getId() : null;
  310.         if(!$salesChannelContext instanceof SalesChannelContext || empty($salesChannelId) === true) {
  311.             return [nullnull];
  312.         }
  313.         $validateOnLogin $this->systemConfigService->get('AcrisTaxCS.config.VatIDValidateOnLogin'$salesChannelId);
  314.         if (empty($validateOnLogin) || !is_string($validateOnLogin) || !in_array($validateOnLoginself::PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTIONS)) {
  315.             return [nullnull];
  316.         }
  317.         $customer $salesChannelContext->getCustomer();
  318.         $validation = new DataValidationDefinition('customer.login.vatId.validation');
  319.         $data = new DataBag();
  320.         $validationEvent = new BuildValidationEvent($validation$data$context->getContext());
  321.         list($validationPersonalData$validationBilling$validationShipping) = $this->checkFieldsForValidation($validateOnLogin$customer);
  322.         // validate personal data and billing address
  323.         if(empty($customer) !== true && !empty($customer->getDefaultBillingAddress())) {
  324.             $billingAddressVatId = !empty($customer && !empty($customer->getDefaultBillingAddress())) ? $this->getBillingAddressVatId($customer->getDefaultBillingAddress()) : null;
  325.             $billingAddressArray $this->convertAddress($customer->getDefaultBillingAddress(), $customer->getId(), $customer->getCompany());
  326.             if (empty($billingAddressArray) !== true) {
  327.                 if ($validationPersonalData === true && array_key_exists('company'$billingAddressArray) && !empty($billingAddressArray['company']) && !empty($customer->getVatIds()) && is_array($customer->getVatIds())) {
  328.                     $billingAddressArray['vatIdValidationEntry'] = 'personalData';
  329.                     $this->checkVatIdValidation($billingAddressArray$validationEvent$salesChannelId$salesChannelContext$customer->getVatIds(), self::CUSTOMER_LOGIN_CAUSEtrue'customerUpdate');
  330.                 }
  331.                 if ($validationBilling === true && array_key_exists('addressCompany'$billingAddressArray) && !empty($billingAddressArray['addressCompany']) && !empty($billingAddressVatId) && is_string($billingAddressVatId)) {
  332.                     $billingAddressArray['vatIdValidationEntry'] = 'billingAddress';
  333.                     if (array_key_exists('customerId'$billingAddressArray)) {
  334.                         unset($billingAddressArray['customerId']);
  335.                     }
  336.                     $billingAddressArray['company'] = $billingAddressArray['addressCompany'];
  337.                     $this->checkVatIdValidation($billingAddressArray$validationEvent$salesChannelId$salesChannelContext, [$billingAddressVatId], self::CUSTOMER_LOGIN_CAUSEtrue'billingAddress');
  338.                 }
  339.             }
  340.         }
  341.         // validate shipping address
  342.         if(empty($customer) !== true && !empty($customer->getDefaultShippingAddress())) {
  343.             $shippingAddressVatId = !empty($customer && !empty($customer->getDefaultShippingAddress())) ? $this->getBillingAddressVatId($customer->getDefaultShippingAddress()) : null;
  344.             $shippingAddressArray $this->convertAddress($customer->getDefaultShippingAddress(), $customer->getId(), $customer->getCompany());
  345.             if (empty($shippingAddressArray) !== true) {
  346.                 if ($validationShipping === true && array_key_exists('addressCompany'$shippingAddressArray) && !empty($shippingAddressArray['addressCompany']) && !empty($shippingAddressVatId) && is_string($shippingAddressVatId)) {
  347.                     $shippingAddressArray['vatIdValidationEntry'] = 'shippingAddress';
  348.                     if (array_key_exists('customerId'$shippingAddressArray)) {
  349.                         unset($shippingAddressArray['customerId']);
  350.                     }
  351.                     $shippingAddressArray['company'] = $shippingAddressArray['addressCompany'];
  352.                     $this->checkVatIdValidation($shippingAddressArray$validationEvent$salesChannelId$salesChannelContext, [$shippingAddressVatId], self::CUSTOMER_LOGIN_CAUSEtrue'shippingAddress');
  353.                 }
  354.             }
  355.         }
  356.         return [$data$validation];
  357.     }
  358.     private function checkFieldsForValidation(?string $validationCustomerEntity $customer): array
  359.     {
  360.         $validationPersonalData true;
  361.         $validationBilling true;
  362.         $validationShipping true;
  363.         if ($validation !== self::PLUGIN_CONFIG_VALIDATE_ON_LOGIN_OPTION_IF_NOT_VALIDATED) {
  364.             return [$validationPersonalData$validationBilling$validationShipping];
  365.         }
  366.         if (!empty($customer->getCustomFields()) && is_array($customer->getCustomFields()) && array_key_exists('acris_tax_vat_id_status'$customer->getCustomFields()) && is_string($customer->getCustomFields()['acris_tax_vat_id_status'])) {
  367.             $validationPersonalData false;
  368.         }
  369.         if (!empty($customer->getDefaultBillingAddress()) && $customer->getDefaultBillingAddress() instanceof CustomerAddressEntity) {
  370.             $validationBilling $this->checkAddressField($customer->getDefaultBillingAddress());
  371.         }
  372.         if (!empty($customer->getDefaultShippingAddress()) && $customer->getDefaultShippingAddress() instanceof CustomerAddressEntity) {
  373.             $validationShipping $this->checkAddressField($customer->getDefaultShippingAddress());
  374.         }
  375.         return [$validationPersonalData$validationBilling$validationShipping];
  376.     }
  377.     private function checkAddressField(CustomerAddressEntity $address): bool
  378.     {
  379.         if (!empty($address->getCustomFields()) && is_array($address->getCustomFields()) && array_key_exists('acris_tax_vat_id_status'$address->getCustomFields()) && is_string($address->getCustomFields()['acris_tax_vat_id_status'])) {
  380.             return false;
  381.         }
  382.         return true;
  383.     }
  384. }