Documentation for the entire Pricing Script engine. Type declarations can be found in the NPM package and can be used for your TypeScript and JavaScript projects to get full IntelliSense support.
The item management system provides access to all product-related data and functionality needed for pricing calculations. This includes the main product item, its attributes, pricing tiers, and versioning information.
The file handling system provides comprehensive information about uploaded files, allowing scripts to make pricing decisions based on file characteristics.
The system configuration provides access to script settings, parameters, and output functions that control behavior and functionality.
Helper methods provide utility functions for common pricing calculations and data manipulation tasks, making it easier to write complex pricing logic.
When working with pricing script objects, all data is read-only and accessed through the provided interfaces. The script receives the current state of the pricing context and returns the calculated price or pricing adjustments.
Updates to the pricing system are handled through the return value of the script, which can include price modifications, attribute adjustments, and other pricing-related changes.
Pricing scripts are triggered by various events in the pricing system:
The script can react to these events by recalculating prices, adjusting attributes, or providing user feedback.
Pricing scripts can store and retrieve data in various ways:
The pricing script system supports various file types for file-based pricing calculations:
For document-based pricing, the system provides access to:
Simple pricing calculations can be performed using basic arithmetic operations on the Item.Price property and attribute adjustments.
Complex pricing models can be implemented using the tier system, which supports:
Dynamic pricing can be calculated based on selected attributes:
File characteristics can influence pricing decisions:
Pricing scripts should validate their inputs and handle edge cases:
Robust pricing scripts should include error recovery mechanisms:
Simple pricing calculation based on quantity and base price:
// Basic price calculation with markup
var basePrice = Item.Price;
var quantity = Item.Quantity;
var markup = 1.25; // 25% markup
var totalPrice = basePrice * quantity * markup;
debug("Base: $" + basePrice + " x " + quantity + " = $" + totalPrice);
return totalPrice;
Fixed price with quantity discounts:
var unitPrice = 10.00;
var quantity = Item.Quantity;
var discount = 0;
// Apply quantity-based discounts
if (quantity >= 100) {
discount = 0.20; // 20% off for 100+
} else if (quantity >= 50) {
discount = 0.15; // 15% off for 50+
} else if (quantity >= 25) {
discount = 0.10; // 10% off for 25+
}
var finalPrice = unitPrice * quantity * (1 - discount);
debug("Quantity: " + quantity + ", Discount: " + (discount * 100) + "%");
return finalPrice;
Using built-in tier pricing with HelperMethods:
// Define pricing tiers
var tiers = [
{ Quantity: 1, Price: 5.00 },
{ Quantity: 50, Price: 4.00 },
{ Quantity: 100, Price: 3.50 },
{ Quantity: 250, Price: 3.00 },
{ Quantity: 500, Price: 2.50 },
{ Quantity: 1000, Price: 2.00 }
];
// Find the appropriate tier for the current quantity
var tier = HelperMethods.FindTier(Item.Quantity, tiers);
if (tier) {
var totalPrice = tier.Price * Item.Quantity;
debug("Tier price: $" + tier.Price + " for qty " + Item.Quantity);
return totalPrice;
}
return Item.Price * Item.Quantity;
Interpolated pricing for smooth transitions:
var tiers = [
{ Quantity: 1, Price: 10.00 },
{ Quantity: 100, Price: 8.00 },
{ Quantity: 500, Price: 6.00 },
{ Quantity: 1000, Price: 4.00 }
];
// Get interpolated price between tiers
var unitPrice = HelperMethods.InterpolatePrice(Item.Quantity, tiers);
var totalPrice = unitPrice * Item.Quantity;
debug("Interpolated unit price: $" + unitPrice.toFixed(2));
return totalPrice;
Apply different pricing based on customer roles:
var basePrice = Item.Price * Item.Quantity;
var discount = 0;
// Check for VIP customers
if (HelperMethods.Contains(Item.CustomerRoles, "VIP")) {
discount = 0.25; // 25% VIP discount
debug("VIP customer - 25% discount applied");
}
// Check for wholesale customers
else if (HelperMethods.Contains(Item.CustomerRoles, "Wholesale")) {
discount = 0.20; // 20% wholesale discount
debug("Wholesale customer - 20% discount applied");
}
// Check for registered customers
else if (HelperMethods.Contains(Item.CustomerRoles, "Registered")) {
discount = 0.05; // 5% member discount
debug("Registered customer - 5% discount applied");
}
return basePrice * (1 - discount);
Role-based tier pricing:
// Define tiers with customer role support
var tiers = [
{ Quantity: 1, Price: 10.00 },
{ Quantity: 50, Price: 8.00, CustomerRole: "Registered" },
{ Quantity: 50, Price: 7.00, CustomerRole: "Wholesale" },
{ Quantity: 50, Price: 6.00, CustomerRole: "VIP" },
{ Quantity: 100, Price: 6.00 },
{ Quantity: 100, Price: 5.00, CustomerRole: "Wholesale" },
{ Quantity: 100, Price: 4.00, CustomerRole: "VIP" }
];
// FindTier automatically considers customer roles
var tier = HelperMethods.FindTier(Item.Quantity, tiers, Item.CustomerRoles);
if (tier) {
return tier.Price * Item.Quantity;
}
return Item.Price * Item.Quantity;
Parse and use CSV data for pricing:
// CSV pricing data (could come from Configuration.ScriptConfig)
var csvData = "Quantity,Price,Setup\n1,5.00,25.00\n50,4.50,20.00\n100,4.00,15.00\n500,3.50,10.00";
// Parse CSV into array
var rows = HelperMethods.CSV.parse(csvData);
// Skip header row, find matching tier
var quantity = Item.Quantity;
var unitPrice = 5.00;
var setupFee = 25.00;
for (var i = 1; i < rows.length; i++) {
var row = rows[i];
if (quantity >= row[0]) {
unitPrice = row[1];
setupFee = row[2];
}
}
var totalPrice = (unitPrice * quantity) + setupFee;
debug("Unit: $" + unitPrice + ", Setup: $" + setupFee + ", Total: $" + totalPrice);
return totalPrice;
Calculate pricing based on uploaded file properties:
var basePrice = 0;
var files = Item.GetUploadedFiles();
if (files && files.length > 0) {
for (var i = 0; i < files.length; i++) {
var file = files[i];
// Price per page for PDFs
if (file.MimeType === "application/pdf") {
var pageCount = file.PageCount || 1;
var pricePerPage = 0.50;
basePrice += pageCount * pricePerPage;
debug("PDF: " + pageCount + " pages @ $" + pricePerPage + "/page");
}
// Price by file size for images
else if (file.MimeType.indexOf("image/") === 0) {
var sizeInMB = file.Size / (1024 * 1024);
var pricePerMB = 2.00;
basePrice += sizeInMB * pricePerMB;
debug("Image: " + sizeInMB.toFixed(2) + "MB @ $" + pricePerMB + "/MB");
}
}
}
return basePrice * Item.Quantity;
Apply discounts based on total cart value:
// Calculate total cart value from session
var cartTotal = 0;
for (var i = 0; i < Session.CartItems.length; i++) {
var cartItem = Session.CartItems[i];
cartTotal += cartItem.Price * cartItem.Quantity;
}
// Apply cart-wide discount tiers
var cartDiscount = 0;
if (cartTotal >= 500) {
cartDiscount = 0.15; // 15% off orders $500+
} else if (cartTotal >= 250) {
cartDiscount = 0.10; // 10% off orders $250+
} else if (cartTotal >= 100) {
cartDiscount = 0.05; // 5% off orders $100+
}
var itemPrice = Item.Price * Item.Quantity;
var discountedPrice = itemPrice * (1 - cartDiscount);
debug("Cart total: $" + cartTotal + ", Discount: " + (cartDiscount * 100) + "%");
return discountedPrice;
Calculate pricing based on dimensions:
// Get dimensions from item
var width = Item.Width || 0;
var height = Item.Height || 0;
// Calculate area in square inches
var areaInSqIn = width * height;
// Convert to square feet
var areaInSqFt = areaInSqIn / 144;
// Price per square foot with minimum
var pricePerSqFt = 2.50;
var minimumPrice = 10.00;
var calculatedPrice = areaInSqFt * pricePerSqFt * Item.Quantity;
var finalPrice = Math.max(calculatedPrice, minimumPrice);
debug("Area: " + areaInSqFt.toFixed(2) + " sq ft @ $" + pricePerSqFt + "/sq ft");
return finalPrice;
Apply pricing based on customer department (Session-level):
var basePrice = Item.Price * Item.Quantity;
var departmentDiscount = 0;
// Check customer department
switch (Session.Department) {
case "Marketing":
departmentDiscount = 0.15;
debug("Marketing department - 15% discount");
break;
case "Sales":
departmentDiscount = 0.10;
debug("Sales department - 10% discount");
break;
case "Education":
departmentDiscount = 0.20;
debug("Education department - 20% discount");
break;
default:
debug("Standard pricing applied");
}
return basePrice * (1 - departmentDiscount);
Calculate price adjustments from selected attributes:
var basePrice = Item.Price;
var attributeAdjustment = 0;
// Get attribute adjustments with tier support
attributeAdjustment = HelperMethods.GetAttributePriceAdjustment(
Item.Quantity,
Item.CustomerRoles
);
// Calculate total
var totalPrice = (basePrice + attributeAdjustment) * Item.Quantity;
debug("Base: $" + basePrice + ", Attributes: $" + attributeAdjustment);
return totalPrice;
Manual attribute iteration:
var basePrice = Item.Price;
var adjustments = 0;
// Iterate through all attributes
for (var i = 0; i < Item.Attributes.length; i++) {
var attr = Item.Attributes[i];
// Check if attribute has a selected value
if (attr.SelectedValue) {
adjustments += attr.SelectedValue.PriceAdjustment || 0;
debug(attr.Name + ": " + attr.SelectedValue.Name +
" (+$" + (attr.SelectedValue.PriceAdjustment || 0) + ")");
}
}
return (basePrice + adjustments) * Item.Quantity;
Apply pricing based on checkout/shipping information:
var basePrice = Item.Price * Item.Quantity;
var shippingSurcharge = 0;
// Check shipping destination country
if (CheckoutItem.Address && CheckoutItem.Address.Country) {
var countryCode = CheckoutItem.Address.Country.TwoLetterIsoCode;
// International shipping surcharge
if (countryCode !== "US") {
shippingSurcharge = 15.00;
debug("International shipping to " + countryCode + " - $15 surcharge");
}
// Remote area surcharge
if (countryCode === "AK" || countryCode === "HI") {
shippingSurcharge = 10.00;
debug("Alaska/Hawaii shipping - $10 surcharge");
}
}
// Business address discount
if (CheckoutItem.Address && CheckoutItem.Address.Company) {
basePrice *= 0.95; // 5% B2B discount
debug("Business address - 5% B2B discount applied");
}
return basePrice + shippingSurcharge;
Generated using TypeDoc