Hello NetSuite Gurus,
I'm trying to listen for ?promocode=XXX in the URL and in specific cases to not apply it. I'm trying to modify PromocodeSupport.ts Module under SC_20.1_Live/Advanced/PromocodeSupport/JavaScript/PromocodeSupport.ts.
const PromocodeSupport: any = {
mountToApp: function() {
// Method defined in file UrlHelper.js
UrlHelper.addTokenListener('promocode', function(value) {
// Because this is passed from the URL and there might be spaces and special chars,
// we need to fix this so it does not invalidate our promocode
value = unescape(value.replace(/[+]/g, ' '));
// isB2C true/false logic to be implemented here
let isB2C = true;
if(!isB2C) {
const liveorder = LiveOrderModel.getInstance();
const promocodes = liveorder.get('promocodes') || [];
const new_promocodes = promocodes.concat({code: value});
// We get the instance of the ShoppingCart and apply the promocode
liveorder.save({promocodes: new_promocodes}).always(function savePromocodeEnded() {
liveorder.trigger('promocodeUpdated', 'applied');
});
}
if(isB2C) {
const liveorder = LiveOrderModel.getInstance();
const new_promocodes = [];
liveorder.save({promocodes: new_promocodes}).always(function savePromocodeEnded() {
liveorder.trigger('promocodeUpdated', 'applied');
});
}
let url;
url = Backbone.history.fragment
.replace('&promocode=' + value, '')
.replace('?promocode=' + value, '');
Backbone.history.navigate(url, { trigger: false, replace: true });
return false;
});
}
};
export = PromocodeSupport;
When isB2C = true, I'm applying empty array of promocodes. That code is working on the local SCA server and when the customer is trying www.domainname.com/?promocode=XXX the promocode is not applied and any other applied promocodes are removed. The problem is when the same code is deployed in the account it never works as expected. The promocode is always applied regardless the logic in the code. My question is how can I make the SCA to not apply promotional code through URL for any special cases.
Thanks!