This is another 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 calculating a price per sqm, where the user is inputting the width and height of the product. The script is handling the background calculation and is returning the updated price.
Some error handling is also included to ensure a price of £10,000 is returned when a price cannot be calculated.
//Pre-set critical values to 0
var width = Item.getAttributeValue("Width"); //Define a product attribute as a variable
var height = Item.getAttributeValue("Height"); //Define a product attribute as a variable
//Pre-set values to 0 to ensure a clean start each time the script is run
var sqmPrice = 0;
var sqm = 0;
var finalPrice=0;
//begin price calculation
sqm = width*height;
sqmPrice = Item.Price; //Call a value specified within Infigo into the script. In this case, the Price field for the product.
//error handling - default on no calculated price is £10,000
if (isNaN(sqm) || sqm === 0) {
return 10000;
}
//return price
finalPrice = sqmPrice * sqm;
return finalPrice; //The returned price