Modifying attribute values and using Formulas

As you have noticed, almost every product attribute can be accessed in export templates or dynamic attributes with an expression like {attr:attribute_code}. In this section we will explain, how you can modify attribute values or make some manipulation with them.

Retrieving the N-th element of an Array

Some attributes can have multiple values (for example one product can be assigned to multiple categories). Depending on your Export profile template, our app will automatically select first category or do some needed modifications.

However, if you use the static file export (CSV / XML / JSON), you can set to export only the N-th category. If attribute is not array (for example string, integer), it will skip modification.

Here are a few examples:

{attr:categories|[0]} - will return the first element of and array
{attr:names|[english]} - you can get array element by key
{attr:names|[en]|[label]} - multidimensional arrays are also supported

Serialization to JSON

{attr:categories|json} - if Categories value is array, then this modifier will convert it to JSON string

Value type conversion

Wise2Sync mainly holds two types of supplier attributes: numeric and text. You can switch between types like this:

{attr:qty|txt} - Typecast conversion to String |txt. Value will be converted to String type
{attr:qty|int} - Typecast conversion to Int |int. Value will be converted to Int type
{attr:length|float} - Typecast conversion to Float |float[:precision]. For example {attr:length|float:2} will convert Length value to Float type with precision of 2.

Examples

Volume#1 Product volume. Lets say, you want to calculate total product volume in cubic meters, when you supplier only provides with, height, and length in centimeters.

What you do is create a dynamic attribute with type "number" and set a value expression:

{attr:length|float}/100 * {attr:height|float}/100 * {attr:width|float}/100


#2 Custom product name. Lets say you would like to have have custom product names, which would include product Category label as a prefix. So, what you would do is create a textual dynamic attribute "Custom Name" and set its value as follows:

{attr:lab_val_category|[0]} - {attr:name}

So if your product name was "Funny Sunshine 101" and it belongs to a category "Eye Glasses", then product "Custom name" would be "Eye Glasses - Funny Sunshine 101".

Support across the Wise2Sync App
Type Expression Example Dynamic Attributes Export profile Templates Repricing Rules
Array element value |[n] {attr:category|[0]} Yes Yes No
Array serialization to JSON |json {attr:tags|json} Yes Yes No
Value type conversion |txt, |int, |float[:precision] {attr:length|float:2} Yes Yes No
Numeric operators ceil(..), floor(..), round(..), abs(..) ceil({attr:length|float}) Yes Yes Yes
Find lowest / highest value min(..), max(..) min({attr:price}, 0) Yes Yes Yes
Current Date {date:format} {date:Y-m-d} Yes Yes No

 


Revision #13
Created Thu, Jan 14, 2021 2:11 PM by Liudas
Updated Thu, Jan 28, 2021 7:59 PM by Liudas