Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

This page contains a listing of available variables for adjusting pricing at the Order Level.
To see how Pricing Scripts work generally, please read General Rules for Pricing Scripts .

In contrast to scripts for materials and post-processing, Order Level Pricing Scripts are meant to be applied based on the selections of the customer while ordering. That is why these variables are accessible for each material and post-processing method.

As Order Level Pricing Scripts are applied to a whole order, they are not added to a material pricing script. Instead, place them in Settings → Agile ERP Settings → Order Pricing → Additional Order Fees.

Available Order Level Variables

Variable

Description

lines[0].model.volume

Line volume for the first line.
(Use [1] for the 2nd item and so on)

lines[0].support.volume

Line support volume for the first line.
(Use [1] for the 2nd item and so on)

All other model and support variables

See model and support variables here: Material Pricing Scripts based on Material Cost

lines[0].price

Line unit price for the first line.
(Use [1] for the 2nd item and so on)
This value is null if the line is to be priced manually

lines[0].quantity

Line quantity
(Use [1] for the 2nd item and so on)

lines[0].title

Line name
(Use [1] for the 2nd item and so on)

lines[0].product.title

Material name of the line item
(Use [1] for the 2nd item and so on)

lines[0].product.technology

3D printing technology of the line item
(Use [1] for the 2nd item and so on)

lines[0].post_processings[0].title
lines[0].post_processings[0].price
lines[0].post_processings[0].color

Post processing title, price (net) and color for the line item
(Use [1] for the 2nd item and so on)

line[0].product.density_min
line[0].product.density_max

Line density for the material
(Use [1] for the 2nd item and so on)

pick_up

Boolean, if true if shipping type is Pick Up Location

User Based Pricing

See User Based Pricing Scripts

Note: If Manual Pricing is enabled and triggered, the resulting Request will have a total request value of ‘null’. Therefore, if using the lines[0].price variable, it is necessary to allow for this null condition in the pricing script to avoid a script error.

Examples

Shipping Fee based on Weight

Calculates the weight of all models in the basket and charges €10 / kg as an additional shipping fee.

Code Block
languagejs
let mass = 0;
let rate = 10;
let total_volume = 0;
let total_quantity = 1;

const
countryCodes = ['DK', 'DNK', 'NO', 'NOR', 'FI', 'FIN', 'SE', 'SWE']
let userCode = user.country_code;
if ((userCode) && (countryCodes.includes(userCode))) {
	for (let line of lines) {
		total_quantity = line.quantity;
		total_volume = (line.model.volume + line.support.volume) * total_quantity
		mass += total_volume * line.product.density_min / 1000000;
}
}
let additional_cost = rate * mass;
additional_cost;

Discount based on pickup location selected

Code Block
languagejs
let discount;
if (pick_up){
  discount = 100;
} else {
  discount = 1;
}

-discount;

Discount based on Material

In this example, a discount is applied if the total volume / area of the total order of all items in a specific material exceeds a threshold.

Code Block
languagejs
// Discount Based on total volume / area

// Change this to the material
const material = "PA12";  

// leave the following lines untouched
let material_subtotal = 0;
let material_volume = 0;
let material_area = 0;
let discount = 0;
for (let line of lines) {
	if (line.product.title == material) {
		material_volume += line.model.volume;
		material_area += line.model.area;
		material_subtotal += parseFloat(line.price);
	}
}

// Adjust the following variables for you needs

if (material_volume > 10000 && material_area > 1000) {
	discount = 0.05 * material_subtotal;
}

else if (material_volume > 20000 && material_area > 2000) {
	discount = 0.10 * material_subtotal;
}

// Last line contains the negative fee = discount.
-discount;

Additional Fee for Changing Materials

Checks if there are models with different materials but the same technology. If yes, we will charging charge $25 for each material switch on a machine.

Code Block
languagejs
const all_technologies = lines.map((line) => line.product.technology);
let all_technologies_grouped = new Set(all_technologies);
let n = 0;
let fee = 25;
for (let technology of all_technologies_grouped) {
	let v = [];
	for (let line of lines) {
    		if(line.product.technology == technology) {
        		v.push(line.product.title);
    		}
}
let new_v = new Set(v);
n += new_v.size - 1;
}
n * fee;

Minimum Order Fee for Materials & Post-Processing

This script takes care that the printing and/or post-processing will cost at least a certain amount. It will only work from version 4.2 on.

Code Block
languagejs
// Minimum Order Priceses

// Adjust the titles and values here.
// All items from the order in this material combined
// must at least cost this much.
// If a line contains a material that is not in this list
// it is ignored by this script (also the Post-Processing of it)
const materialsMinPrices = {
    "PA12": 69,
    "PA 2210 FR": 69,
    "Accura Xtreme": 69,
    };

// Adjust the titles and values here.
// All items from the order in this post processing combined
// must at least cost this much.
// If coloring is used, each color counts seperately.
const ppMinPrices = {
    "Coloring": 5,
    "Polishing": 5,
    "Sandblasting": 5,
};

// Don't modify the following lines

let materialsUsed = {};
let ppsUsed = {};

for (let line of lines) {
    if (!line.price) continue; // line is manually priced
    let materialTitle = line.product.title;
    if(materialTitle in materialsMinPrices) {
        if (!(materialTitle in materialsUsed)) {
            materialsUsed[materialTitle] = parseFloat(materialsMinPrices[materialTitle]);
        }
        materialsUsed[materialTitle] -= parseFloat(line.price);

        for (let postProcessing of line.post_processings) {
            let ppTitleColor = postProcessing.color ? materialTitle + postProcessing.title + postProcessing.color : postProcessing.title;         
            if (!ppTitleColor || !postProcessing.price) { continue; }
            if (!(ppTitleColor in ppsUsed)) {
                ppsUsed[ppTitleColor] = parseFloat(ppMinPrices[postProcessing.title]);
            }
            ppsUsed[ppTitleColor] -= parseFloat(postProcessing.price);
            if(materialTitle in materialsMinPrices) {
                materialsUsed[materialTitle] += parseFloat(postProcessing.price);
            }
        }
    }
}

let fee = 0;

for (let [material, value] of Object.entries(materialsUsed)) {
    if (value > 0) {
        fee += value;
    }
}
for (let [pp, value] of Object.entries(ppsUsed)) {
    if (value > 0) {
        fee += value;
    }
}
fee;