create_customer
Generates a form for creating a new customer account.
Params
form_type{String}The name of the desired form type.content{String}The form contents.hash{Object}form html attributes,optionalreturns{String}html
Inputs
| input | type | name | required | remarks |
|---|---|---|---|---|
| customer[email] | Required for merchants to open email registration | |||
| phone | phone | customer[phone] | Required for merchants to open cell phone number registration | Cell phone number format: international closed phone number, e.g. China cell phone number: 15600000000 |
| area code | text | customer[code] | Required for merchants to open cell phone number registration | Area code is the international telephone area code, for example, China cell phone area code: 86 |
| password | password | customer[password] | yes | |
| Verification Code | text | customer[verifycode] | Required when the merchant opens the identity verification | |
| first name | text | customer[first_name] | no | |
| last name | text | customer[last_name] | no | |
| birthday | date | customer[birthday] | no | |
| gender | number | customer[gender] | no | |
| email subscription | checkbox | customer[accepts_marketing] | no | |
| custom fields | string | attribute[your_key] | no | e.g.<input name="attribute[age]" /> |
Example
{{#form 'create_customer'}}
<div class="account">
<label for="email">{{ t 'user.username' }}</label>
<input type="text" name="customer[email]" placeholder="{{ t 'user.username' }}" />
</div>
<div class="password">
<label for="password">{{ t 'user.password' }}</label>
<input type="password" name="customer[password]" placeholder="{{ t 'user.password' }}" />
</div>
{{#if form.registerConfig.checkTag}}
<div class="verifycode">
<input type="text" name="customer[verifycode]" placeholder="{{ t 'user.code' }}" />
<button class="verifycode-button">{{ t 'user.send' }}</button>
</div>
{{/if}}
{{#if form.registerConfig.firstNameCheck}}
<div class="first-name">
<label for="first-name">{{ t 'user.firstName' }}</label>
<input type="text" name="customer[first_name]" placeholder="{{ t 'user.firstName' }}" />
</div>
{{/if}}
{{#if form.registerConfig.lastNameCheck}}
<div class="last-name">
<label for="last-name">{{ t 'user.lastName' }}</label>
<input type="text" name="customer[last_name]" placeholder="{{ t 'user.lastName' }}" />
</div>
{{/if}}
{{#if form.registerConfig.birthdayCheck}}
<div class="birthday">
<label for="birthday">{{ t 'user.birthday' }}</label>
<input type="date" name="customer[birthday]" placeholder="{{ t 'user.birthday' }}" />
</div>
{{/if}}
<div class="age">
<label for="age">{{ t 'user.age' }}</label>
<input type="text" name="attribute[age]" placeholder="{{ t 'user.age' }}" />
</div>
<div class="accepts-marketing">
<input type="checkbox" name="customer[accepts_marketing]" value="true">
<label for="accepts-marketing">Subscribe to email marketing</label>
</div>
<div class="submit">
<input class="submit-button" type="submit" value="{{ t 'user.signUp' }}">
</div>
{{/form}}
Used in conjunction
The above code needs to be used in conjunction with the following script.
class Register {
constructor() {
this.form = document.querySelector('#create-customer-form');
this.form.addEventListener('submit', this.onSubmitHandler.bind(this));
this.verifyCodeButton = this.form.querySelector('.verifycode-button');
this.verifyCodeButton.addEventListener(
'click', this.onSendVerifyCodeHandler.bind(this)
);
this.register = new window.Shopline.customerAccount.Register(this.form)
}
// Sending email or SMS verification code
onSendVerifyCodeHandler(e) {
e.preventDefault();
if (this.verifyCodeButton.getAttribute('aria-disabled') === 'true') return;
this.verifyCodeButton.setAttribute('aria-disabled', true);
this.register.sendVerifyCode()
.then(response => {
if (response.errorMessage) {
this.verifyCodeError = true;
// Handling send failure exception scenarios
}
})
.finally(() => {
if (!this.verifyCodeError) {
this.verifyCodeButton.removeAttribute('aria-disabled');
}
})
}
// Registration Logic
onSubmitHandler(e) {
e.preventDefault();
this.register.submit()
.then(response => {
window.location.href = '/user/center';
})
.catch(error => {
// Handling registration failure exception scenarios
})
}
}
// Initialize user login registration JS SDK
window.Shopline.loadFeatures(
[
{
name: 'customer-account-api',
version: '0.3'
}
],
function(error) {
if (error) {
throw error;
}
new Register();
}
);
Was this article helpful to you?