This is our first example of a basic custom pricing script.
Instead of utilising the Generic pricing script, the pricing for this product is obtained using a separately written script, usually to perform a very specific task.
In this case, we are working with the scenario that different prices are required to be shown based on the status of the customer accessing the product. This has been accomplished with a short script which displays a separate price based on the department of the customer accessing the product.
var file = Item.getGlobalFileContent("CustomPricingScript1.csv"); //Identify the CSV file to use
//Predefine some variables for use in the script, drawing values from the Infigo product where necessary
var sku = Item.Sku; //Reads the SKU for the product
var defaultPrice = Item.Price; //Reads the Price field for the product
var userDepartment = Item.Department; //Reads the department for the current user
var csvTable = file.CsvContent; //Ensures we can read the CSV content
//Read the current user department and the product SKU. Return a price based on these two values.
if(csvTable[0][0] && csvTable[0][0].toLowerCase() === "sku")
{
for(var i = 1; i < csvTable.length; i++) {
if(sku == csvTable[i][0]){
if(userDepartment == csvTable[0][3]) { //Lower Fee column
return parseFloat(csvTable[i][3]);
}
else {
return parseFloat(csvTable[i][2]); //Higher Fee column
}
}
}
}
return defaultPrice;