Performing operations on numbers
To perform a condition or operation using a number in the system rules, you need to first verify if our field is indeed a numeric field.
Numeric field has a specific format, i.e. it consists of numeric characters with a decimal separator in the form of a "." - dot.
Below are a few examples of incorrect numbers:
10,99
10 000.99
10,000.99
10.99 USD
The correct number is:
10000.99
We can verify our data in two places
1) In the "Items" tab after going to the specific product tab, we see all the assigned fields. We look for the field that is important to us and check what value it represents. Below is an example:
2) Directly in the rule after enabling the test mode, we see hints in conditions and operations. Below is an example:
In the given examples, we will refer to the "price" field. As you can see, the field represents the value "69.95 PLN". Therefore, it is not a numerical field. To perform numerical operations on it, we need to correct the field value by removing " PLN", which will result in the value "69.95", which is a number.
So we add the rule "Replace price with a number". The rule will be applied to all products. So:
IF
All elements
THEN
TAKE "price" and "Replace value" " PLN" "
It should look like this:
As you can see, if we have "Test mode" enabled, we immediately see how the applied operation will affect our value. "Results" is the result after applying the "Replace value" operation.
At this point, in the "price" field, we have the value "69.95" which is a numerical value. So we can condition the next rule based on it. For example, we will want to decrease the "price" value by 10% for products that are more expensive than 50.00.
We add another rule, which we will name "Decrease price for products more expensive than 50" (it is important to maintain the order of rules, as they are executed sequentially, the rule "Convert price to a number" should be executed before the rule "Decrease price for products more expensive than 50"). The rule will look as follows:
IF
"price" "number" "greater than" "50"
THEN
TAKE "price" "calculate value" use "price" Multiply by "0.9"
It will look like this:
It should be emphasized here that in the conditions we should choose the "Number" group. "Greater than" appears in both the "Number" group and the "Text" group, but their operation is completely different. The "Text" group and the "Greater than" condition will compare character by character, but we want to compare numbers.
In the Operation in the "Results" we can see the result of the "price" (69.95) multiplied by "0.9", which is "62.96".
Currently, for all products more expensive than "50.00", the value of "price" has been reduced by 10%.
So we have the expected result. However, since we removed " PLN" from the "price" field, which our product file format requires "price" to contain " PLN", we need to add another rule that will append this value to the modified "price" field.
So we add another rule "Add PLN" (it should be placed after the two rules described above).
IF
All elements
THEN
TAKE "price" and "Append value" " PLN"
Example:
After executing the three rules above, we have successfully fulfilled our assumption. The result we will obtain for this example product is: "62.96 PLN" and this result will be passed to the product file we are working on.
As we can see, this relatively simple operation required us to be familiar with our data, understand numerical conditions and operators, and execute the rules in the established sequence.