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. As it is currently an exprerimental tool, only the internal clerk staff can use it for now. So please contact support if you need this functionality.
It supports the following commands.
Command | Effect |
---|---|
set | Adds an attribute to all products |
delete | Removes an attribute on all products |
update | Update an attribute on all products |
type | Changes the type of an attribute on all products |
split | Split a string by separator, into a list of strings. |
expression | Evaluates an expression in an attribute |
format | Formats a string in an attribute |
lower | Formats a string to all lowercase characters |
upper | Formats a string to all upper characters |
capitalize | Formats a string to title casing with first character uppercased |
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.
Commands #
Here are each of the commands with an example, 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
}
Example In this example I will overwrite the ‘shown’ attribute if the product is out of stock.
{
"type": "set",
"attribute": "shown",
"new_value": "false",
"if": "stock < 1"
}
Before #
{
"id": 153,
"name": "Lineman Chute",
"stock" : 0,
"shown" : true,
"price": 200.00,
}
After #
{
"id": 153,
"name": "Lineman Chute",
"stock" : 0,
"shown" : false,
"price": 200.00,
}
Delete #
Deletes the given attribute from all products.
{
"type":"delete",
"attribute": ATTRIBUTE
}
Example Here I will remove the shown attribute for all products.
{
"type":"delete",
"attribute": "shown"
}
Before #
{
"id": 153,
"name": "Lineman Chute",
"shown": true,
"price": 200.00,
}
After #
{
"id": 153,
"name": "Lineman Chute",
"price": 200.00,
}
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 helpful 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",
}
Example Here I will remove a part of the url, with a regex that maches the last part of the url, making sure to escape the /.
{
"type":"update",
"attribute": "url",
"regexp": "\/\/__example",
"replace_by": ""
}
Before #
{
"id": 153,
"name": "Lineman Chute",
"url": "https://example.domain/product/153//__example",
"price": 200.00
}
After #
{
"id": 153,
"name": "Lineman Chute",
"url": "https://example.domain/product/153",
"price": 200.00
}
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"]
}
Example Here we are changing the type of the price, from a string into a float.
{
"type":"type",
"attribute": "price",
"new_type": "float"
}
Before #
{
"id": 153,
"name": "Lineman Chute",
"price": "200",
}
After #
{
"id": 153,
"name": "Lineman Chute",
"price": 200.00,
}
Split #
Allows for splitting a string by a separator, into a list of strings. Defaults to splitting by comma if no separator is given.
{
"type":"split",
"attribute": "ATTRIBUTE",
"separator": "STRING"
}
Example Here we are splitting an attribute with categories.
{
"type":"split",
"attribute": "string_categories"
}
Before #
{
"id": 153,
"name": "Lineman Chute",
"string_categories": "lineman, chute"
}
After #
{
"id": 153,
"name": "Lineman Chute",
"string_categories":["lineman","chute"]
}
Format #
Allows for creation of a formatted string.
This could be making a new value valled {price} {currency}.
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,
"new_value": VALUE_TO_SET,
... : ... #(can include more attributes that are needed for formating)
}
Example Here I will add a currency to the end of the price, first I’ll need to change the type to a string, then inject the formatted syntax, and then I’ll get it to format. The update command adds the value in replace_by to the end of price.
[
{
"type":"format",
"attribute": "price_with_currency",
"new_value": "{price} {currency}"
}
]
Before #
{
"id": 153,
"name": "Lineman Chute",
"currency": "DKK",
"price": 200.00,
}
After #
{
"id": 153,
"name": "Lineman Chute",
"currency": "DKK",
"price": 200.00,
"price_with_currency": "200.00 DKK"
}
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",
"new_value": NEW_VALUE,
"attribute": ATTRIBUTE
}
Example 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": "price_alt",
"new_value": "price * 0.65"
}
]
Before #
{
"id": 153,
"name": "Lineman Chute",
"price": 200.00,
}
After #
{
"id": 153,
"name": "Lineman Chute",
"price": 200.00,
"price_alt": "130.0",
}
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.
Available operators are:
Operator | Meaning |
---|---|
= | Match all products where the attribute is equal to value. |
!= | Match all products where the attribute is not equal to value. |
> | Match all products where the attribute is greater than value. |
>= | Match all products where the attribute is greater than or equal to value. |
< | Match all products where the attribute is less than value. |
in | Match a substring in a string or an element in a list |
When comparing an attribute to a specific value, the syntax is:
{
"type":"delete"
"attribute": ATTRIBUTE,
"if":"ATTRIBUTE OPERATOR VALUE"
}
When evaluating a substring in a string or an element in a list the syntax is:
{
"type":"delete"
"attribute": ATTRIBUTE,
"if":"VALUE in ATTRIBUTE"
}
Example Comparing to a specific value
{
"type": "set",
"attribute": "shown",
"new_value": "false",
"if": "stock < 1"
}
Example Checking a substring
{
"type": "set",
"attribute": "shown",
"new_value": "false",
"if": "'withdrawn' in name"
}
if statements can be also grouped using ‘and’/‘or’ in statements:
{
"type": "set",
"attribute": "shown",
"new_value": "false",
"if": "(stock < 1 and 'withdrawn' in name) or brand = 'Nike'"
}
Combinations #
Here’s an example of multiple modifications chained together. Here I’m making a new attribute called price_alt for a specific product. It takes both the price and currency and make a new field with them.
[{
"type":"set",
"attribute":"price_alt",
"new_value":"{price}{currency}",
"if":"id == 153"
},{
"type":"update",
"attribute":"price_alt",
"regexp":"o",
"replace_by":"i",
"if":"id == 153"
},{
"type":"format",
"attribute":"price_alt",
"currency":"DKK",
"if":"id == 153"
}]
This would make a new field called price_alt with the price and DKK at the end.
Before #
{
"id": 153,
"name": "Lineman Chute",
"price": 200.00,
}
After #
{
"id": 153,
"name": "Lineman Chute",
"price": 200.00,
"price_alt": "200.00DKK"
}