From 7a9322c610b0b2506c72d4fda4abc7172bcfd339 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 17 Aug 2023 09:30:17 +0530 Subject: [PATCH 1/2] Use previous guest account if available during guest checkout --- controllers/front/AuthController.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 320da13dd..4975c268f 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -386,8 +386,28 @@ class AuthControllerCore extends FrontController if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email)) { if (Customer::customerExists($email)) { $this->errors[] = Tools::displayError('An account using this email address has already been registered.', false); - } elseif (Customer::customerExists($email, false, false)) { - $this->errors[] = Tools::displayError('You are already registered as a guest with this email address.').' '.Tools::displayError('').' to generate a password for your account.'; + } elseif ($idCustomer = Customer::customerExists($email, true, false)) { + $return = array(); + $objCustomer = new Customer($idCustomer); + if (!$objCustomer->active || $objCustomer->deleted) { + $this->errors[] = Tools::displayError('You can not create a booking using this email.', false); + } + + if (!count($this->errors)) { + $this->context->updateCustomer($objCustomer, 1); + $this->context->cart->update(); + + $return['isSaved'] = true; + $return['id_customer'] = (int)$this->context->cookie->id_customer; + $return['id_address_delivery'] = $this->context->cart->id_address_delivery; + $return['id_address_invoice'] = $this->context->cart->id_address_invoice; + $return['token'] = Tools::getToken(false); + } + + $return['hasError'] = !empty($this->errors); + $return['errors'] = $this->errors; + + $this->ajaxDie(json_encode($return)); } } From 1171b20344c2c69007e26bbba2244f2f401417c3 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 23 Nov 2023 15:16:14 +0530 Subject: [PATCH 2/2] Fix account and address update --- controllers/front/AuthController.php | 48 ++++++++++++---------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 4975c268f..da9baad37 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -386,28 +386,8 @@ class AuthControllerCore extends FrontController if (Validate::isEmail($email = Tools::getValue('email')) && !empty($email)) { if (Customer::customerExists($email)) { $this->errors[] = Tools::displayError('An account using this email address has already been registered.', false); - } elseif ($idCustomer = Customer::customerExists($email, true, false)) { - $return = array(); - $objCustomer = new Customer($idCustomer); - if (!$objCustomer->active || $objCustomer->deleted) { - $this->errors[] = Tools::displayError('You can not create a booking using this email.', false); - } - - if (!count($this->errors)) { - $this->context->updateCustomer($objCustomer, 1); - $this->context->cart->update(); - - $return['isSaved'] = true; - $return['id_customer'] = (int)$this->context->cookie->id_customer; - $return['id_address_delivery'] = $this->context->cart->id_address_delivery; - $return['id_address_invoice'] = $this->context->cart->id_address_invoice; - $return['token'] = Tools::getToken(false); - } - - $return['hasError'] = !empty($this->errors); - $return['errors'] = $this->errors; - - $this->ajaxDie(json_encode($return)); + } elseif (Tools::getValue('is_new_customer', 1) && Customer::customerExists($email, false, false)) { + $this->errors[] = Tools::displayError('You are already registered as a guest with this email address.').' '.Tools::displayError('').' to generate a password for your account.'; } } @@ -608,8 +588,16 @@ class AuthControllerCore extends FrontController } if (!count($this->errors)) { - if (Customer::customerExists(Tools::getValue('email'))) { - $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); + if (!Tools::getValue('is_new_customer', 1)) { + if ($idCustomer = Customer::customerExists(Tools::getValue('email'), true, false)) { + if ($idAddress = Customer::getCustomerIdAddress($idCustomer)) { + $address = new Address($idAddress); + } + } + } else { + if (Customer::customerExists(Tools::getValue('email'))) { + $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); + } } $this->processCustomerNewsletter($customer); @@ -623,11 +611,17 @@ class AuthControllerCore extends FrontController $customer->active = 1; // New Guest customer if (Tools::isSubmit('is_new_customer')) { - $customer->is_guest = !Tools::getValue('is_new_customer', 1); + if ($idCustomer) { + // update guest customer details + $customer = new Customer($idCustomer); + $customer->firstname = Tools::getValue('firstname'); + $customer->lastname = Tools::getValue('lastname'); + } + $customer->is_guest = 1; } else { $customer->is_guest = 0; } - if (!$customer->add()) { + if (!$customer->save()) { $this->errors[] = Tools::displayError('An error occurred while creating your account.'); } else { foreach ($addresses_types as $addresses_type) { @@ -644,7 +638,7 @@ class AuthControllerCore extends FrontController if ($addresses_type == 'address_invoice') { $_POST = $post_back; } - if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount')) && !$$addresses_type->add()) { + if (!count($this->errors) && (Configuration::get('PS_REGISTRATION_PROCESS_TYPE') || $this->ajax || Tools::isSubmit('submitGuestAccount')) && !$$addresses_type->save()) { $this->errors[] = Tools::displayError('An error occurred while creating your address.'); } }