Skip to content

Commit 454b726

Browse files
authored
Merge pull request #783 from abhishek-webkul/gli-1472
Updated: Do not create multiple guest acounts with the same email, use previous one if available
2 parents 5f72627 + 1171b20 commit 454b726

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

controllers/front/AuthController.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ protected function processSubmitAccount()
389389
if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email)) {
390390
if (Customer::customerExists($email)) {
391391
$this->errors[] = Tools::displayError('An account using this email address has already been registered.', false);
392-
} elseif (Customer::customerExists($email, false, false)) {
392+
} elseif (Tools::getValue('is_new_customer', 1) && Customer::customerExists($email, false, false)) {
393393
$this->errors[] = Tools::displayError('You are already registered as a guest with this email address.').'&nbsp;<button type="submit" class="btn btn-link alert-link btn-transform" name="submitTransformAccount">'.Tools::displayError('Click here').'</button>'.Tools::displayError('').' to generate a password for your account.';
394394
}
395395
}
@@ -591,8 +591,16 @@ protected function processSubmitAccount()
591591
}
592592

593593
if (!count($this->errors)) {
594-
if (Customer::customerExists(Tools::getValue('email'))) {
595-
$this->errors[] = Tools::displayError('An account using this email address has already been registered. Please enter a valid password or request a new one. ', false);
594+
if (!Tools::getValue('is_new_customer', 1)) {
595+
if ($idCustomer = Customer::customerExists(Tools::getValue('email'), true, false)) {
596+
if ($idAddress = Customer::getCustomerIdAddress($idCustomer)) {
597+
$address = new Address($idAddress);
598+
}
599+
}
600+
} else {
601+
if (Customer::customerExists(Tools::getValue('email'))) {
602+
$this->errors[] = Tools::displayError('An account using this email address has already been registered. Please enter a valid password or request a new one. ', false);
603+
}
596604
}
597605

598606
$this->processCustomerNewsletter($customer);
@@ -606,11 +614,17 @@ protected function processSubmitAccount()
606614
$customer->active = 1;
607615
// New Guest customer
608616
if (Tools::isSubmit('is_new_customer')) {
609-
$customer->is_guest = !Tools::getValue('is_new_customer', 1);
617+
if ($idCustomer) {
618+
// update guest customer details
619+
$customer = new Customer($idCustomer);
620+
$customer->firstname = Tools::getValue('firstname');
621+
$customer->lastname = Tools::getValue('lastname');
622+
}
623+
$customer->is_guest = 1;
610624
} else {
611625
$customer->is_guest = 0;
612626
}
613-
if (!$customer->add()) {
627+
if (!$customer->save()) {
614628
$this->errors[] = Tools::displayError('An error occurred while creating your account.');
615629
} else {
616630
foreach ($addresses_types as $addresses_type) {
@@ -627,7 +641,7 @@ protected function processSubmitAccount()
627641
if ($addresses_type == 'address_invoice') {
628642
$_POST = $post_back;
629643
}
630-
if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount')) && !$$addresses_type->add()) {
644+
if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount')) && !$$addresses_type->save()) {
631645
$this->errors[] = Tools::displayError('An error occurred while creating your address.');
632646
}
633647
}

0 commit comments

Comments
 (0)