Choose your language

Choose your login

Support

About the estimateCost(order) function

This page applies to:

When you create a cost script, the script editor is automatically populated with a basic template script containing the estimateCost(order) function. This function defines the cost estimate information that is displayed on the New Order form.

Use the template as a starting point for your cost script. It contains one line item, which is customizable; you can change the heading text, the description, and how it is calculated. Once you get the hang of it, you can add as many line items as will fit on the New Order form.

Example cost script

Here is an example of a simple cost script with only one line item.

New Order form

A screenshot showing the New Order form, showing cost estimations.

An example of the New Order form, showing cost estimations.

A screenshot showing the cost script associated with the above New Order form.

The cost script associated with the above New Order form.

Now let’s take a look at the template script in a bit more detail.

Define a line item

For each line item you want to display on the New Order form, you need to specify what will be displayed. This includes any individual line items, such as delivery costs, cumulative line items, such as Finishing costs, and any sub totals you might want to display, such as, cost per copy. While the template has only one line item, you can create as many line items as will fit on the New Order form.

New Order form
A screenshot of the New Order form showing the name, description, and cost.

An example of the New Order form, showing a name, description, and cost.

Costing script
printingCostLineItem = {
    name:           'Printing Costs',
    description:    printingDescription(order),
    cost:           paperCost + tonerCost,
    style:          'OPTION_1'
};

For each line item, you need to define the following:

Object Description
name The name of the line item as it appears on the New Order form. The name is displayed in bold. Try to limit this to 40 characters or less so that it fits on one line.
Valid format: String.
description The description of the line item that is displayed underneath the line item name. You can use any of the following:

- empty — no description is displayed. In this case, the description value is ’’.
- text strings — a description of the various options that are included in this line item. For example, you might have a line item for Finishing Costs. The description could be “Covers, binding, and hole punching”.
- variables — a variable defined earlier in the script. For example, you might use a variable that defines the cost per copy and the number of copies. In this case, the description would be something like “3 copies @ $7.50 per copy”. For more information, see Using variables .
- Order object attributes — a value defined in a product or delivery options configuration file. For example, you might use a method to retrieve the name of the Binding option selected in the order. For more information, see Using Order object attributes .
- functions — a function defined in the script that dynamically displays a description based on what a customer has selected. For example, if you define a function to return the exact paper stock, the description for a particular order could be “Paper stock: Letter, White, 80gsm”. For more information, see Using functions .
cost The way in which the line item cost is calculated. You can use any of the following:

- numbers — an exact cost. For example, you might charge a flat rate of $12.00 for posters. In this case, you would specify 12.0 as the line item cost.
- variables — a variable defined in the script. For example, you might use a variable that adds the cost of each Paper Stock attribute (color, size, and type) to calculate the line item cost for Paper Stock. For more information, see Using variables .
- Order object attributes — a value defined in a product or delivery options configuration file. For example, you might use a method to retrieve the cost of the selected Paper Stock. For more information, see Using Order object attributes .
- functions — if you have complex cost calculations, you might find it easier to define each one in a separate function that is then referenced. You might consider using a separate function if your cost calculation involves a For Loop or Conditional Statements. For more information, see Using functions .
style The css styling option that will be applied to the line item. The following options are available:

- OPTION_1 — Gray background behind the line item.
- OPTION_2 — White background behind the line item

Push a line item into the items array

Each line item needs to be pushed to an array that is then rendered in the Job Ticketing interface. Make sure you have this push command for every line item. This is done using the following command:

items.push(<line item object name>)

If you have a line item object called printingCostLineItem, the command would be:

items.push(printingCostLineItem)

Calculate the total cost

Now that you have defined all of the line item costs, you need to define a calculation for the total estimated cost. This calculation is the sum of specific line item costs. The total is handled differently to the individual line items as it does not need to be pushed to the items array. It is returned directly to the New Order form in Job Ticketing.

Example

In this example, the estimated cost is the sum of the sub-total ($3.80) and the delivery cost ($0.00).

New Order form

A screenshot of the New Order form, showing the total cost.

An example of the New Order form, showing the total cost.

Costing script

total = subtotal + deliveryCost;

Return the data to the New Order form

Now that you have defined each line item and pushed the line items to the items array, you need to send the array and the total cost to the caller of this function. For the estimateCost (order) function, the caller is the New Order form in Job Ticketing.

Costing script
return {
          total: total,
          description: '',
          items: items
       };
Object Description
total The value of the total that will be displayed.
description (optional) A description of the total estimated cost. This is displayed underneath the Estimated cost. You can use one of the following:

- empty — no description is displayed. In this case, the description value is ’’.
- text string — a static text string. For example, This is an estimate only. The final cost might differ slightly depending on your selections.
- function — a function defined in the script that dynamically displays a description based on what a customer has selected. For example, you might want to display all of the options selected by the customer rather than having separate line items. For more information, see Using functions .
- variables — a variable defined in the script. For example, you might use a variable that defines the cost per copy and the number of copies. In this case, the description would be something like “3 copies @ $7.50 per copy”. For more information, see Using variables .
items The name of the array (“items”) to which the line items have been pushed.

Comments