A scriptable cart is used to make the customisation on the cart page. For example, if we are created a new price level for items and trying to strike through on the website will work except for the Cart page. On the cart page, it will show the default price and strikethrough. But Using a scriptable cart we can customise the cart page
/**
* Script Description
* This script will update the item line based on promotion
*/
/*******************************************************************************
* Ox tools
* **************************************************************************
*
* Date: 05-03-2021
*
* Author: Jobin & Jismi IT Services LLP
*
*
* REVISION HISTORY
*
*****************************************************************************
**/
var jjContext, entity, promotionPrice = '92';
function ClientPageInit(type) {
//
jjContext = nlapiGetContext().getExecutionContext();
nlapiLogExecution('DEBUG', 'SCA', ':: page init');
try {
var entity = nlapiGetFieldValue('entity')
} catch (error) {
nlapiLogExecution('DEBUG', 'entity', error);
}
if (jjContext == 'userinterface') {
nlapiLogExecution('DEBUG', 'userinterface', 'error');
}
}
function jjWebStore_ClientValidateLine(type) {
jjContext = nlapiGetContext().getExecutionContext();
nlapiLogExecution('DEBUG', 'jjContext', jjContext);
if (jjContext == 'webstore') {
// price override for SCA
try {
log.debug('testing')
promoPriceRecalc(); //
} catch (error) {
nlapiLogExecution('DEBUG', 'jjWebStore_ClientValidateLine', error);
}
}
return true;
}
/**
* Set correct price; apply column mapping
* runs on each line validation (on checkout - on back-end)
*/
function promoPriceRecalc() {
//
try {
var ItemDet = nlapiGetCurrentLineItemValue('item', 'item');
var domainUrl1 = nlapiGetContext();
nlapiLogExecution('DEBUG', 'domainUrl1', domainUrl1);
//.getSetting('SCRIPT', 'custscript_otgn_445_domainurl') || 'http://otgn.scatheme.ml/';
var domainUrl = 'http://bp.sca-jobinandjismi.ml/';
if (ItemDet) {
var domainUrl = 'http://bp.sca-jobinandjismi.ml/';
var fullUrl = domainUrl + 'api/items?id=' + ItemDet + '&fields=custitem59';
var headers = {
"Content-Type": "application/json",
"Accept": "application/json"
};
var response = nlapiRequestURL(fullUrl, null, headers, "GET");
var body = JSON.parse(response.getBody());
var code = response.getCode();
nlapiLogExecution('DEBUG', 'body', JSON.stringify(body));
nlapiLogExecution('DEBUG', 'code', code);
if (code == 200 && body.items[0].custitem59) {
nlapiSetCurrentLineItemValue('item', 'price', promotionPrice);
//nlapiSetCurrentLineItemValue('item', 'description', 'Updated for promotion');
}