From 505e258b63a882bfaccbf2146e16398c04422a8d Mon Sep 17 00:00:00 2001 From: DanieliMi Date: Thu, 22 Feb 2024 14:37:12 +0100 Subject: [PATCH] Set isSecureArea before deleting customer Deletion of the customer is only possible if isSecureArea is true. If it is not set deletion will fail with an exception and the customer will not know why the registration failed and will not be able to register again due to the existing entity. --- app/code/Magento/Customer/Model/AccountManagement.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index a5792c1ce20df..8d94efb075770 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -943,7 +943,15 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash } $this->customerRegistry->remove($customer->getId()); } catch (InputException $e) { + $originalValue = $this->registry->registry('isSecureArea'); + $this->registry->unregister('isSecureArea'); + $this->registry->register('isSecureArea', true); + $this->customerRepository->delete($customer); + + $this->registry->unregister('isSecureArea'); + $this->registry->register('isSecureArea', $originalValue); + throw $e; } $customer = $this->customerRepository->getById($customer->getId());