This extension is to navigate to the checkout page when the user is logged out, pages shown on the config record will be only shown
Configuration File
{
"type": "object",
"subtab": {
"id": "gatekeeper",
"title": "Gate Keeper Extension",
"description": "Customization made on gate keeper extension",
"group": "extensions"
},
"properties": {
"gatekeeper.data": {
"group": "extensions",
"subtab": "gatekeeper",
"type": "array",
"title": "Excluded Urls",
"description": "When the user is logged out these urls wont be checked by gate keeper",
"items": {
"type": "object",
"properties": {
"button": {
"type": "string",
"title": "Page",
"description": ""
},
"link": {
"type": "string",
"title": "Url",
"description": ""
}
}
},
"default": [
{
"button": "LogOff",
"link": "?logoff=T&whence="
},
{
"button": "FAQ",
"link": "about-us"
},
{
"button": "Our Story",
"link": "our-story"
},
{
"button": "Meet our Team",
"link": "meet-team"
},
{
"button": "Privacy Policy",
"link": "privacy-policy"
},
{
"button": "Accessibility Policy",
"link": "accessibility-policy"
},
{
"button": "Shipping",
"link": "shipping"
},
{
"button": "Ordering And Online Accounts",
"link": "online-accounts"
},
{
"button": "Terms And Conditions",
"link": "terms-and-conditions"
}
]
},
"gatekeeper.showSearch": {
"group": "extensions",
"subtab": "gatekeeper",
"type": "boolean",
"title": "Remove Item Search",
"default": true
}
}
}
Javascript File
// @module JJ.GateKeeper.GateKeeper
define('JJ.GateKeeper.GateKeeper.View', [
'jj_gatekeeper_gatekeeper.tpl',
'Backbone',
'underscore',
'Profile.Model'
], function (
template,
Backbone,
_,
ProfileModel
) {
'use strict';
// @class JJ.GateKeeper.GateKeeper.View @extends Backbone.View
return Backbone.View.extend({
template: template,
initialize: function () {
Backbone.history.on('route', this.beforeCompositeViewRender, this);
},
beforeCompositeViewRender: function () {
const isLoggedIn = ProfileModel.getInstance().get('isLoggedIn') === 'T';
if (!isLoggedIn) {
$("html").addClass("private-window");
const urlfragment = Backbone.history.fragment;
const currentUrl = window.location.href;
let excludedURL = [];
const urlList = _.isEmpty(SC.CONFIGURATION.gatekeeper.data);
if (!urlList) {
excludedURL = SC.CONFIGURATION.gatekeeper.data.map(item => item.link);
}
const home = SC.getSessionInfo().touchpoints.home;
if (home + "/" === currentUrl) {
_.defer(() => {
$("html").removeClass("private-window");
});
return true;
}
if (!excludedURL.includes(urlfragment) && !currentUrl.includes("scs/checkout.ssp")) {
const checkoutUrl = SC.getSessionInfo().touchpoints.login;
const redirectURL = home + checkoutUrl;
window.location.replace(redirectURL);
} else {
_.defer(() => {
$("html").removeClass("private-window");
});
}
if (SC.CONFIGURATION.gatekeeper.showSearch) {
_.defer(() => {
$(".header-menu-search-link").removeAttr("data-action");
$(".header-menu-search-link").addClass("remove-icon");
});
}
}
},
getContext: function () {
this.beforeCompositeViewRender();
return {
message: ""
};
}
});
});