diff --git a/classes/Customer.php b/classes/Customer.php index b9b4b042071dc..20310b8a6d978 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -1210,6 +1210,11 @@ public function transformToCustomer($idLang, $password = null) return false; } + // If a customer with the same email already exists, wrong call + if (Customer::customerExists($this->email)) { + return false; + } + $this->is_guest = false; /* diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 944ce5bc33d6d..b51e3e8046a25 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -113,6 +113,13 @@ public function postProcess() [], 'Shop.Notifications.Error' ); + // Check if a different customer with the same email was not already created in a different window or through backoffice + } elseif (Customer::customerExists($customer->email)) { + $this->errors[] = $this->trans( + 'You can\'t transform your account into a customer account, because a registered customer with the same email already exists.', + [], + 'Shop.Notifications.Error' + ); // Attempt to convert the customer } elseif ($customer->transformToCustomer($this->context->language->id, $password)) { $this->success[] = $this->trans( diff --git a/controllers/front/OrderConfirmationController.php b/controllers/front/OrderConfirmationController.php index 038de3b78b339..c12d09d3d20c0 100644 --- a/controllers/front/OrderConfirmationController.php +++ b/controllers/front/OrderConfirmationController.php @@ -181,12 +181,22 @@ public function postProcess() return; } + // Prevent error + // A) either on page refresh + // B) if we already transformed him in other window or through backoffice if ($this->customer->is_guest == 0) { $this->errors[] = $this->trans( 'A customer account has already been created from this guest account. Please sign in.', [], 'Shop.Notifications.Error' ); + // Check if a different customer with the same email was not already created in a different window or through backoffice + } elseif (Customer::customerExists($this->customer->email)) { + $this->errors[] = $this->trans( + 'You can\'t transform your account into a customer account, because a registered customer with the same email already exists.', + [], + 'Shop.Notifications.Error' + ); // Attempt to convert the customer } elseif ($this->customer->transformToCustomer($this->context->language->id, $password)) { $this->success[] = $this->trans(