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

Returns a sanitized ID from the current category.

Template compatibility: item group

Input

None

Examples

$getCategoryId()
=> '42'

$getProductId

Returns a sanitized ID from the current product.

Template compatibility: item

Input

None

Examples

$getProductId()
=> '42'

$getVariantId

Returns a sanitized ID from the current variant.

Template compatibility: variation and grouping

Input

None

Examples

$getVariantId()
=> '42'

$getImageUrl

Returns the main image URL of the current product or variant.

Template compatibility: item, variation, and grouping

Input

None

Examples

$getImageUrl()
=> 'https://example.com/image.jpg'

$getProductUrl

Returns the main URL of the current product.

Template compatibility: item, variation, and grouping

Input

None

Examples

$getProductUrl()
=> 'https://example.com/product-slug'

$getItemKeywords

Returns the keywords of the current product.

Template compatibility: item

Input

None

Examples

$getItemKeywords()
=> ['clothing', 't-shirts']

$getAttributeValue

Extracts 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 centAmount field.
  • Enum: will return the value of the key field.
  • Reference: will return the value of the id field.
  • Set: will return an array of the values on each key field.
  • 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, andgrouping

Input

An attribute name, a locale (optional)

Examples

$getAttributeValue('price')
=> 4200

$getAttributeValue('color', 'fr-FR')
=> 'bleue'