Template Functions and Syntax

Advanced formatting features for templates.

Introduction

Template functions can be used to program the template output through writing functions in the “Format” text box of the Field Properties dialog box. For example:

  • You can write a specific text for specific product families by detecting their product parentage,

  • You can do calculations such as, adding tax to the price or multiply price by 1.1

  • You can do “IF” checks and format the output accordingly.

  • You can perform actions depending on Boolean values (Which is either TRUE or FALSE)

Where to use these functions

You can use these functions while setting field properties located in Settings>Templates:

mceclip1.png

Also you can use these functions while writing Price Rules, Min and Max Price rules. Price rules are located in Channel>Channel Settings>Pricing tab:

General Programming Guidelines

Functions

Math Functions

If() Function

Comparison Operators

Then() function

Logical Operators

Count

Sum Operator

Negate

Text String Operators

Examples

Notes

 

General Programming Guidelines

There are 3 types of parameters; (1) Variables or Fields, (2) Strings and Text and (3) Functions. SA programming language allows, unlimited consecutive statements, which must be separated with “dot” (.).

E.g.:

{Product.Price}

{Product.Price.Multiply(1.2).Then ()}

 

(1) Dynamic Variable, Fields

Fields are data sources from your inventory database, and each product has all these fields assigned. Below are Dynamic Fields syntax and guidelines:

  • All Dynamic fields must be put in curly brackets {} when being referred to, e.g.: {Product.Price}.

  • Some products may not have values for these fields. These are assigned as “NULL.”

  • Some fields are Boolean, meaning only have 2 possible values; “TRUE” or “FALSE.”

  • Some fields may be number or text-specific

(2) Strings and Text

Strings are regular text that goes into the expression without any change. Strings do not require curly brackets {}.

E.g., Description or Sales

 

(3) Functions

Functions perform checks and run operations on dynamic Variables. Below are some function writing guidelines:

  • All functions must be put in Curly brackets {}, or the system won’t recognize the text as a function. E.g.: {Add(10)}

  • Once a Curly bracket is opened ({), you can write functions as many as you want; make sure to separate them with a dot (.). E.g.: If({Product.Price.GreaterThan(100)},expensive,cheap)

  • You don’t need to open multiple curly brackets when you are already in one.

  • When the function is written, make sure to Close the Curly brackets (}).

  • The general function syntax is writing the function name and open/close parenthesis “()” with some value.

  • Some functions don’t require parenthesis, below is a list of those functions:

>NULL sends null character ("NULL"),

> Space prints a space character (“ ”),

> NewLine prints a newline (“<CR, LF>”),

> Comma prints a comma character (","),

> IsNull checks if the value is null or not,

> IsTrue checks if the function returns true or not.

E.g.: Consider the following Programming Statement:

{Product.Price.GreaterThan(100).Then(NewLine)}

Here ”Product.Price” Field, and both “GreaterThan” and “Then” function was put in curly brackets and all were separated with a Dot (.); even though there were two functions and a field, only one set of Curly brackets were used.

E.g.: Consider the Following Programming Statement:

{Product.Title} Newline

{Product.Price} Space {Product.Tax} NewLine

{Product.Description}

This will produce the following Result:

Sony

$1200 10%

New Sony Product

 

Math Functions

StoreAutomator has built-in math functions to do basic calculations in statements. Math Functions always perform operations on the value on the left-hand side with the value in brackets.

Below is a list of these functions that might be useful in some cases:

 

> Add(), e.g: {Product.Price.Add(10)}, or {Price.Add(-10)},

> Multiply(), e.g: {Product.Price.Multiply(1.2)},

> Divide(), e.g: {Product.Price.Divide(2)},

> Percent(), e.g: {Product.Price.Percent(80)}

>Num(), defines a number in decimal, e.g.: {Num(3)}, returns 3.00

>RoundMoney, rounds a number using two decimals, e.g. :{Num(1.2356).RoundMoney} returns 1.23

>RoundUp, rounds a number up to an integer, e.g.: :{Num(1.2356).RoundUp} returns 2

>RoundDown, rounds a number down to an integer, e.g.: :{Num(1.2356).RoundDown} returns 1

>Min, returns the lowest of the numbers in parentheses, e.g.: {Min(1,2,3)} Returns 1

>Max, returns the highest of the number is parentheses, e.g.: {Max(1,2,3)} Returns 3

 

Multiple Math functions can be performed in a line separated by dots (.):

E.g:

Let's say you want to perform the following operation: (((Product.Price X 1.2 ) + 10 ) / 2 ) X 90 /100

this can be written as a Math expression as:

{Product.Price.Multiply(1.2).Add(10).Divide(2).Percent(90)}

 

If() Function

You can use “If()” statement to do checks and then perform actions. Basic usage is:

If(Comparison_Statement,

Then[Statements_to_be_executed_if_Comparison_statement_is_TRUE],

Else[Statements_to_be_executed_if_Comparison_statement_is_FALSE])

Or in short: If(Comparison_Statement, Then, Else)

Here “Then” expression is required, “Else” is not required. Comma usage is required after comparison statement. Called variable must be in curl Brackets ({}).

 

Basic Usage Example:

If({Product.Price.GreaterThan(100)}, expensive, cheap)

 

Result: If this particular product’s “Price” Field value is greater than 100, then it will display “expensive”, and if the field’s value is not greater than 100, then it will display “cheap”. “GreaterThan” is a Comparison Operator, and it results in either “TRUE” or “FALSE” value; “TRUE” executes the action written after the first comma (,) and “FALSE” executes the action, which is written after the second comma.

 

Comparison Operators

Comparison Operators always compares the value on its left-hand side with the value in brackets. If we look into the example above, “GreaterThan” is the comparison operator and comparing the values of the Product.Price, and 100.

Below is a list of all comparison operators in Store Automator:

> GreaterThan() – Checks and returns true, if the value on the left-hand side is greater than the value in brackets,

> GreaterThanOrEqualsTo() – Checks and returns true, if the value on the left-hand side is greater than or equal to the value in brackets,

> LessThan() – Checks and returns true, if the value on the left-hand side is less than the value in brackets,

> LessThanOrEqualsTo() – Checks and returns true, if the value on the left-hand side is less than or equal to the value in brackets,

> EqualsTo() – Checks and returns true, if the value on the left-hand side and the value in brackets are equal. EqualsTo() can be used for texts but Contains() functions is recommended for this use, see below for more information.

> Contains() - Checks if the value on the left hand side contains the value in the parentheses.

Note: “If” statement cannot nest multiple conditions in its brackets, to nest multiple conditions, please use the "Then" function.

Boolean Function Usage

“If” statement can be used with Boolean functions and Boolean fields. Boolean functions can return only two values, either “TRUE” or “FALSE”. Below example shows how a Boolean operator works:

E.g.: Consider the following Programming Statement:

 

If({Product.Name.IsNull},Product does not have a name, Product has a name)

 

Result: “IsNull” function checks if the Product’s Name is Null or not. If the function returns “True” (Meaning, yes, it is Null, this product don’t have a name), then it will display “Product does not have a name”, if the result is “FALSE” then it will display “Product has a name” on the screen. Boolean Functions returns the result; returns TRUE if the result is TRUE and FALSE if the result is FALSE.

 

Below is a list of Boolean Functions in StoreAutomator:

> IsNull – Checks and returns true, if the field or value is NULL,

> IsTrue – Checks and returns true, if the entity has a value of TRUE, or the returns TRUE,

> StartsWith() – Checks and returns true, if field starts with the expression in brackets,

>Contains() - Checks and returns true, if the field contains the text given in parenthesis.

 

Boolean fields can have “TRUE” or “FALSE” value.

 

E.g.: Consider the following Programming Statement:

 

If({Product.IsInStock}, We have this product, We do not have this Product)

 

Result: If this particular product’s “IsInStock” field has a value of “TRUE”, then it will display “We have this Product”, if the field is “FALSE”, then it will display “We do not have this Product” on the screen.

Below is a list of Boolean Fields in StoreAutomator:

> IsFba Checks if the Product’s “IsFba” field is TRUE

> IsFreeShipping – Checks if the Product’s “IsFreeshipping” field is TRUE

> IsInStock – Checks if the Product’s “IsInStock” field is TRUE

> IsLowStock – Checks if the Product’s “IsLowStock” field is TRUE

> IsNew – Checks if the Product’s “IsNew” field is TRUE

> IsOnSale – Checks if the Product’s “IsOnSale” field is TRUE

> IsParent -  Checks if the product is a parent and returns TRUE

> IsChild - Checks if the product is a Child and returns TRUE

> IsSingle - Checks if the product is a Single product and returns TRUE

> IsAlias - Checks if the product is an Alias and returns TRUE

> IsAltsku - Checks if the product is an Altsku and returns TRUE

> IsKit - Checks if the product is a Kit product and returns TRUE

> Discontinued – Checks if the Product’s “Discontinued” field is TRUE

> FastListingEnabled – Checks if the Product’s “FastListingEnabled” field is TRUE

 

StoreAutomator recognizes the following values as FALSE:

> NULL character,

> If the field is a number type field, the number Zero (0), (all other numbers return True),

> If the field is a string type field, empty string(“”), (all other characters return True).

 

Then Function

Then Function checks the condition written on the left-hand side and executes the statement in brackets. Basic usage is:

Condition_Statement.Then(Then, Else)

 

Condition Statement is checked and, if returned “True” then the system executes the code in the first part of the brackets (Then part), if returned “False” then the system executes the code in the second part of the brackets (Else Part). Similar to IF() function, Then the part is required, and Else is not.

 

E.g.: Consider the following Programming Statement:

 

{Product.Sku.StartsWith(FBA-CAN).Then({Product.FbaFee},0)}

Result: Function checks if the Product.SKU starts with “FBA-CAN,” if returned “True” then Product’s FbaFee Value is written on the screen. If returned “False” then “0” is written.

 

Multiple statements can be logically checked using And or Or functions, written before “Then” and the statement in brackets will be executed.

E.g.: Consider the following Programming Statement:

 

Condition_1.And(Condition_2).And(Condition_3).Then(then, else)

Condition_1.Or(Condition_2).OR(Condition_3).Then(then, else)

 

Result: This syntax will display all data in the “Bullet Points” array one by one as a list of bullet points with a Dot in the front.

 

Other Logical Operators

Not()

Not, takes the inverse of a boolean value, Basic Usage is:

Not(Field_Value)

Not (Boolean_Function)

 

E.g.: Consider the following Programming Statement:

 

{Not(Product.IsOnSale).Then(Product is not on sale)}

 

Result: If the Product is not actually on sale, so IsOnSale value = False, taking NOT of False is TRUE, so the condition becomes TRUE, and then the function will perform the action after “Then” and display “Product is not on sale” on screen; If the Product is actually on sale(Not of IsOnSale=FALSE), then Do nothing; “Then” function doesn’t require the second part.

 

Any()

Any checks if any fields are having a value as “True” is a list. Any returns TRUE if at least one variable in the list is “TRUE” and the rest have value ”False”. Basic Usage is:

Any(Value_a,Value_b,Value_c,…)

 

E.g.: Consider the following Programming Statement:

 

{Any(Product.IsInStock,Product.IsNew, Product.IsOnSale)}

 

Result: Let’s say these fields have the following values:

IsInStock= True

IsNew= False

IsOnSale= False

There is one True value so that the result will be “True”

 

All()

All checks if all values being “True” or not, in a list. All returns “False”, even if there is just one “False” and the rest have a value of “True”, in the list is. Basic Usage is:

All(Value_a,Value_b,Value_c,…)

 

E.g.: Consider the following Programming Statement:

 

{All(Product.IsInStock,Product.IsNew, Product.IsOnSale)}

 

There are two “False” values so that the result will be “False”

Let’s say these fields have the following value:

IsInStock= True

IsNew= True

IsOnSale= True

All Values are True so that the result will be “True”.

 

And()

And function performs logical AND between all values. Basic usage:

{Field_Value1.And({Field_Value1}).And({Field_Value2}).And({Field_Value3})…

 

E.g.: Consider the following Programming Statement:

 

{Product.IsNew.And({Product.IsInStock}).And({Product.IsOnSale})}

 

Result: Values of below fields taken from above:

IsInStock= True

IsNew= False

IsOnSale= False

AND of these values will be “False”.

 

Or()

Or Function performs logical OR for all objects in a list. Basic usage:

{Field_Value1.Or({Field_Value1}).Or({Field_Value2}).Or({Field_Value3})…

E.g.: Consider the following Programming Statement:

 

{Product.IsNew.Or({Product.IsInStock}).Or({Product.IsOnSale})}

 

Result: Values of below fields taken from above:

IsInStock= True

IsNew= False

IsOnSale= False

Or of these values will be “True”.

 

Length

Length returns the number of characters in a field or value.

E.g.: consider a field: bullet-point-10 has a value of: "sold separately for continental US"

Product.CustomField[bullet-point-10].Lenght

Result: 35

 

Count

Count function counts the number of objects in an array object. An array object can store multiple text fields, in double quotes (") that are separated by commas (,). ["test 1 2 3 !","$23.99"] In this array example first field is "test 1 2 3 !" and the second field is "$23.99".

Basic usage:

Field_Variable.Count

E.g.: Consider the following Programming Statement:

Product.Url.Count

Result: 2, it means there are 2 entries in the URL object, stored as an array.

 

Result: Code counts the number of characters in the Url field and returns the number.

 

Sum

Sum function adds all objects’ value together. It is similar to the add function. Sum operates on values on the right-hand side, while Add adds two values, one left-hand side and one in right-hand side brackets. Basic usage:

Sum(Field_1, Field_2, Field_3,…)

E.g.: Consider the following Programming Statement:

 

Sum({Product.Quantity},{Product.SaleCount})

 

This adds these two fields’ value together and returns.

 

Negate

Negate function takes the inverse of the value. It is similar to Not operator. Negate operates on the left-hand side value, while NOT operates on the brackets' value on the right-hand side. Basic usage:

Field.Negate

E.g.: Consider the following Programming Statement:

 

{Product.IsFba.Negate}

 

Let’s say IsFba = False

The result of this statement will be: True.

 

String/Text Operators

Concat()

Concat() function adds text one after other.

E.g.: Consider the following Programming Statement:

 

If({Product.IsChild},Concat({Product.CustomFields[amazon-title]}, Size: ,{Product.GetOptionNameByType(size)}), {Product.FullName})

 

Result: if product is a child product, combine the texts in fields “amazon-title”, size, get the Option Name value info of the field “Size" and write on the screen; if not just write the Product’s full name on screen.

Output: Good Dress Size: 34

 

List()

List defines an array and include provided parameters in it.

E.g.: List(1,2,3,4), returns {1 2 3 4}

E.g.: List(1,2,3,4).Sum, returns 10

 

Str()

Str returns a joined new string of the provided parameters.

E.g.: Str({Product.Name}, ,{Product.Price}, ,dollars) returns Tony Television 999 dollars

 

Includes()

This function returns a Boolean value if the parameter given in "includes" function, is included in the initial field defined.

E.g.: LIST(alex,jane,richard,mark).INCLUDES(jane)

Result: Includes function checks if "jane" is included in the initial list which is (alex,jane,richard,mark), and the result is yes it is included, so the function returns TRUE.

 

E.g.: STR(Length returns the number of characters in a field or value).INCLUDES(number)

Result: This example shows how to use includes functions with STR (string) function. Includes function checks if "number" is included in the initial string "Length returns the number of characters in a field or value", and the result is yes it is included, so the function returns TRUE.

 

Join()

This command joins the members of an array with the parameter provided. The first parameter is the joining parameter, following parameters are the words to be joined. Default joining parameter is comma (,).

E.g.: LIST(a,b,c).JOIN(-) result: a-b-c

E.g.: Join (-,a,b,c,d) result: a-b-c-d

 

Split()

Split is used to split strings as per provided parameters. The first parameter is the splitting parameter. Split can be used for splitting characters or words in a text.

E.g.: SPLIT(-,a-b-c-d-e-f).COUNT Result: 6

E.g.: SPLIT(**,It is a long established** fact that a to reader will be distracted by the readable content of a page when looking at its layout. The point of **using Lorem Ipsum is that to it has a more-or-less normal **distribution of letters as opposed to using)[2]

Result: using Lorem Ipsum is that to it has a more-or-less normal

 

ToAlphaNumeric

This function removes any non alpha numeric characters from the string. 

e.g.: STR(a-c-*da/123 4asde).TOALPHANUMERIC

Result: acda1234asde

 

ToLowercase

ToLowercase function converts the text into lowercase letters.

E.g.: Product.CustomFields[gender].ToLowercase

Result: convert the values in "gender" custom field to lower case characters.

MALE ->male

 

ToUppercase

ToUppercase function converts the text into uppercase letters.

E.g.: Product.CustomFields[gender].ToUppercase

Result: Male -> MALE

 

ToCamelCase

Camel Case function converts the text into camel-case letters.

E.g.: Product.CustomFields[gender].CamelCase

Result: testcamelcase -> TestCamelCase

 

ToProperCase

ProperCase function converts the text into proper case letters, which is using uppercase letter for every word.

E.g.: Product.CustomFields[gender].ProperCase

Result: test proper case -> Test Proper Case.

 

ToUrl

ToUrl function converts the text into a Url.

E.g.: Product.CustomFields[url-address].ToLowercase

Result: if content of url-address custom field is storeautomator.com, then the result would be: http://www.storeautomator.com

 

Trim

Trim removes invisible characters from the beginning and the end of any text, such as space, enter, <CR>, <LF>, \n.

E.g.: Product.CustomFields[care-instructions].Trim

Result: Wash Instructions:/n

            machine wash

-> Wash Instructions: machine wash

 

StripHtml

This statement will strip any HTML formatting from the text and send. It is used to  remove HTML markings from descriptions.

E.g.: Product.Description.StripHtml

Result: <p> <b> Example Text </b></p>

-> Example Text

 

SimpleHtml

This statement will convert detailed HTML formatting to a simpler HTML formatting that all market places accept. It is used to simplify HTML formatting from descriptions.

E.g.: Product.Description.SimpleHtml

Result: <p> <b> Example Text </b></p>

-> <p> <b> Example Text </b></p>

 

FixSpaces

This function will reduce excessive spacings from strings.

E.g.: STR(abcd efgh).FIXSPACES

Result: 9

 

RemoveSpaces

This function removes all space characters from the sentence and make it one word.

E.g.: STR(Lorem Ipsum is).REMOVESPACES

Result: LoremIpsumis

 

String Character sending functions

EmptyStr sends empty String to the channel, Usage: {EmtpyStr}

Null or NULL sends null character ("NULL"), Usage: {NULL}

Space or SPACE prints a space character (“ ”), Usage: {SPACE}

NewLine prints a newline (“<CR, LF>”), Usage: {NewLine}

Comma or COMMA prints a comma character (","), Usage: {COMMA}

IsNull checks if the value is null or not.

 


Examples:

Detecting FBA status

To make the FBA Fee work, you should mark your product as FBA. Then the system collects FBA fees for that product. FbaFee in our system refers to TotalFbaFees-ReferralFee.

Product.Price.Add({Product.Sku.StartsWith(FBA-CAN).Then({Product.FbaFee},0)})

 

If you mark your products as FBA, then that statement becomes:

Product.Price.Add({Product.IsFba.Then({Product.FbaFee},0)})

OR:

If({Product.Cost.Multiply(1.5).Add({Product.ShipCost}).LessThan({Product.Msrp})},{Product.Msrp},{Product.Cost.Multiply(1.5).Add({Product.ShipCost})})

 

Detecting a products Parentage

– To detect the product’s parentage use: Product.IsParent

This will return True or False. True being The product is parent

– StoreAutomator has three product properties for this. IsParent, IsChild and IsSingle. You can use like below:

If(Product.IsParent, parent, noparent)

Or there is another form you can use, which might be more readable

Product.IsParent.Then(parent,noparent)

 

Detecting Product dimensions

Below statement detects  if there is a value in PackageLenght and if there is sends it:

If({Product.PackageLength.GreaterThan(0)},{Product.PackageLength})

 

Sending Custom Fields

To send data from custom fields you cans imply choose from the searchbox or if you are writing manually, make sure to include the custom field name in brackets ("[" and "]"):

Product.CustomFields[amazon-manufacturer]

 

Sending Array type Data

To send Array type data, the target filed must be array type, then you can select as many sources as you like and make sure to select "combine fields into array" option at the top right corner. A good example of array type remote field can be Shopify's "tags" field:

mceclip0.png

 

Sending Bullet Points

Array type field's first item is in index number 0. Below expression sends bullet_point_1:

Product.Tags.BulletPoints[0]

 in this case you must include all bullets points that you want to send.

 

Below expression sends all bullet points or Target Audience :

Product.Tags.BulletPoints
Product.Tags.TargetAudience

You must also select "Repeat" from array options and mark "Skip Empty" in Advanced tab.

 

mceclip1.png

Sending StoreAutomator Option type

Below expression sends product's color, e.g. red, green, blue, etc...:

Product.GetOptionNameByType(Color)

Result -> Red

 

Below expression checks if the OptionType contains color and sytle:

If({Product.OptionType.Contains(Color).And({Product.OptionType.Contains(Style)})},


Sending Amazon current update Method

Below expression sends the Current Internal Amazon update method:
Product.CIAmazonUpdateMethod
Result -> Update OR Delete


How to Send NULL Character

Below expression sends NULL:

{NULL}

Result -> NULL

 

How to send Local Category Group Name

Below expression  sends the StoreAutomator Local category group name:

Product.CategoryGroup[category].Select(Name)

Result -> T-Shirts

 

How to check a product's parentage

Below expression checks if a product is single and if it is single, it sends Null.

 

If({Product.Parentage.EqualsTo(Single)},{Null})

 


Notes:

1- To use these expressions in an If clause, They must be placed in braces ("{","}")"

E.g.:

If({Product.OptionType.Contains(Color)},Yes, No)

Notice that the dynamic field is in braces.

2- All optional fields must be sent with "Skip empty" option to prevent problems due to empty values. Skip empty option is located in "advanced" Tab.

Was this article helpful?

0 out of 0 found this helpful