We can set a value to the new field in the customer record while registering from the website by extending “register” function in Account.Model.
_.extend(AccountModel, {
register: function (user_data) {
var customfields = {};
var guest_data = ModelsInit.customer.getFieldValues();
var newFieldvalue = <value>
user_data.newFieldvalue = newFieldvalue;
for (var property in user_data) {
if (property.substring(0, 10) == 'custentity') {
customfields[property] = user_data[property];
}
}
if (ModelsInit.customer.isGuest()) {
var guest_data = ModelsInit.customer.getFieldValues();
ModelsInit.customer.setLoginCredentials({
internalid: guest_data.internalid
, email: user_data.email
, password: user_data.password
});
ModelsInit.session.login({
email: user_data.email
, password: user_data.password
});
if (Object.keys(customfields).length) {
ModelsInit.customer.updateProfile({
internalid: guest_data.internalid
, firstname: user_data.firstname
, lastname: user_data.lastname
, companyname: user_data.company
, emailsubscribe: (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F'
, customfields: customfields
, <fieldId>: user_data.newFieldvalue
});
} else {
ModelsInit.customer.updateProfile({
internalid: guest_data.internalid
, firstname: user_data.firstname
, lastname: user_data.lastname
, companyname: user_data.company
, emailsubscribe: (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F'
, <fieldId>: user_data.newFieldvalue
});
}
}
else {
user_data.emailsubscribe = (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F';
var result = ModelsInit.session.registerCustomer({
firstname: user_data.firstname
, lastname: user_data.lastname
, companyname: user_data.company
, email: user_data.email
, password: user_data.password
, password2: user_data.password2
, emailsubscribe: (user_data.emailsubscribe && user_data.emailsubscribe !== 'F') ? 'T' : 'F'
, <fieldId>: user_data.newFieldvalue
});
if (Object.keys(customfields).length && result.customerid) {
ModelsInit.customer.updateProfile({
internalid: result.customerid
, customfields: customfields
, <fieldId>: user_data.newFieldvalue
});
}
}
var user = Profile.get();
user.isLoggedIn = ModelsInit.session.isLoggedIn2() ? 'T' : 'F';
user.isRecognized = ModelsInit.session.isRecognized() ? 'T' : 'F';
return {
touchpoints: ModelsInit.session.getSiteSettings(['touchpoints']).touchpoints
, user: user
, cart: LiveOrder.get()
, address: Address.list()
, creditcard: CreditCard.list()
};
}
});