For the complete documentation index, see llms.txt. This page is also available as Markdown.

Formula

Formulas are the configurator's most powerful tool. With them you calculate prices, dimensions, weight, a product number or display values dynamically from your customers' input – such as "price = area × square-metre price" or "10% discount from 100 units".

This chapter explains formulas from the ground up. You need no programming knowledge – just a bit of logical thinking. You can use all examples directly.

Premium feature: "Expert calculation" (all formula inputs) is part of the Premium version. In other versions the formula fields are visible but disabled – see Advanced & Premium version.

What is a formula?

A formula is a small calculation expression that produces a result. In the simplest case it is pure maths:

price + 10

This formula means: take the product price and add 10. Instead of fixed numbers you can use variables – placeholders that are filled with the real values of the customer input at runtime.

Technical background: formulas use the template language Twig in a secured environment. Only the variables, functions and filters documented here are allowed – this keeps formulas safe.

Where do I enter formulas?

There are two places:

1. Configurator calculations (the configurator's Calculation tab). Each calculation has a switch and a formula field:

Calculation
Result
Variable type

Price

Final unit price

Number

Width / Height / Length / Weight

New dimension/weight value

Number

Product number

Generated product number

Text

2. Field calculations (the Calculation tab of an individual field):

Calculation
Result
Variable type

Default value

Pre-fill of the field

Number/Text

Result formula (only field type Interim result)

Live displayed value

Text

Available variables

In every formula you have these variables available:

Variable
Meaning

price

Base unit price of the product

width, height, length, weight

Dimensions and weight of the product

fields.<identifier>

The current value of a field, e.g. fields.quantity

options.<identifier>.price

Surcharge of the selected option of that field

options.<identifier>.width

Width of the selected option (likewise height, length, weight)

options.<identifier>.value

Technical value of the selected option

  • <identifier> is the technical identifier of the field (see Elements & field types).

  • For multiple choice, options.<identifier> refers to the first selected option.

  • Fields without input return an empty value – use the default filter for those (see below).

Calculating: operators

Operator
Meaning
Example

+ - * /

Basic arithmetic

price * 2

%

Remainder (modulo)

fields.quantity % 2

**

Power

width ** 2

~

Concatenate text

'NR-' ~ fields.colour

== != > < >= <=

Comparisons

fields.quantity >= 100

and or not

Logical combination

width > 0 and height > 0

Functions & filters

Functions (called with parentheses):

Function
Meaning
Example

max(a, b, …)

largest value

max(price, 25)

min(a, b, …)

smallest value

min(price, 500)

round(value, digits)

round

round(price, 2)

Filters (applied with |):

Filter
Meaning
Example

round

round

price|round(2)

ceil

round up

(price)|ceil

floor

round down

(price)|floor

abs

absolute (positive) value

price|abs

number_format

format

price|number_format(2)

default

fallback when empty

fields.quantity|default(1)

length

count/length

fields.lines|length

abs, ceil and floor exist only as filters (value|abs), not as functions.

Conditions and intermediate variables

You can use case distinctions and your own intermediate values:

The blocks {% if %}, {% elseif %}, {% else %}, {% set %} and {% for %} are allowed.

Important: how the price formula works

The price formula replaces the entire unit price – it is not a surcharge.

  • If the price calculation is active, the formula alone determines the price. Option surcharges are not added automatically – if you need them, include them via options.<identifier>.price in the formula.

  • If the price calculation is off, the rule is: product price + the sum of the selected option surcharges.

More about the interaction with cart and display under Price & cart.

Examples

Fixed surcharge

Include an option's surcharge

Area price (width × height)

Dimensions from customer input in centimetres, price per square metre = €40:

Quantity tiers (discount from a number of units)

Enforce a minimum price

Price per unit × quantity

Surcharge by material choice

Round cleanly to two decimals

Calculate a dimension (width formula)

Final width = base width + surcharge from input:

Calculate weight (weight formula)

Generate a product number (text formula)

Result e.g.: SIGN-gold-30x20

Show an interim result (result formula)

For a field of type Interim result:

Shows the customer live, e.g.: Area: 0.06 m²

Pre-fill a default value (default value formula)

Checking & error behaviour

  • Check the formula: While editing you can have a formula validated for correct syntax directly in the backend. Unknown variables or disallowed constructs are reported.

  • Robustness in the shop: If a formula does not produce a sensible result at runtime (e.g. due to a division by zero), the configurator automatically falls back to the base value (base price or base dimension). So your shop never shows an error, but in case of doubt the unchanged price.

Tips & pitfalls

  • Concatenate text with ~, calculate with + - * /. 'A' + 'B' does not work as expected.

  • Use the decimal point: 0.5, not 0,5.

  • Safeguard empty fields: fields.quantity|default(1) prevents calculating with an empty value.

  • Mind the units: convert lengths deliberately (e.g. cm → m² by dividing by 10000) so your square-metre price is correct.

  • abs, ceil, floor only as filters: value|ceil.

  • Start small: test a simple formula, check the result in the shop, then extend it step by step.

Last updated

Was this helpful?