Skip to content

Commit 3fd6746

Browse files
committed
ACP2E-3791: [Cloud] Delete operation is forbidden for current area error during customer account creation
1 parent 7bb4ca9 commit 3fd6746

File tree

2 files changed

+123
-125
lines changed

2 files changed

+123
-125
lines changed

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

Lines changed: 23 additions & 6 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;
@@ -406,6 +405,11 @@ class AccountManagement implements AccountManagementInterface
406405
*/
407406
private Authenticate $authenticate;
408407

408+
/**
409+
* @var AddressFactory
410+
*/
411+
private AddressFactory $addressFactory;
412+
409413
/**
410414
* @param CustomerFactory $customerFactory
411415
* @param ManagerInterface $eventManager
@@ -446,6 +450,7 @@ class AccountManagement implements AccountManagementInterface
446450
* @param Backend|null $eavValidator
447451
* @param CustomerLogger|null $customerLogger
448452
* @param Authenticate|null $authenticate
453+
* @param AddressFactory|null $addressFactory
449454
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
450455
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
451456
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -491,7 +496,8 @@ public function __construct(
491496
?AuthenticationInterface $authentication = null,
492497
?Backend $eavValidator = null,
493498
?CustomerLogger $customerLogger = null,
494-
?Authenticate $authenticate = null
499+
?Authenticate $authenticate = null,
500+
?AddressFactory $addressFactory = null,
495501
) {
496502
$this->customerFactory = $customerFactory;
497503
$this->eventManager = $eventManager;
@@ -536,6 +542,7 @@ public function __construct(
536542
$this->eavValidator = $eavValidator ?? $objectManager->get(Backend::class);
537543
$this->customerLogger = $customerLogger ?? $objectManager->get(CustomerLogger::class);
538544
$this->authenticate = $authenticate ?? $objectManager->get(Authenticate::class);
545+
$this->addressFactory = $addressFactory ?? $objectManager->get(AddressFactory::class);
539546
}
540547

541548
/**
@@ -921,15 +928,25 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
921928

922929
$customerAddresses = $customer->getAddresses() ?: [];
923930
$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+
924943
try {
925944
// If customer exists existing hash will be used by Repository
926945
$customer = $this->customerRepository->save($customer, $hash);
927946
} catch (AlreadyExistsException $e) {
928947
throw new InputMismatchException(
929948
__('A customer with the same email address already exists in an associated website.')
930949
);
931-
} catch (LocalizedException $e) {
932-
throw $e;
933950
}
934951
try {
935952
foreach ($customerAddresses as $address) {

0 commit comments

Comments
 (0)