Change guest account transformation flow
This commit is contained in:
@@ -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.').' <button type="submit" class="btn btn-link alert-link btn-transform" name="submitTransformAccount">'.Tools::displayError('Click here').'</button>'.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
|
||||
|
||||
@@ -50,11 +50,17 @@
|
||||
</div>
|
||||
{/if}-->
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="alert alert-success" id="guest_transform_success" style="display:none">
|
||||
{l s='Your guest account has been transformed into a customer account successfully and the login credentials have been sent to you. Please make sure to change the password for security.'}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
<form action="{$link->getPageLink('authentication', true)|escape:'html':'UTF-8'}" method="post" id="create-account_form" class="box">
|
||||
<h3 class="page-subheading">{l s='Create an account'}</h3>
|
||||
<div class="form_content clearfix">
|
||||
<p class="content">{l s='Please enter your email address to create an account.'}</p>
|
||||
<div class="alert alert-info" id="create_account_information" style="display:none"></div>
|
||||
<div class="alert alert-danger" id="create_account_error" style="display:none"></div>
|
||||
<div class="form-group">
|
||||
<label for="email_create" class="">{l s='Email address'}</label>
|
||||
@@ -68,7 +74,6 @@
|
||||
{l s='Create an account'}
|
||||
</span>
|
||||
</button>
|
||||
<input type="hidden" class="hidden" name="SubmitCreate" value="{l s='Create an account'}" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
margin-bottom: 8px; }
|
||||
#create-account_form .form-group {
|
||||
margin: 0 0 20px 0; }
|
||||
#create-account_form .btn-transform {
|
||||
padding: 0;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
vertical-align: initial;
|
||||
text-decoration: underline; }
|
||||
|
||||
#login_form {
|
||||
min-height: 297px; }
|
||||
|
||||
@@ -22,17 +22,31 @@
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
$(document).ready(function(){
|
||||
$(document).on('submit', '#create-account_form', function(e){
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).on('click', '#SubmitCreate', function(e) {
|
||||
e.preventDefault();
|
||||
submitFunction();
|
||||
submitFunction('SubmitCreate');
|
||||
});
|
||||
|
||||
$(document).on('click', '.btn-transform', function(e) {
|
||||
e.preventDefault();
|
||||
submitFunction('submitTransformAccount');
|
||||
});
|
||||
$('.is_customer_param').hide();
|
||||
});
|
||||
|
||||
function submitFunction()
|
||||
{
|
||||
function submitFunction(submitAction) {
|
||||
$('#create_account_error').html('').hide();
|
||||
var data = {
|
||||
controller: 'authentication',
|
||||
ajax: true,
|
||||
email_create: $('#email_create').val(),
|
||||
back: $('input[name=back]').val(),
|
||||
token: token
|
||||
};
|
||||
data[submitAction] = 1;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: baseUri + '?rand=' + new Date().getTime(),
|
||||
@@ -40,62 +54,66 @@ function submitFunction()
|
||||
cache: false,
|
||||
dataType : "json",
|
||||
headers: { "cache-control": "no-cache" },
|
||||
data:
|
||||
{
|
||||
controller: 'authentication',
|
||||
SubmitCreate: 1,
|
||||
ajax: true,
|
||||
email_create: $('#email_create').val(),
|
||||
back: $('input[name=back]').val(),
|
||||
token: token
|
||||
},
|
||||
success: function(jsonData)
|
||||
{
|
||||
if (jsonData.hasError)
|
||||
{
|
||||
var errors = '';
|
||||
for(error in jsonData.errors)
|
||||
//IE6 bug fix
|
||||
if(error != 'indexOf')
|
||||
errors += '<li>' + jsonData.errors[error] + '</li>';
|
||||
$('#create_account_error').html('<ol>' + errors + '</ol>').show();
|
||||
data: data,
|
||||
success: function(jsonData) {
|
||||
// display confirmations
|
||||
if (jsonData.hasConfirmation) {
|
||||
if (in_array('TRANSFORM_OK', jsonData.confirmations)) {
|
||||
$('#guest_transform_success').show('slow');
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jsonData.hasInformation) {
|
||||
var informations = '';
|
||||
for(information in jsonData.informations) {
|
||||
//IE6 bug fix
|
||||
if(information != 'indexOf') {
|
||||
informations += '<li>' + jsonData.informations[information] + '</li>';
|
||||
}
|
||||
}
|
||||
$('#create_account_information').html('<ol>' + informations + '</ol>').show();
|
||||
return;
|
||||
}
|
||||
if (jsonData.hasError) {
|
||||
var errors = '';
|
||||
for(error in jsonData.errors) {
|
||||
//IE6 bug fix
|
||||
if(error != 'indexOf') {
|
||||
errors += '<li>' + jsonData.errors[error] + '</li>';
|
||||
}
|
||||
}
|
||||
$('#create_account_error').html('<ol>' + errors + '</ol>').show();
|
||||
} else {
|
||||
// adding a div to display a transition
|
||||
$('#center_column').html('<div id="noSlide">' + $('#center_column').html() + '</div>');
|
||||
$('#noSlide').fadeOut('slow', function()
|
||||
{
|
||||
$('#noSlide').fadeOut('slow', function() {
|
||||
$('#noSlide').html(jsonData.page);
|
||||
$(this).fadeIn('slow', function()
|
||||
{
|
||||
if (typeof bindUniform !=='undefined')
|
||||
$(this).fadeIn('slow', function() {
|
||||
if (typeof bindUniform !=='undefined') {
|
||||
bindUniform();
|
||||
if (typeof bindStateInputAndUpdate !=='undefined')
|
||||
}
|
||||
if (typeof bindStateInputAndUpdate !=='undefined') {
|
||||
bindStateInputAndUpdate();
|
||||
}
|
||||
document.location = '#account-creation';
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
error = "TECHNICAL ERROR: unable to load form.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus;
|
||||
if (!!$.prototype.fancybox)
|
||||
{
|
||||
$.fancybox.open([
|
||||
{
|
||||
if (!!$.prototype.fancybox) {
|
||||
$.fancybox.open([{
|
||||
type: 'inline',
|
||||
autoScale: true,
|
||||
minHeight: 30,
|
||||
content: "<p class='fancybox-error'>" + error + '</p>'
|
||||
}],
|
||||
{
|
||||
}], {
|
||||
padding: 0
|
||||
});
|
||||
}
|
||||
else
|
||||
} else {
|
||||
alert(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user