sello #
Syntax: sello [string] = [string];
The Sello function is at the core of Sift. This is used to assign a value to a field in Sello. The available fields can be found at the mapping settings page in Sello. Values can be assigned in multiple ways:
This example will set the sku
field in Sello to the webshop-sku
field in your webshop.
sello "sku" = src("webshop-sku");
This example will define a function and use it’s value as the sku
field in Sello.
fn mySku() {
return "my-cool-sku";
}
sello "sku" = mySku();
You can use arithmetics, for example:
sello "price" = 10 + number(src("webshop-price"));
src() #
Syntax: src(string)
sello "sku" = src("webshop-sku");
The src()
function is used to reference the value of a field in your system. For example, if you have a field called webshop-sku
in your system and it has the value “ABC”, the above expression will set the sku
field to “ABC”.
contains() #
Syntax: contains(string, string)
Example:
fn getPrice() {
if (contains(src("title"), "expensive")) {
return 20;
} else {
return 10;
}
}
sello "price" = getPrice();
This example creates a function called getPrice, it checks the “title” field in your system if it contains the string “expensive”. If it does, it will set the price to 20, otherwise it will set the price to 10.
convertCurrency() #
Syntax: convertCurrency(fromCurrency, toCurrency, value)
Convert value
from currency specified as fromCurrency
to currency specified as toCurrency
. Currency rates are updated daily from ECB (European Central Bank)
Example:
let price = convertCurrency("EUR", "USD", 10);
If the currency difference between EUR and USD would be 1.2, price in the above example would be set to 12.
len() #
Syntax: len(string or array)
If argument is a string, this function will return the length of that string. If the argument is an array, this function will return the length of that array.
Example:
let testA = len("test"); // 4
let testB = len([1, 2, 3]); // 3
trim() #
Syntax: trim(string)
Removes spaces before and after a string.
Example:
let str = " my string ";
sello "private name" = trim(str); // "my string"
number() #
Syntax: number(string)
Convert a string to number. This is required when you want to do math on a source field.
Example:
sello "price" = number(src("webshop-price")) * 1.5;
The above example will take the field “webshop-price” in your system, multiply it with 1.5 and assign it as the value for “price” in Sello.
split() #
Syntax: split(string, string)
Split a string into pieces.
Example:
let mystring = "foo,bar,baz";
let things = split(mystring, ","); // Split by comma
sello "private name" = mystring[0]; // foo
sello "sku" = mystring[1]; // bar
push() #
Syntax: push(array, item)
Use this function to add an item to an array.
Example:
let things = [1, 2, 3];
push(things, 4); // things is now 1, 2, 3, 4
stripHtml() #
Syntax: stripHtml(string)
Remove HTML from a string.
replace() #
Syntax: replace(haystack, needle, newtext)
Replace a string (needle) in a string (haystack) with newtext.
Example:
let name = "My cool name";
let newName = replace(name, "cool", "awesome"); // My awesome name"
regex() #
Syntax: regex(haystack, regexp)
Perform a regular expression on string “haystack”. The function will return falsey if no match. If the regex contains capture groups, an array will be returned with the matches.
Example:
let mystring = "I like cats and dogs";
let matches = regex(mystring, "I like (.+?) and (.+?)");
// matches[0] now is "cats"
// matches[0] now is "dogs"
To search in a string with newlines, add flag (?s) to your regex string. Like:
let matches = regex(mystring, "(?s)I like (.+?) and (.+?)");
regexReplace() #
Syntax: regex(haystack, regexp, replaceWith)
Replace in string “haystack” using regular expression “regexp” with “replaceWith”.
Example:
// Numbers in sku will be replaced by A
sello "private name" = sello "private name" = regexReplace(src("sku"), "[0-9]", "A");
regexFirstMatch() #
Syntax: regexFirstMatch(haystack, regexp)
This function behaves the same as regex() with the exception that it will return a string instead of array. If the regex doesn’t match, it will return an empty string. If it matches and has a capture group, that value will be returned.
Example:
let mystring = "I like cats and dogs";
sello "private name" = regexFirstMatch(mystring, "I like (.+?) and (.+?)");
In this example “private name” will be set to “cats”.
To search in a string with newlines, add flag (?s) to your regex string. Like:
sello "private name" = regexFirstMatch(mystring, "(?s)I like (.+?) and (.+?)");
round() #
Syntax: round(number)
Round a number to nearest full integer.
Example:
let nr1 = round(1.1); // will round to 1
let nr2 = round(1.7); // will round to 2
splitMaterial() #
Syntax: splitMaterial(materialProp, materialPercentageProp, text)
This function is useful for fashion merchants. Marketplaces often wants you to specify your materials and percentages as separate attributes, but you usually only have a string with combined materials and examples.
For example, you might have the string “80% cotton, 20% polyester” and this needs to be transformed into ZalandoMaterial1, ZalandoMaterial2, ZalandoMaterialPercentage1, ZalandoMaterialPercentage2. This function will do that for you.
Example:
let mymaterial = "80% cotton, 20% polyester";
splitMaterial("ZalandoMaterial", "ZalandoMaterialPercentage", mymaterial);
The above example will set these attributes and values for you: ZalandoMaterial1 = cotton ZalandoMaterialPercentage1 = 80 ZalandoMaterial2 = polyester ZalandoMaterialPercentage2 = 20