How to use sync modifiers

Learn how to use modifiers.

Overview

Modifiers is a powerful tool that allows you to change the product data after the sync without the need to get a developer to make changes in the data-feed.

It supports the following commands.

CommandEffect
setAdds an attribute to all products
deleteRemoves an attribute on all products
updateUpdate an attribute on all products
typeChanges the type of an attribute on all products
expressionEvaluates an expression in an attribute
formatFormats a string in an attribute

All commands also supports the if clause. The if clause can be added to anything with a statement, and the command will only be run on the attribute if the statement evaluates to true.

Examples

Here are examples for each of the commands, with variables as needed. All commands take a type that specifies what command to run, and an attribute that indicates what attribute to run the command on.

Set

Takes a new_value that shows what value to set the attribute to, can be used both as a new attribute, or on top of an existing one to replace it.

{
  'type':'set'
  'attribute': ATTRIBUTE
  'new_value': NEW_VALUE
}

Delete

Deletes the given attribute from all products.

{
  'type':'delete'
  'attribute': ATTRIBUTE
}

Update

If you are non-technical and you are reading this. Strap in because we are using regex with the python library.

Update takes the attribute regexp that is a regex expression that matches on some parts of the attribute and replaces each matched group with the content of replace_by. Here’s a helpfull tool for you to craft your regex.

An example regex could be [/]+ with a replace_by of ’/’, this would take all places in the attribute that has multiple /’s in a row and replace them with singular /. So https://test//tests would become https:/test/tests.

{
  'type':'update'
  'attribute': ATTRIBUTE
  'regexp': MATCH_REGEX
  'replace_by': STRING
}

Type

Allow for changing of types in an attribute. So if the data is a number and you need it to be a string, you can use this to typecast it.

{
  'type':'type'
  'attribute': ATTRIBUTE
  'new_type': any of ['string', 'int', 'float', 'boolean']
}

Format

Allows for formatting of attribute strings. The attribute inside would likely already have a formattable string, most likely made by you with either set or update. But this allows for dynamic entries of other parts of the product data into this attribute.

This could be starting with adding {currency} at the end of the price attribute with an update and then calling this will add whatever is in the products attribute currency onto the price.

If the needed data is not an attribute on the product, you can also add the extra attribute to the command.

{
  'type':'format'
  'attribute': ATTRIBUTE,
  ... : ... #(can include more attributes that are needed for formating)
}

Expression

Evaluates an expression that is in the given attribute. For instance, if there’s the string ‘price * 0.8’ inside an attribute and we run expression on it, the result will be 80% of what is in the price attribute.

{
  'type':'expression'
  'attribute': ATTRIBUTE
}

If

If if is added to any of the above commands with a statement, the command will only run on attributes where the given statement evaluates to true.

{
  'type':'delete'
  'attribute': ATTRIBUTE,
  'if':'price < 200'
}

Multi modification example

Here’s an example of multiple modifications chained together. Here I’m making a new attribute called price_alt that takes both the price and currency and make a new field with them.

[{
  'type':'set',
  'attribute':'price_alt',
  'new_value':"{proce}{currency}"
},{
  'type':'update',
  'attribute':'price_alt',
  'regexp':"o",
  'replace_by':"i"
},{
  'type':'format',
  'attribute':'price_alt',
  'currency':"DKK"
}]

This would make a new field called price_alt with the price and DKK at the end.