Conditions (in the element path)

In this post, we will learn:

What are conditions?

The conditions in element path are a filter that allows us to filter values and their elements within a given path. They are written in curly brackets { } and bound to the element to the left of them. In conditions, you can filter only through the elements nested within the element to which the conditions bind.

A few examples you may have come across:

  1. image
  2. image
  3. image

:information_source:   The curly brackets { } are typed as follows on the Czech and Slovak keyboards: left bracket using right Alt + B or Option + í (Mac) and right bracket using right Alt + N or Option + é (Mac).
On the English keyboard they are typed as follows: left bracket using Shift + [ and right bracket using Shift + ].

Let’s explain the conditions with an example. Let’s have the following data:

image

…i.e. with element structure such that the PARAM element is the parent and the PARAM_NAME and VAL elements are its children. And let’s have the path from the first image in the introduction: PARAM { PARAM_NAME = "Color" } | VAL. In this path, the condition is { PARAM_NAME = "Color" }. This condition binds to the parent PARAM element and is specified via the nested PARAM_NAME element (which is also a child of the PARAM element).

7c922120018878fdad64ffb1c7fd7bf914b2b7fa

This path with condition reads sequentially from left to right like this:
Take a PARAM element whose underlying PARAM_NAME element has a value equal to Color, and in such a PARAM element, target its child VAL.

ezgif.com-gif-maker

And if we break down the process into steps, it looks like this:

  1. We take the (multi-value) parent element PARAM…
    path reading: Screenshot from 2023-06-06 09-40-50

1

  1. …whose nested PARAM_NAME element has the value Color…
    path reading: Screenshot from 2023-06-06 09-40-57

2

  1. …and in such a PARAM element we target the (multiple) VAL element.
    path reading: Screenshot from 2023-06-06 09-41-02

3

So the PARAM { PARAM_NAME = "Color" } | VAL path filters and targets only those VAL elements that have PARAM_NAME elements with Color as sibling.

What are the conditions for?

ezgif-4-09100b9b24

As we mentioned earlier, the conditions in the element path are a filter. The conditions refine the specified path and allow you to target a more specific subset of the element’s values.

Let’s take an example:
Consider a product with parameters Size, Color, Material, and Gender. Let’s say we want to override Size from the original value of “XXL” to “M”. How do we do it? We know that we target the parameter values using the PARAM | VAL path, which is a path without a condition:

3 (copy)

Well yeah, but we only want to override (target) the value “XXL” for the Size parameter. The conditions will help us to do that! The conditioned path then looks like this:

PARAM { PARAM_NAME = "Size" } | VAL

original (copy)

Conditions are only worth using for multi-value elements. You can use conditions for simple elements too, but it misses the point of the element’s simplicity - such elements have only one value, so there is no reason and nothing to filter from.

:information_source:  In MERGADO 1, conditions didn’t exist and couldn’t be worked with, as there were no multi-value elements or element structure in that version.

Correct condition notation

Let’s have a path PARAM { PARAM_NAME = "Color" } | VAL. The basic template for writing a condition is:

Screenshot from 2023-06-08 07-49-39

:bulb: Spaces are important and can’t be left out! Both spaces in the condition itself and spaces before and after the condition.

The content of the condition resembles the query form for custom MQL query. The first image from the introduction is from the same place.

And it’s no coincidence. In fact, we can type absolutely anything into the conditions of an MQL query. This opens up a world of incredible possibilities. For example, an MQL query for the values of the variant parameters Size and Material

goes into the path condition that targets the store name

VARIANTS | VARIANT { PARAMETERS | PARAMETER { NAME = "Size" } | VALUE = "M" AND PARAMETERS | PARAMETER { NAME = "Material" } | VALUE = "Cotton" } | STOCK | WAREHOUSES | WAREHOUSE | NAME

By defining the condition, only variants whose value of the Size parameter is M and at the same time the value of the Material parameter is Cotton are filtered out. In this example, we see that there can be other conditions and operators in one condition and that we can work with arbitrarily nested elements.

:information_source:  There are conditions in the element path and conditions in MQL. Meaningfully, they are two different things, even though they are called the same. A condition in the element path starts and ends with curly brackets { } and a condition in MQL consists of 3 parts. There can be multiple MQL conditions in an element path condition.

Screenshot from 2023-06-06 10-24-55

What if an element has no children?

In the What are conditions? section, we said that conditions are bound to the parent element and that in conditions you can only work with nested elements. What if an element has no children and no nested elements? Can conditions be used for such elements as well? Yes, they can.

There are special attributes @@POSITION and @@VALUE (we will add more in the future). These attributes are also bound to the element and can therefore be used in conditions.

Let’s give an example:
Let’s have the following data:

image

We have a multi-value IMGURL_ALTERNATIVE element with 3 values. How do we target its second value?

image

The answer is the third image from introduction:

image

After the element, just type a condition with the special attribute @@POSITION = 2 and such a path will only target the IMGURL_ALTERNATIVE element whose position is two.

Another way may be to use the special attribute @@VALUE:

image

which filters out only IMGURL_ALTERNATIVE elements that have a value equal to https://picsum.photos/400/300. However, this method of targeting the second value works only if the element does not take the value multiple times. Otherwise, the path targets all such values, i.e. not just the second value.

Most common uses

In general, conditions can be applied to any element (and especially multi-value elements). In this section, we will give some examples that we have encountered in practice. For clarity, we mark the condition in yellow in the examples.

1. Parameters and deliveries

Clearly the most common use of conditions is for parameters and deliveries. We have been working with one such example throughout this post:

PARAM{ PARAM_NAME = "Color" } | VAL

This is a path that targets the value of the parameter Color, with elements from Heureka format specification or Zboží. Similar paths for other formats:

  • Shoptet: TEXT_PROPERTIES | TEXT_PROPERTY { NAME = "Color" } | VALUE
  • Shoptet, filtering parameters: INFORMATION_PARAMETERS | INFORMATION_PARAMETER { NAME = "Color" } | VALUE
  • Google: g:product_detail { g:attribute_name = "Color" } | g:attribute_value

For delivery, e.g. a path is used to target a price for a particular carrier:

DELIVERY { DELIVERY_ID = "PPL" } | DELIVERY_PRICE_COD

:bulb: Parameters and deliveries are whisperable in the MERGADO Editor.

image

2. Variants

Since there are usually more variants and we want to work with variants efficiently and effectively, we cannot avoid using conditions. Usually we will want to target some specific variants.
For example, a variant whose some element takes on some particular value. We gave one example in the Correct condition notation section.

VARIANTS | VARIANT { PARAMETERS | PARAMETER { NAME = "Size" } | VALUE = "M" AND PARAMETERS | PARAMETER { NAME = "Material" } | VALUE = "Cotton" } | STOCK | WAREHOUSES | WAREHOUSE | NAME

:information_source:  Some users also use a special @@POSITION attribute to target specific variants.

3. Image URLs and categories

Some products may have multiple images. To target a specific image or group of images, use @@POSITION or @@VALUE and the appropriate operators. We gave one example in What if an element has no children?, other examples include

  • IMGURL_ALTERNATIVE { @@POSITION >= 3 }
  • IMGURL_ALTERNATIVE { @@POSITION >= 3 AND @@POSITION <= 8 }
  • IMGURL_ALTERNATIVE { @@VALUE != "https://picsum.photos/400/300" }

Less often, but it does happen, products can have multiple categories, e.g. the Shoptet format does.

If we want to target a specific category, or group of categories, we again use @@POSITION or @@VALUE and the appropriate operators for them. For example:

  • CATEGORIES | CATEGORY { @@POSITION < 3 }
  • CATEGORIES | CATEGORY { @@VALUE NOT CONTAINS "Playgrounds" }

Summary

  • What are conditions?
    Conditions in path to an element are a filter that allows us to filter values and their elements within a given path. They are written in curly brackets { } and are bound to the element to the left of them. In conditions, you can only filter through the nested elements in the element to which the conditions are bound.

  • What are conditions for?
    Conditions refine the specified path, allowing you to target a more specific subset of the element’s values.

  • How do you write conditions correctly?
    Let’s have a path PARAM { PARAM_NAME = "Color" } | VAL. The basic template for writing a condition is:
     
    Screenshot from 2023-06-08 07-49-39

  • What if an element has no children?
    Even for such elements you can use conditions. There are special attributes that are bound to the element and can be used in conditions.

  • Most common uses
    The most common use of conditions in an element path is when working with parameters, deliveries, variants, categories, and image URLs.