productImage

function, since version 1.0.0
categories: image, product, prestashop

productImage(imageId, name, [type])

returns url to product image. Function respects prestashop Friendly URL settings.

parameters

return type:

string

examples

productImage(product.imageId, product.friendlyUrl)
productImage(product.imageId, 'product-'+product.id+'-'+product.friendlyUrl)
productImage(product.imageId, 'img', 3)

if Friendly URL are enabled

https://www.domain.com/13/printed-summer-dress.jpg
https://www.domain.com/13/product-100-printed-summer-dress.jpg
https://www.domain.com/13-medium_default/img.jpg

if Friendly URL are disabled:

https://www.domain.com/img/p/1/3/13.jpg
https://www.domain.com/img/p/1/3/13.jpg
https://www.domain.com/img/p/1/3/13-medium_default.jpg

advanced example

Image file names can help us with our SEO efforts. By default, image file names are based on friendlyURL field of associated product, so all images of the same product will have the same suffix. Although images in PrestaShop don’t have their own friendlyURL field, they have caption / label field.

We would like to use this legend field as image filename. It can contain any characters so we need to sanitize its value – we allow only alphanumeric characters, anything else will be replaced by dash. This field can also be empty – in that case, we want to fallback to friendlyUrl field.

productImage(image.id,coalesce(allowedChars(image.legend,'a-zA-Z0-9','-'),image.friendlyUrl))

Related functions:

Update your privacy settings