The option Expression enables extremely felxible calculations and combinations.

Through formulas, option values can easily be linked to each other, even if-then queries are possible. With the full scope of JavaScript functionality you are able to individualize your product even further.

Presentation in the frontend

The Expression is primarily designed for calculations in the backend, but of course you can have the result be displayed in the frontend.

Settings in the backend

As already mentioned, the expression is designed for you to input your customized Javascript-code. You can do so in the Calculation-field. If you are the guy who uses really complicated and long calculations, you even can switch the editor to its new full size mode with the blue button on its upper right corner.

In order to use values out of other options, you need to use the following syntax:

  • $variable.price returns the price of the linked option
  • $variable.originalPrice returns the original price of the linked option
  • $variable.qty returns the quatity of selected values.
  • If the selected option has multiple choices (multiselect, Multiselect with Quantity, Checkbox), an array with all values from the choosen optionvalues is returned.

For variable you need to insert the ID of the option you want to access.

Examples:

  • $valueX>=100?$valueY:0 

Here it is queried if the value of the option valueX is greater than or equal to 100. If this is the case, the expression is set to the value of the option value of the option valueY, otherwise the value 0.

  • if($valueX+$valueY>10)?10:20

If the sum of the value of option valueX and valueY is greater than 10, the expression returns 10, otherwise 20.

You can use artihmetic operations like addition, substraction, multiplication, division, modulo, ...

If you want to use branching conditions, please don't use multiple "if"-statements in a row, but the "switch-case"-statement or "if - else if - else"-branches.

  • switch($valueX) {case 1: 10; break; case 2: 20; break; default: 150;}

If the value of the option valueX is 1, the expression returns 10. If the the value is 2, the expression returns 20.

If the value is not 10 and not 20, the expression takes in the value 150.

Please give us a feedback! Does this article help you? If not, please do not hesitate to contact us personally via chat (blue chat button).

Did this answer your question?