Variables

In this post, we will learn:

Introduction

In the MERGADO Editor, you may have encountered a situation where you need to create a placeholder component for all values of a specific element of different products in a rule. That’s what variables are for.

image

What are variables?

Variables in the MERGADO Editor represent placeholders for specific values from elements. For example, if we have a PRICE_VAT element in the feed, which contains the final price of the product with VAT, this price can be different for each product. The PRICE_VAT element therefore contains (across products) a variable numerical value, which we can generally call a variable. So the variable can have a different value for each product in the feed.

Example: We want to build a product name from multiple elements with different values and we want the name to contain:

  • manufacturer,
  • original product name used on the e-shop
  • and a parameter expressing the size of the product.

We create a rewriting rule, where we fill in PRODUCTNAME in the field for the element and write the following 3 variables in the field New content:

  • %MANUFACTURER%
  • %PRODUCTNAME%
  • %PARAM_SIZE%

After applying such a rule, the specific name of the product will be compiled for us in the form, for example: Adidas Men’s sports shirt XXL.

:information_source:  MERGADO 2 already uses the element itself to represent the value and therefore no longer automatically creates all variables from your feed elements like MERGADO 1. However, it still allows you to create new variables if needed. The complete management and overview of variables can be found in the left menu under the link Variables.

Variable creation procedure

We add a new variable to the MERGADO Editor by clicking the New variable button on the Variables page and then:

  1. We choose the element from which the variable will be based.
  2. Enter regular expression, which represents a mask for selecting text from the given element.
  3. In the Test text field we will see a randomly selected value from the element we selected. By clicking on the double arrow icon we can change the test text or enter your own text in the field if necessary.
  4. We click on the Test expression button.
  5. If we are not satisfied with the result of our regular expression mask, we can modify the regular expression and test its application on the sample data again.
  6. Once we are satisfied with the regular expression, we save the specific part (or parts) of the text corresponding to our regular expression in variables, just enter their name and click on the Save variable button.

:bulb: We also recommend regex101.com for testing regular expressions.

Examples

Users with variables most often set a new value in some element (using rules). Variables are also used to separate a part of (variable) text from some element.