|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2014 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
|
37 | 37 | use Magento\Framework\Encryption\Helper\Security;
|
38 | 38 | use Magento\Framework\Event\ManagerInterface;
|
39 | 39 | use Magento\Framework\Exception\AlreadyExistsException;
|
40 |
| -use Magento\Framework\Exception\EmailNotConfirmedException; |
41 | 40 | use Magento\Framework\Exception\InputException;
|
42 | 41 | use Magento\Framework\Exception\InvalidEmailOrPasswordException;
|
43 | 42 | use Magento\Framework\Exception\LocalizedException;
|
@@ -406,6 +405,11 @@ class AccountManagement implements AccountManagementInterface
|
406 | 405 | */
|
407 | 406 | private Authenticate $authenticate;
|
408 | 407 |
|
| 408 | + /** |
| 409 | + * @var AddressFactory |
| 410 | + */ |
| 411 | + private AddressFactory $addressFactory; |
| 412 | + |
409 | 413 | /**
|
410 | 414 | * @param CustomerFactory $customerFactory
|
411 | 415 | * @param ManagerInterface $eventManager
|
@@ -446,6 +450,7 @@ class AccountManagement implements AccountManagementInterface
|
446 | 450 | * @param Backend|null $eavValidator
|
447 | 451 | * @param CustomerLogger|null $customerLogger
|
448 | 452 | * @param Authenticate|null $authenticate
|
| 453 | + * @param AddressFactory|null $addressFactory |
449 | 454 | * @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
450 | 455 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
451 | 456 | * @SuppressWarnings(PHPMD.NPathComplexity)
|
@@ -491,7 +496,8 @@ public function __construct(
|
491 | 496 | ?AuthenticationInterface $authentication = null,
|
492 | 497 | ?Backend $eavValidator = null,
|
493 | 498 | ?CustomerLogger $customerLogger = null,
|
494 |
| - ?Authenticate $authenticate = null |
| 499 | + ?Authenticate $authenticate = null, |
| 500 | + ?AddressFactory $addressFactory = null, |
495 | 501 | ) {
|
496 | 502 | $this->customerFactory = $customerFactory;
|
497 | 503 | $this->eventManager = $eventManager;
|
@@ -536,6 +542,7 @@ public function __construct(
|
536 | 542 | $this->eavValidator = $eavValidator ?? $objectManager->get(Backend::class);
|
537 | 543 | $this->customerLogger = $customerLogger ?? $objectManager->get(CustomerLogger::class);
|
538 | 544 | $this->authenticate = $authenticate ?? $objectManager->get(Authenticate::class);
|
| 545 | + $this->addressFactory = $addressFactory ?? $objectManager->get(AddressFactory::class); |
539 | 546 | }
|
540 | 547 |
|
541 | 548 | /**
|
@@ -921,15 +928,25 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
|
921 | 928 |
|
922 | 929 | $customerAddresses = $customer->getAddresses() ?: [];
|
923 | 930 | $customer->setAddresses(null);
|
| 931 | + foreach ($customerAddresses as $address) { |
| 932 | + $addressModel = $this->addressFactory->create()->updateData($address); |
| 933 | + $errors = $addressModel->validate(); |
| 934 | + if ($errors !== true) { |
| 935 | + $exception = new InputException(); |
| 936 | + foreach ($errors as $error) { |
| 937 | + $exception->addError($error); |
| 938 | + } |
| 939 | + throw $exception; |
| 940 | + } |
| 941 | + } |
| 942 | + |
924 | 943 | try {
|
925 | 944 | // If customer exists existing hash will be used by Repository
|
926 | 945 | $customer = $this->customerRepository->save($customer, $hash);
|
927 | 946 | } catch (AlreadyExistsException $e) {
|
928 | 947 | throw new InputMismatchException(
|
929 | 948 | __('A customer with the same email address already exists in an associated website.')
|
930 | 949 | );
|
931 |
| - } catch (LocalizedException $e) { |
932 |
| - throw $e; |
933 | 950 | }
|
934 | 951 | try {
|
935 | 952 | foreach ($customerAddresses as $address) {
|
|
0 commit comments