Redirect To Homepage When Customer Register

The code is added below for redirect to the homepage when the customer Register into the Website.


define(
	'JJ.LoginRegister.LoginRegister'
	, [
		'JJ.LoginRegister.LoginRegister.View', 'LoginRegister.Register.View', 'Utils'
	]
	, function (
		LoginRegisterView, LoginRegisterRegisterView, Utils
	) {
		'use strict';

		return {
			mountToApp: function mountToApp(container) {
				// using the 'Layout' component we add a new child view inside the 'Header' existing view 
				// (there will be a DOM element with the HTML attribute data-view="Header.Logo")
				// more documentation of the Extensibility API in
				// https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/index.html

				/** @type {LayoutComponent} */
				var layout = container.getComponent('Layout');

				_.extend(LoginRegisterRegisterView.prototype, {

					redirect: function(_context, response) {
						const self = this;
						return this.cancelableTrigger('after:LoginRegister.register').then(function() {
							const url_options = Utils.parseUrlOptions(window.location.search);
							const { touchpoints } = response;
							const { application } = self;
				
							if (url_options.is && url_options.is === 'checkout') {
								const profile_model = ProfileModel.getInstance();
				
								response.user && profile_model.set(response.user);
								response.cart && LiveOrderModel.getInstance().set(response.cart);
								response.address && profile_model.get('addresses').reset(response.address);
								response.paymentmethod &&
									profile_model.get('paymentmethods').reset(response.paymentmethod);
				
								// Track Guest Checkout Event
								self.trackEvent(function() {
									application.setConfig('currentTouchpoint', 'checkout');
									Backbone.history.navigate('', { trigger: true });
								});
							} else {
								// Track Login Event
								self.trackEvent(function() {
									// if we know from which touchpoint the user is coming from
									if (url_options.origin && touchpoints[url_options.origin]) {
										// we save the url to that touchpoint
										let url = touchpoints[url_options.origin];
										// if there is an specific hash
										if (url_options.origin_hash) {
											// we add it to the url as a fragment
											url = Utils.addParamsToUrl(url, { fragment: url_options.origin_hash });
										}
										window.location.href = url;
									} else {
										// We've got to disable passwordProtectedSite feature if customer registration is disabled.
										if (
											Configuration.getRegistrationType() !== 'disabled' &&
											SC.ENVIRONMENT.siteSettings.siteloginrequired === 'T'
										) {
											window.location.href = touchpoints.home;
										} else {
											// otherwise we need to take it to the customer center
											window.location.href = touchpoints.home;
										}
									}
								});
							}
						});
					},
				})

			}
		};
	});

Leave a comment

Your email address will not be published. Required fields are marked *