Rule box category Work with prices & math
Use the rule box category Work with prices & math to manage numbers and math functions in Productsup.
Introduction
The category Work with prices & math contains all rule boxes that can help you perform calculations, set prices, add VAT, round up numbers, convert currencies, and add discounts.
This category can be divided into several subgroups. In the following sections, you can find how to use the rule boxes of the Work with prices & math category:
Add VAT to your prices and convert currencies
The Work with prices & math rule box category contains the Add VAT and Convert Currency rule boxes to let you adapt your prices to different markets.
Add VAT
The Add VAT rule box adds the Value Added Tax to your prices based on a desired percentage.
Take the steps from Add a rule box to add the Add VAT rule box.
In the input field, enter a required tax percentage without the percent symbol (%). If you leave this field empty, the rule box applies 19% VAT by default.
Choose how you want to round off the numbers after applying the VAT percentage:
always round up rounds off your prices by favoring rounding up.
round uses the standard rules of rounding off numbers without favoring rounding up or down.
always round down rounds off your prices by favoring rounding down.
Select what the rule box should do if a current value isn't a number:
leave unchanged doesn't change the current value.
treat as 0 adds
0
to overwrite the current value.return empty string empties the value.
Select Save.
For example, you have the following values in the price attribute. You want to add a 19% VAT to the prices of your products and round them up. You can achieve this with the Add VAT rule box:
price (before) | price (after) |
---|---|
323.69 |
|
34.89 |
|
3.39 |
|
If you choose the round option, your prices will be 385.19
, 41.52
, 4.03
. And if you choose the always round down option, your prices will be 385.19
, 41.51
, 4.03
.
Convert Currency
The Convert Currency rule box converts prices to a selected currency using the Open Exchange Rates API.
Take the steps from Add a rule box to add the Convert Currency rule box.
In Source Currency, select the currency used in your current values.
In Target Currency, select the target currency you need.
In Default Value, select what the rule box should do with non-numeric and empty values in the attribute:
0.00 overwrites non-numeric values with
0.00
./empty/ leaves non-numeric values unchanged.
Select Save.
For example, you have the following values in the price attribute and want to convert them from USD to EUR. You can achieve this with the Convert Currency rule box by selecting USD and EUR as the source and target currencies:
price (before) | price (after) |
---|---|
323.69 |
|
34.89 |
|
3.39 |
|
|
Add discounts
The Work with prices & math rule box category contains the Discount and Discount Percentage rule boxes to let you calculate prices based on a set discount or the discounted percentage based on the original and the sale prices.
Discount
The Discount rule box sets a reduced price if one or two selected attributes contain certain values.
Take the steps from Add a rule box to add the Discount rule box.
In Mandatory Column, select the attribute that should contain certain values for the rule box to add a discounted price in the current attribute.
Choose the condition that the mandatory attribute should meet regarding the searched values:
Contains applies the discount if the searched attribute contains one of the provided values.
Contains not applies the discount if the searched attribute doesn't contain one of the provided values.
Is Empty applies the discount if the searched attribute contains an empty value. If you choose this option, you can skip Step 4.
greater than applies the discount if the searched attribute contains a number greater than one of the provided values.
less than applies the discount if the searched attribute contains a number less than one of the provided values.
equals to applies the discount if the searched attribute contains a number equal to one of the provided values or if the searched attribute contains a text value completely identical to one of the provided values.
In the text field, enter the values that the rule box should search for in the chosen attribute. To enter multiple terms, start each term from a new line without a delimiter.
Tip
If you want to apply a discount to all products, you can add this mandatory condition: the price attribute should be greater than
0
.If you want to apply a discount based on the contents of two attributes, set up a condition for another attribute.
Note
If you set up two conditions, a product has to fulfill both the mandatory and the optional conditions for the rule box to apply the discount.
Select an attribute in Optional Column.
Choose the condition that the optional attribute should meet regarding the searched values:
Contains applies the discount if the searched attribute contains one of the provided values.
Contains not applies the discount if the searched attribute doesn't contain one of the provided values.
Is Empty applies the discount if the searched attribute contains an empty value. If you choose this option, you can skip Step 5.c.
greater than applies the discount if the searched attribute contains a number greater than one of the provided values.
less than applies the discount if the searched attribute contains a number less than one of the provided values.
equals to applies the discount if the searched attribute contains a number equal to one of the provided values or if the searched attribute contains a text value completely identical to one of the provided values.
In the text field, enter the values that the rule box should search for in the chosen attribute. To enter multiple terms, start each term from a new line without a delimiter.
Enter a number without the percent symbol (%) in Discount to define the percentage of the discount.
In If column non-numeric, select what the rule box should do if a current value isn't a number:
leave unchanged doesn't change the current value.
treat as 0 adds
0.00
to overwrite the current value. If the current value is empty, this option leaves it empty.return empty string empties the value.
Select Save.
For example, you have the following values in the price attribute and want to apply an 11% discount to all boots and sneakers for women. You can achieve this with the following setup of the Discount rule box:
category (no changes) | gender (no changes) | price (before) | price (after) |
---|---|---|---|
Apparel & Accessories > Shoes > Winter Boots | women | 323.69 |
|
Apparel & Accessories > Shoes > Sneakers | women | 34.89 |
|
Apparel & Accessories > Shoes > Sneakers | men, women | 3.39 | 3.39 |
Apparel & Accessories > Shoes > Winter Boots | men |
Discount Percentage
The Discount Percentage rule box calculates the difference between two prices, for example, the original and the sale price, and assigns this difference as a percentage in the attribute where you add the rule box.
Take the steps from Add a rule box to add the Discount Percentage rule box.
Select the relevant attributes in Old Price and New Price. The former should be your original price, and the latter should be your discounted price.
In Round Precision, enter the number of decimal places for your discount percentage.
Optionally, you can add text before or after your discount percentage in Text Before and Text After.
Select Save.
For example, you have empty values in the discount_percent attribute and want to calculate the discount percentage based on the attributes price and discounted_price. Besides that, you want discount_percent to display its values with additional text at the end, for example, 30% OFF. You can achieve this with the following setup of the Discount Percentage rule box:
price (no changes) | discounted_price (no changes) | discount_percent (before) | discount_percent (after) |
---|---|---|---|
323.69 | 288.08 |
| |
34.89 | 30.00 |
| |
3.39 | 3.39 |
|
Tidy up price formats and amounts
The Work with prices & math rule box category contains the Make Valid Price and Round Numeric Values rule boxes to let you validate your prices and round them off.
Make Valid Price
The Make Valid Price rule box cleans up the format of the price attribute, for example, from 1.234,23 EUR to 1234.23
as a standard accepted price format. It tidies up price formats by:
Changing the price decimal separator from a comma (,) to a dot (
.
) or vice versa.Removing currency symbols, thousand separators, or other text.
To set up the rule box:
Take the steps from Add a rule box to add the Make Valid Price rule box.
In Decimal Separator, select the desired decimal separator:
dot (1234.23) separates your decimal places with a dot.
comma (1234,23) separates your decimal places with a comma.
automatic leaves both dots and commas as decimal separators in your values.
In Default Value, select what the rule box should do with the empty and non-numeric values in the attribute:
0.00 or 0,00 overwrites the values with
0.00
or0,00
based on your chosen decimal separator.Empty Column empties non-numeric values.
Select Save.
For example, you have the following values in the price attribute and want to convert them to the standard accepted price format with a dot as a decimal separator. You can achieve this with the Make Valid Price rule box:
price (before) | price (after) |
---|---|
323 EUR |
|
34,89 |
|
3.39 | 3.39 |
INVALID |
|
Round Numeric Values
The Round Numeric Values rule box rounds off the fractional part of a numeric value.
Take the steps from Add a rule box to add the Round Numeric Values rule box.
In Round Precision, enter the number of digits after the decimal point that your rounded-off numbers should have.
In If column value is not a number, select what the rule box should do if a current value isn't a number:
leave unchanged doesn't change the current value.
treat as 0 adds
0
to overwrite the current value.return empty string empties the value.
Select Save.
For example, you have the following values in the price attribute and want to round them off to 2 digits after the decimal point. You can achieve this with the Round Numeric Values rule box by entering 2
in Round Precision:
price (before) | price (after) |
---|---|
323.6923489 |
|
34,89873 |
|
3.393 |
|
Perform calculations with numeric attributes
The Work with prices & math rule box category contains the rule boxes Math, Column Math, Math Template, and In-Row Math to let you perform calculations of varying levels of complexity with the numeric attributes in your site.
Math
The Math rule box performs calculations with numbers in the current attribute and either a static number provided in the rule box setup or the dynamic numbers from another attribute. See Rule box category Add static or dynamic values for the difference between static and dynamic values.
Take the steps from Add a rule box to add the Math rule box.
In Operator, select a required operation to add, subtract, multiply, or divide values in the current attribute:
+
-
*
/
Choose if you want to perform the calculation using a static or dynamic value:
If you want to make calculations with numbers from a different attribute, choose a relevant attribute in Column.
If you want to make calculations with the same number for all products in the current attribute, enter that number in Static Value.
Note
If you provide both the dynamic and static numbers, the rule box ignores the chosen attribute and makes calculations with the static number.
Enter the allowed number of decimal places for the calculated result in Round Precision, or leave it empty to produce whole numbers.
In If column not numeric, select what the rule box should do if a value in the current attribute isn't a number:
leave unchanged doesn't change the current value.
treat as 0 adds
0
to overwrite the current value.return empty string empties the value.
Choose how you want to round off the resulting numbers:
round up rounds off your numbers by favoring rounding up.
round uses the standard rules of rounding off numbers without favoring rounding up or down.
round down rounds off your numbers by favoring rounding down.
Select Save.
For example, you have the following values in the price attribute and want to add shipping costs from shipping to your prices. If the price attribute contains an empty or other non-numeric value, you want to treat it as zero. You can achieve this with the following setup of the Math rule box:
shipping (no changes) | price (before) | price (after) |
---|---|---|
15.46 | 323.69 |
|
30 | 34.89 |
|
3.39 | 3.39 |
|
10.5 | 10.5 | |
1 |
|
Column Math
The Column Math rule box lets you perform two operations with static numbers provided in the rule box setup or dynamic numbers from other attributes.
The rule box uses the following formula:
current_attribute |
| ( | chosen_attribute_1 or static number 1 |
| chosen_attribute_2 or static number 2 | ) |
| result that overwrites the value in current_attribute |
You can choose other operations, not only addition (+).
The rule box calculates the part in brackets first.
Take the steps from Add a rule box to add the Column Math rule box.
In Current Field Value, select a required operation to add, subtract, multiply, or divide values in the current attribute. This operation takes place second.
+
-
*
/
In Operator, select a required operation to add, subtract, multiply, or divide the provided static numbers or the dynamic numbers of the chosen attributes. This operation takes place first.
+
-
*
/
Choose the first number for the first operation:
If you want to make calculations with numbers from a different attribute, choose a relevant attribute in Input Column 1.
If you want to make calculations with a static number, enter that number in Input Static Value 1.
Choose the second number for the first operation:
If you want to make calculations with numbers from another attribute, choose a relevant attribute in Input Column 2.
If you want to make calculations with a static number, enter that number in Input Static Value 2.
Enter the allowed number of decimal places for the calculated result in Round Precision, or leave it empty to produce whole numbers.
Select Save.
For example, you have the following values in the price attribute and want to add shipping costs from shipping to your prices. But the shipping attribute contains shipping costs for a package of products, while you need to add individual shipping costs to price. You first need to divide the shipping costs by the number of items in a package from items_in_package and then add the result to price. You can achieve this with the following setup of the Column Math rule box:
shipping (no changes) | items_in_package (no changes) | price (before) | price (after) |
---|---|---|---|
15.46 | 1 | 323.69 |
|
30 | 18 | 34.89 |
|
3.39 | 2 | 3.39 |
|
Here is the formula used in the rule box, with the numbers from the second row: 34.89+(30/18)=36.56
.
Math Template
The Math Template rule box lets you perform your calculations with a custom formula. You can use the current attribute, up to 3 other attributes, and any static numbers to perform calculations via Twig. With Twig, you can create custom formulas, such as:
{{ (value / column1) * 45 + column2 }}
You can use the following operators in Twigs:
For addition, subtraction, division, and multiplication, use
+
,-
,/
, and*
, respectively.For calculating the remainder of an integer division, use
%
. For example,{{ 11 % 7 }}
is 4.For raising the left operand to the power of the right operand, use
**
. For example,{{ 2 ** 3 }}
is 8.For floor division, use
//
. For example,{{ 20 // 7 }}
is 2.
See Twig Fiddle to create and test your formulas. See Twig-based rule box capabilities to enhance your product data for use cases and rules for creating Twigs in Productsup.
To set up the Math Template rule box:
Take the steps from Add a rule box to add the Math Template rule box.
In Optional Column 1, Optional Column 2, and Optional Column 3, select up to 3 attributes if you want to use their values in your calculations.
In Twig Template, enter a valid Twig that should work as your formula. Use the >_ icon to get an AI-generated suggestion for a valid Twig.
The Twig should begin and end with curly brackets and spaces:
{{ calculation }}
.You must refer to the values of the current attribute as
value
.You must refer to the values of the chosen attributes as
column1
,column2
, orcolumn3
.
Enter the allowed number of decimal places for the calculated result in Round Precision, or leave it empty to avoid trimming the resulting numbers.
Select Save.
For example, you have the following values in the price attribute and want to add shipping costs from shipping and import tax costs from import_tax to your prices. But the shipping and import_tax attributes contain costs for a package of products, while you need to add individual costs to price. You first need to divide the shipping and import tax costs by the number of items in a package from items_in_package and then add the result to price. You can achieve this with the following setup of the Math Template rule box:
The Twig used in this setup is {{ value + (column1 / column3) + (column2 / column3) }}
.
shipping (no changes) | import_tax (no changes) | items_in_package (no changes) | price (before) | price (after) |
---|---|---|---|---|
15.46 | 74.4487 | 1 | 323.69 |
|
30 | 8.0247 | 18 | 34.89 |
|
3.39 | 0.7797 | 2 | 3.39 |
|
Here is the formula used in the rule box, with the numbers from the second row: 34.89+(30/18)+(8.0247/18)=37
.
In-Row Math
The In-Row Math rule box adds or multiplies the numbers in a value if they are separated by a delimiter.
Take the steps from Add a rule box to add the In-Row Math rule box.
In Delimiter, enter a character that separates numbers in your attribute values. Common delimiters are commas (,), semicolons (;), quotes (" or '), braces ({}), pipes (|), or slashes (/ or \).
In Operator, define what you want to do with the numbers in your values:
Add delivers a sum of the delimited numbers.
Multiply delivers a product of the delimited numbers.
Select Save.
For example, your items attribute stores the number of items in stock for each product size, separated with a delimiter, and you want to add them all up to know the total number of products in stock. You can achieve this with the In-Row Math rule box by entering ,
as the delimiter:
items (before) | items (after) |
---|---|
1,42,6,3 |
|
6,2,1,6 |
|
3/12,54,6 |
|
In the last row, you can see that the rule box ignores the number separated from other numbers with a different delimiter.