Commercetools helper functions
You can use the helper functions listed below when developing templates for use with our commercetools connector.
Please note that some functions are only compatible with certain template types.
$getCategoryId
$getCategoryIdReturns a sanitized ID from the current category.
Template compatibility: item group
Input
None
Examples
$getCategoryId()
=> '42'$getProductId
$getProductIdReturns a sanitized ID from the current product.
Template compatibility: item
Input
None
Examples
$getProductId()
=> '42'$getVariantId
$getVariantIdReturns a sanitized ID from the current variant.
Template compatibility: variation.
Input
None
Examples
$getVariantId()
=> '42'$getImageUrl
$getImageUrlReturns the main image URL of the current product or variant.
Template compatibility: item, variation.
Input
None
Examples
$getImageUrl()
=> 'https://example.com/image.jpg'$getProductUrl
$getProductUrlReturns the main URL of the current product.
Template compatibility: item, variation.
Input
None
Examples
$getProductUrl()
=> 'https://example.com/product-slug'$getItemKeywords
$getItemKeywordsReturns the keywords of the current product.
Template compatibility: item
Input
None
Examples
$getItemKeywords()
=> ['clothing', 't-shirts']$getAttributeValue
$getAttributeValueExtracts the value from a custom attribute of the current product. Takes the attribute name as the first argument, and a locale as an optional second argument.
The attribute value will be parsed and extracted according to its type in commercetools:
- Money: will return the value of the
centAmountfield. - Enum: will return the value of the
keyfield. - Reference: will return the value of the
idfield. - Set: will return an array of the values on each
keyfield. - Localized text: will return the value under the specified locale.
- Otherwise, it will return the raw value for all other types.
Template compatibility: item, variation.
Input
An attribute name, a locale (optional)
Examples
$getAttributeValue('price')
=> 4200
$getAttributeValue('color', 'fr-FR')
=> 'bleue'Updated 30 days ago