Calculated Attributes

📘

Support

Technical skills are required to create an expression using Symfony syntax.

For assistance with setting up this feature, please contact your integration partner.


Overview

Calculated attributes are dynamic attributes automatically generated from a formula. They can be added to product sheets, asset sheets, or variants.

A calculated attribute:

  • Appears grayed out on the sheet,
  • Is identified by a sigma symbol Σ on the sheet,
  • Is a non-localized and non-editable attribute,
  • Is not affected by attribute sets; their configuration has no impact on the calculation result.

A sheet may contain several calculated attributes, and each calculated formula can include as many attributes as needed.



Accessing Calculated Attribute Settings

Calculated attributes are a type of attribute and can be found in the attribute administration page, accessible from the Attributes page under the Administration menu.

To add a calculated attribute, select an object from the Object type dropdown list.

  • Then click the last level of the tree where you want to create the new attribute.
  • Click the Add attribute button in the attribute management block.
  • Fill in the following information:
    • Attribute name (non-localized)
    • Code
  • Select the Calculated attribute type.


Entering a Formula

A calculated attribute is based on a formula you define directly in the Calculated formula field.

In a formula, attributes are referenced by their code.

The formula syntax is based on PHP syntax (see the Symfony expression documentation).

A calculated attribute formula can combine one or more attributes from the same product sheet using mathematical operators (+, -, *, /) and functions such as concatenation, average, and many others:

  • roundup() -> Rounds away from 0
  • rounddown() -> Rounds toward 0
  • ceiling() -> Rounds up to the nearest value
  • average() -> average
  • concat() -> concatenation
  • condition ? value if true : value if false

📘

Good to know

  • The result of a calculated attribute is always a text value.
  • In a function, an attribute code is always enclosed in double colons ::

🚧

Limitations

You cannot use in the formula:

  • another calculated attribute
  • any attribute if it is localized
  • an attribute of HTML or JSON type
  • attributes from another object type

❗️

Error Handling

  • If the formula is invalid, creation is blocked and an error message is displayed.
  • In case of division by zero or other inconsistency, an error message is shown on the product sheet.
  • If one of the formula’s attributes is missing, an exclamation mark appears next to the calculated attribute. Hovering over it shows the list of impacted attributes.

Example Calculated Attribute Formulas

  • Text concatenation:

Goal: Concatenate the text values of attributes, separated by a space.

Attribute codeValue
attr_code_AHello
attr_code_BWorld
attr_code_CQuable

Formula: concat(::attr_code_A::," ",::attr_code_B::," ",::attr_code_C::)

Result: Hello World Quable


  • Average of values:

Goal: Calculate the average of the attribute values.

Attribute codeValue
attr_code_A3
attr_code_B4.14
attr_code_C1

Formula: average(::attr_code_A::,::attr_code_B::,::attr_code_C::)

Result: 2.713


  • Sum of values:

Goal: Calculate the sum of the attribute values.

Attribute codeValue
attr_code_A3
attr_code_B4.14
attr_code_C1

Formula: attr_code_A+attr_code_B+attr_code_C

Result: 8.14


  • Conditional logic:

Goal: If the attribute is <0, display A. If <2, display B. If <10, display C. If <18, display D. Otherwise, display E.

Attribute codeValue
attr_code_A3

Formula: ::attr_code_A:: < 0 ? "A" : ( ::attr_code_A:: <= 2 ? "B" : ( ::attr_code_A:: <= 10 ? "C" : (::attr_code_A:: <= 18 ? "D" : "E" ) ) )

Result: C


Automatic Calculation

A calculated attribute is automatically updated when:

  • One of the values used in the formula is modified,
  • The formula itself is modified,
  • A mass action is applied to the relevant sheets.

🚧

Limitations

  • All attributes used in the formula must be enriched for the calculation to succeed.
  • A calculated attribute cannot be imported into a data model or updated via the API. Formula creation and editing must be done exclusively via the front-end interface.
  • A calculated attribute cannot be made mandatory or edited directly from a product sheet.
  • You cannot delete an attribute that is used in one or more calculated attribute formulas. You must first manually remove it from all related formulas.

Apply Settings

Once all settings are configured, use the “Add” button to save your changes.



Best Practices

  • Document formulas in the help field to ease maintenance, making them visible through the help text.
  • Result on the product sheet: