Template Functions and Syntax

Article author
Store Automator
  • Updated

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:

 

 

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

Concatenate Operator

 

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 paranthesis, below is a list of those functions:

> Space prints a space character (“ ”),

> EmptyStr prints empty string (“”),

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

> 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)}

 

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.

 

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

> “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 “IsOnSal”e field is 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.

 

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

 

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

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

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

Result: testcamelcase -> TestCamelCase

 

ToProperCase

ToProperCase function converts the text into proper case letters.

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

Result: test camel case -> Test camel case.

 

ToUrl

ToUrl function converts the text into a Url.

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

Result: storeautomator.com -> 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

 

Examples:

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)})

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

 

E.g., 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)

Was this article helpful?

0 out of 0 found this helpful