Skip to main content

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.

work_with_prices___math.png

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.

  1. Take the steps from Add a rule box to add the Add VAT rule box.

    Add VAT rule box
  2. 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.

  3. 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.

  4. 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.

  5. 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

385.2

34.89

41.52

3.39

4.04

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.

  1. Take the steps from Add a rule box to add the Convert Currency rule box.

    Convert Currency rule box
  2. In Source Currency, select the currency used in your current values.

  3. In Target Currency, select the target currency you need.

  4. 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.

  5. 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

298.27

34.89

32.15

3.39

3.12

0.00

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.

  1. Take the steps from Add a rule box to add the Discount rule box.

    Discount rule box
  2. In Mandatory Column, select the attribute that should contain certain values for the rule box to add a discounted price in the current attribute.

  3. 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.

  4. 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.

  5. 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.

    1. Select an attribute in Optional Column.

    2. 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.

    3. 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.

  6. Enter a number without the percent symbol (%) in Discount to define the percentage of the discount.

  7. 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.

  8. 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:

The Discount rule box example: Mandatory Column: category Contains boots sneakers Optional Column: gender equal to women Discount 11%

category (no changes)

gender (no changes)

price (before)

price (after)

Apparel & Accessories > Shoes > Winter Boots

women

323.69

288.08

Apparel & Accessories > Shoes > Sneakers

women

34.89

31.05

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.

  1. Take the steps from Add a rule box to add the Discount Percentage rule box.

    Discount percentage rule box
  2. 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.

  3. In Round Precision, enter the number of decimal places for your discount percentage.

  4. Optionally, you can add text before or after your discount percentage in Text Before and Text After.

  5. 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:

Old Price: price, New Price: discounted_price, Round Precision: 0, Text After: % OFF

price (no changes)

discounted_price (no changes)

discount_percent (before)

discount_percent (after)

323.69

288.08

11% OFF

34.89

30.00

14% OFF

3.39

3.39

0% OFF

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:

  1. Changing the price decimal separator from a comma (,) to a dot (.) or vice versa.

  2. Removing currency symbols, thousand separators, or other text.

To set up the rule box:

  1. Take the steps from Add a rule box to add the Make Valid Price rule box.

    Make Price Valid rule box
  2. 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.

  3. 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 or 0,00 based on your chosen decimal separator.

    • Empty Column empties non-numeric values.

  4. 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

323.00

34,89

34.89

3.39

3.39

INVALID

0.00

Round Numeric Values

The Round Numeric Values rule box rounds off the fractional part of a numeric value.

  1. Take the steps from Add a rule box to add the Round Numeric Values rule box.

    Round Numeric Values​ rule box
  2. In Round Precision, enter the number of digits after the decimal point that your rounded-off numbers should have.

  3. 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.

  4. 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

323.69

34,89873

34.90

3.393

3.39

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.

  1. Take the steps from Add a rule box to add the Math rule box.

    Math rule box
  2. In Operator, select a required operation to add, subtract, multiply, or divide values in the current attribute:

    • +

    • -

    • *

    • /

  3. 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.

  4. Enter the allowed number of decimal places for the calculated result in Round Precision, or leave it empty to produce whole numbers.

  5. 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.

  6. 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.

  7. 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:

The Math rule box example: Operator: + Column: shipping Round Precision: 2 If column not numeric: treat as 0, round

shipping (no changes)

price (before)

price (after)

15.46

323.69

339.15

30

34.89

64.89

3.39

3.39

6.78

10.5

10.5

1

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.

  1. Take the steps from Add a rule box to add the Column Math rule box.

    Column Math
  2. In Current Field Value, select a required operation to add, subtract, multiply, or divide values in the current attribute. This operation takes place second.

    • +

    • -

    • *

    • /

  3. 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.

    • +

    • -

    • *

    • /

  4. 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.

  5. 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.

  6. Enter the allowed number of decimal places for the calculated result in Round Precision, or leave it empty to produce whole numbers.

  7. 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:

Current Field Value: +, Input Column 1: shipping, Operator: /, Input Column 2: items_in_package, Round Precision: 2

shipping (no changes)

items_in_package (no changes)

price (before)

price (after)

15.46

1

323.69

339.15

30

18

34.89

36.56

3.39

2

3.39

5.09

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:

  1. Take the steps from Add a rule box to add the Math Template rule box.

    Math Template
  2. 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.

  3. 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.

    Twig Generator
    • 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, or column3.

  4. Enter the allowed number of decimal places for the calculated result in Round Precision, or leave it empty to avoid trimming the resulting numbers.

  5. 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:

math_template_setup_example.png

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

413.6

30

8.0247

18

34.89

37

3.39

0.7797

2

3.39

5.47

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.

  1. Take the steps from Add a rule box to add the In-Row Math rule box.

    In-Row Math rule box
  2. In Delimiter, enter a character that separates numbers in your attribute values. Common delimiters are commas (,), semicolons (;), quotes (" or '), braces ({}), pipes (|), or slashes (/ or \).

  3. 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.

  4. 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

52

6,2,1,6

15

3/12,54,6

63

In the last row, you can see that the rule box ignores the number separated from other numbers with a different delimiter.