Skip to content

Commit 9a84997

Browse files
committed
ACP2E-3791: [Cloud] Delete operation is forbidden for current area error during customer account creation
1 parent 60713e8 commit 9a84997

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,15 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
928928

929929
$customerAddresses = $customer->getAddresses() ?: [];
930930
$customer->setAddresses(null);
931+
$customerAddresses = array_filter(
932+
$customerAddresses,
933+
fn ($address) => $this->isAddressAllowedForWebsite($address, $customer->getStoreId())
934+
);
931935
foreach ($customerAddresses as $address) {
932936
$addressModel = $this->addressFactory->create()->updateData($address);
937+
if ($this->configShare->isWebsiteScope()) {
938+
$addressModel->setStoreId($customer->getStoreId());
939+
}
933940
$errors = $addressModel->validate();
934941
if ($errors !== true) {
935942
$exception = new InputException();
@@ -950,9 +957,6 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
950957
}
951958
try {
952959
foreach ($customerAddresses as $address) {
953-
if (!$this->isAddressAllowedForWebsite($address, $customer->getStoreId())) {
954-
continue;
955-
}
956960
if ($address->getId()) {
957961
$newAddress = clone $address;
958962
$newAddress->setId(null);

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

Lines changed: 6 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;
@@ -365,7 +366,11 @@ protected function setUp(): void
365366
[
366367
EmailNotificationInterface::class,
367368
$this->createMock(EmailNotificationInterface::class)
368-
]
369+
],
370+
[
371+
AddressFactory::class,
372+
$this->createMock(AddressFactory::class)
373+
],
369374
];
370375
$this->objectManagerHelper->prepareObjectManager($objects);
371376
$this->accountManagement = $this->objectManagerHelper->getObject(

0 commit comments

Comments
 (0)