Skip to content

Commit 6bdba02

Browse files
Merge branch '2.4-develop' into DHL_AC-13258_25APR25
2 parents b677c64 + 6ea6112 commit 6bdba02

File tree

8 files changed

+437
-333
lines changed

8 files changed

+437
-333
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -37,7 +37,6 @@
3737
use Magento\Framework\Encryption\Helper\Security;
3838
use Magento\Framework\Event\ManagerInterface;
3939
use Magento\Framework\Exception\AlreadyExistsException;
40-
use Magento\Framework\Exception\EmailNotConfirmedException;
4140
use Magento\Framework\Exception\InputException;
4241
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
4342
use Magento\Framework\Exception\LocalizedException;
@@ -56,6 +55,7 @@
5655
use Magento\Framework\Session\SessionManagerInterface;
5756
use Magento\Framework\Stdlib\DateTime;
5857
use Magento\Framework\Stdlib\StringUtils as StringHelper;
58+
use Magento\Framework\Validator\Factory as ValidatorFactory;
5959
use Magento\Store\Model\ScopeInterface;
6060
use Magento\Store\Model\StoreManagerInterface;
6161
use Psr\Log\LoggerInterface as PsrLogger;
@@ -446,6 +446,8 @@ class AccountManagement implements AccountManagementInterface
446446
* @param Backend|null $eavValidator
447447
* @param CustomerLogger|null $customerLogger
448448
* @param Authenticate|null $authenticate
449+
* @param AddressFactory|null $addressFactory
450+
* @param ValidatorFactory|null $validatorFactory
449451
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
450452
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
451453
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -491,7 +493,9 @@ public function __construct(
491493
?AuthenticationInterface $authentication = null,
492494
?Backend $eavValidator = null,
493495
?CustomerLogger $customerLogger = null,
494-
?Authenticate $authenticate = null
496+
?Authenticate $authenticate = null,
497+
private ?AddressFactory $addressFactory = null,
498+
private ?ValidatorFactory $validatorFactory = null,
495499
) {
496500
$this->customerFactory = $customerFactory;
497501
$this->eventManager = $eventManager;
@@ -536,6 +540,8 @@ public function __construct(
536540
$this->eavValidator = $eavValidator ?? $objectManager->get(Backend::class);
537541
$this->customerLogger = $customerLogger ?? $objectManager->get(CustomerLogger::class);
538542
$this->authenticate = $authenticate ?? $objectManager->get(Authenticate::class);
543+
$this->addressFactory = $addressFactory ?? $objectManager->get(AddressFactory::class);
544+
$this->validatorFactory = $validatorFactory ?? $objectManager->get(ValidatorFactory::class);
539545
}
540546

541547
/**
@@ -921,21 +927,34 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
921927

922928
$customerAddresses = $customer->getAddresses() ?: [];
923929
$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+
924948
try {
925949
// If customer exists existing hash will be used by Repository
926950
$customer = $this->customerRepository->save($customer, $hash);
927951
} catch (AlreadyExistsException $e) {
928952
throw new InputMismatchException(
929953
__('A customer with the same email address already exists in an associated website.')
930954
);
931-
} catch (LocalizedException $e) {
932-
throw $e;
933955
}
934956
try {
935957
foreach ($customerAddresses as $address) {
936-
if (!$this->isAddressAllowedForWebsite($address, $customer->getStoreId())) {
937-
continue;
938-
}
939958
if ($address->getId()) {
940959
$newAddress = clone $address;
941960
$newAddress->setId(null);

app/code/Magento/Customer/Test/Unit/Model/AccountManagementApiTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Customer\Model\AccountManagement;
1919
use Magento\Customer\Model\AccountManagement\Authenticate;
2020
use Magento\Customer\Model\AccountManagementApi;
21+
use Magento\Customer\Model\AddressFactory;
2122
use Magento\Customer\Model\AddressRegistry;
2223
use Magento\Customer\Model\AuthenticationInterface;
2324
use Magento\Customer\Model\Config\Share;
@@ -51,6 +52,7 @@
5152
use Magento\Framework\Session\SessionManagerInterface;
5253
use Magento\Framework\Stdlib\StringUtils;
5354
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
55+
use Magento\Framework\Validator\Factory as ValidatorFactory;
5456
use Magento\Store\Api\Data\StoreInterface;
5557
use Magento\Store\Model\StoreManagerInterface;
5658
use PHPUnit\Framework\MockObject\MockObject;
@@ -365,7 +367,15 @@ protected function setUp(): void
365367
[
366368
EmailNotificationInterface::class,
367369
$this->createMock(EmailNotificationInterface::class)
368-
]
370+
],
371+
[
372+
AddressFactory::class,
373+
$this->createMock(AddressFactory::class)
374+
],
375+
[
376+
ValidatorFactory::class,
377+
$this->createMock(ValidatorFactory::class)
378+
],
369379
];
370380
$this->objectManagerHelper->prepareObjectManager($objects);
371381
$this->accountManagement = $this->objectManagerHelper->getObject(

0 commit comments

Comments
 (0)