diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 96c3ea223..7df1c19de 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -44,6 +44,10 @@ class AuthControllerCore extends FrontController { parent::init(); + $this->confirmations = array(); + $this->informations = array(); + $this->errors = array(); + if (!Tools::getIsset('step') && $this->context->customer->isLogged() && !$this->ajax) { Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } @@ -161,6 +165,10 @@ class AuthControllerCore extends FrontController )); $return = array( + 'hasConfirmation' => !empty($this->confirmations), + 'confirmations' => $this->confirmations, + 'hasInformation' => !empty($this->informations), + 'informations' => $this->informations, 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'page' => $this->context->smarty->fetch($this->template), @@ -258,6 +266,10 @@ class AuthControllerCore extends FrontController $this->processSubmitAccount(); } + if (Tools::isSubmit('submitTransformAccount')) { + $this->processTransformAccount(); + } + if (Tools::isSubmit('SubmitLogin')) { $this->processSubmitLogin(); } @@ -746,9 +758,11 @@ class AuthControllerCore extends FrontController if (!Validate::isEmail($email = trim(Tools::getValue('email_create'))) || empty($email)) { $this->errors[] = Tools::displayError('Invalid email address.'); } elseif (Customer::customerExists($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->errors[] = Tools::displayError('An account using this email address has already been registered. Please choose another one or sign in.', false); $_POST['email'] = trim(Tools::getValue('email_create')); unset($_POST['email_create']); + } elseif ($id_customer = Customer::customerExists($email, true, false)) { + $this->informations[] = Tools::displayError('You are already registered as a guest with this email address.').' '.Tools::displayError('').' to transform your account.'; } else { $this->create_account = true; $this->context->smarty->assign('email_create', Tools::safeOutput($email)); @@ -756,6 +770,23 @@ class AuthControllerCore extends FrontController } } + /** + * Process submit for account transformation + */ + protected function processTransformAccount() + { + if (!Validate::isEmail($email = trim(Tools::getValue('email_create'))) || empty($email)) { + $this->errors[] = Tools::displayError('Invalid email address.'); + } elseif ($id_customer = Customer::customerExists($email, true, false)) { + $customer = new Customer($id_customer); + if ($customer->transformToCustomer($this->context->language->id)) { + $this->confirmations[] = 'TRANSFORM_OK'; + } else { + $this->errors[] = Tools::displayError('Your guest account could not be transformed to a customer account.'); + } + } + } + /** * Update context after customer creation * @param Customer $customer Created customer diff --git a/themes/hotel-reservation-theme/authentication.tpl b/themes/hotel-reservation-theme/authentication.tpl index 611cfd4e6..8751d9d70 100644 --- a/themes/hotel-reservation-theme/authentication.tpl +++ b/themes/hotel-reservation-theme/authentication.tpl @@ -50,11 +50,17 @@ {/if}-->
" + error + '
' - }], - { + }], { padding: 0 }); - } - else + } else { alert(error); + } } }); } \ No newline at end of file