|
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;
|
|
56 | 55 | use Magento\Framework\Session\SessionManagerInterface;
|
57 | 56 | use Magento\Framework\Stdlib\DateTime;
|
58 | 57 | use Magento\Framework\Stdlib\StringUtils as StringHelper;
|
| 58 | +use Magento\Framework\Validator\Factory as ValidatorFactory; |
59 | 59 | use Magento\Store\Model\ScopeInterface;
|
60 | 60 | use Magento\Store\Model\StoreManagerInterface;
|
61 | 61 | use Psr\Log\LoggerInterface as PsrLogger;
|
@@ -446,6 +446,8 @@ class AccountManagement implements AccountManagementInterface
|
446 | 446 | * @param Backend|null $eavValidator
|
447 | 447 | * @param CustomerLogger|null $customerLogger
|
448 | 448 | * @param Authenticate|null $authenticate
|
| 449 | + * @param AddressFactory|null $addressFactory |
| 450 | + * @param ValidatorFactory|null $validatorFactory |
449 | 451 | * @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
450 | 452 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
451 | 453 | * @SuppressWarnings(PHPMD.NPathComplexity)
|
@@ -491,7 +493,9 @@ public function __construct(
|
491 | 493 | ?AuthenticationInterface $authentication = null,
|
492 | 494 | ?Backend $eavValidator = null,
|
493 | 495 | ?CustomerLogger $customerLogger = null,
|
494 |
| - ?Authenticate $authenticate = null |
| 496 | + ?Authenticate $authenticate = null, |
| 497 | + private ?AddressFactory $addressFactory = null, |
| 498 | + private ?ValidatorFactory $validatorFactory = null, |
495 | 499 | ) {
|
496 | 500 | $this->customerFactory = $customerFactory;
|
497 | 501 | $this->eventManager = $eventManager;
|
@@ -536,6 +540,8 @@ public function __construct(
|
536 | 540 | $this->eavValidator = $eavValidator ?? $objectManager->get(Backend::class);
|
537 | 541 | $this->customerLogger = $customerLogger ?? $objectManager->get(CustomerLogger::class);
|
538 | 542 | $this->authenticate = $authenticate ?? $objectManager->get(Authenticate::class);
|
| 543 | + $this->addressFactory = $addressFactory ?? $objectManager->get(AddressFactory::class); |
| 544 | + $this->validatorFactory = $validatorFactory ?? $objectManager->get(ValidatorFactory::class); |
539 | 545 | }
|
540 | 546 |
|
541 | 547 | /**
|
@@ -921,21 +927,34 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
|
921 | 927 |
|
922 | 928 | $customerAddresses = $customer->getAddresses() ?: [];
|
923 | 929 | $customer->setAddresses(null);
|
| 930 | + $customerAddresses = array_filter( |
| 931 | + $customerAddresses, |
| 932 | + fn ($address) => $this->isAddressAllowedForWebsite($address, $customer->getStoreId()) |
| 933 | + ); |
| 934 | + $addressValidator = $this->validatorFactory->createValidator('customer_address', 'save'); |
| 935 | + foreach ($customerAddresses as $address) { |
| 936 | + $addressModel = $this->addressFactory->create()->updateData($address); |
| 937 | + if ($this->configShare->isWebsiteScope()) { |
| 938 | + $addressModel->setStoreId($customer->getStoreId()); |
| 939 | + } |
| 940 | + if (!$addressValidator->isValid($addressModel)) { |
| 941 | + $exception = new InputException(); |
| 942 | + $messages = $addressValidator->getMessages(); |
| 943 | + array_walk_recursive($messages, [$exception, 'addError']); |
| 944 | + throw $exception; |
| 945 | + } |
| 946 | + } |
| 947 | + |
924 | 948 | try {
|
925 | 949 | // If customer exists existing hash will be used by Repository
|
926 | 950 | $customer = $this->customerRepository->save($customer, $hash);
|
927 | 951 | } catch (AlreadyExistsException $e) {
|
928 | 952 | throw new InputMismatchException(
|
929 | 953 | __('A customer with the same email address already exists in an associated website.')
|
930 | 954 | );
|
931 |
| - } catch (LocalizedException $e) { |
932 |
| - throw $e; |
933 | 955 | }
|
934 | 956 | try {
|
935 | 957 | foreach ($customerAddresses as $address) {
|
936 |
| - if (!$this->isAddressAllowedForWebsite($address, $customer->getStoreId())) { |
937 |
| - continue; |
938 |
| - } |
939 | 958 | if ($address->getId()) {
|
940 | 959 | $newAddress = clone $address;
|
941 | 960 | $newAddress->setId(null);
|
|
0 commit comments