Skip to content

Commit

Permalink
Prevent creating duplicate customers in some scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlavtox committed Jun 28, 2024
1 parent 2937cae commit 7e3de73
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions classes/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down
7 changes: 7 additions & 0 deletions controllers/front/GuestTrackingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions controllers/front/OrderConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7e3de73

Please sign in to comment.