# Formulas

To make dynamic calculations, the module uses a formula system.

The concept is to reference the fields by name between brackets, so if the field has the name width, then it can be referenced as [width]

The module will then replace the field references with their corresponding values

TIP

The module formulas use the same syntax as Excel

Adding a field to the formula is easy, you just need to click the field button to insert it.

Here are some formula example to get an idea about the syntax [width] * [height] / 10000 * 50

([width] + [height]) * 2

Many Excel functions can be used POW([width], 2)

If statement for conditional calculation IF([width] > 100, 10, 12)

TIP

The keyboard shortcut to save a formula is Ctrl + Enter

# Price formula

This formula is used to calculate the cost of the customization.

TIP

The result of this formula will be added to the base price of the product/combination

The module applies the taxes and the reductions to this result.
The reductions that the module supports are:

  • Product specific prices
  • Group reductions
  • Category reductions

# Weight formula

This formula is used to calculate the extra weight that the customization adds.
The result of this formula affects the shipping cost. To display the result of this formula, you can enable the weight display option .

# Quantity formula

This formula affects the quantity that is retracted from the stock when the order is validated.
This is useful when you want to retract meters for example instead of units.

Example:
You have a field named length that you would like to use to retract the number of ordered meters.
You can configure this formula:
[length]

If you'd like to retract by meter squared for example [width] * [length]

# Cost formula

This formula allows you to vary the product cost dynamically. It's useful to get a correct profit reporting.

For example, if you sell a product by the meter, you can configure this formula to calculate the cost based on the length.

Example: [height] * [cost_per_m]

# Field values for each type

  • Numeric Input
    The value is the html field value [width]

  • Slider
    The value is the current slider value [slider]

  • Dropdown
    The value is the selected option value [dropdown] To access the secondary value [[dropdown]]

  • Radio buttons
    The value is the selected option value [radio] To access the secondary value [[radio]]

  • Image list
    The value is the selected option value [list] To access the secondary value [[list]]

  • Checkbox
    The value is 1 if checked, 0 otherwise [checkbox]

    If you want to add an extra cost when the checkbox is checked: [checkbox] * 10 This will add 10 to the formula result when the checkbox is on.

  • Switch
    The value is 1 if checked, 0 otherwise [my_switch]

  • Text
    The value is the html field value. When using this field inside the formula, always surround it with quotes "[text]" To get the text length
    STRLEN("[text]")

    To check if the text was filled CHECK("[text]") This will return 0 if the text is empty and 1 otherwise

  • Text Area
    The value is the html field value. When using this field inside the formula, always surround it with quotes "[textarea]"

  • Date
    The value is the html field value. When using this field inside the formula, always surround it with quotes "[date]"

  • Image
    The value is the uploaded image name. You can check if there is an image that was uploaded by using the CHECK function

    CHECK("[image]") This will return 1 if there is an image, 0 otherwise

  • File
    The value is the uploaded file name. You can check if there is an file that was uploaded by using the CHECK function

    CHECK("[file]") This will return 1 if there is an image, 0 otherwise

  • Fixed Value
    The value is the current field value, that can be either the initial value of the value that was updated using PHP or using a field formula [fixed]

  • Price
    The value is the current field value, that can be either the initial value of the value that was updated using PHP or using a field formula [unit_price]

  • Dynamic Variable
    The value is the current field value, that can be either the initial value of the value that was updated using PHP or using a field formula [dynamic]

  • Feature
    The value is the feature value for the current language [feature]

  • Divider
    Cannot be used in the formula

  • Color picker
    The value is the html field value [picker]

  • Error message
    Can only be used in conditions

# Secondary values

For the fields of type Dropdown, Radio buttons and Image list, you can assign a secondary value to each option.
The way you use this secondary value in the formula is by using double brackets
Example [[dropdown]]

You can easily insert this expression by long pressing the field name