Fetching images gallery of 1 product in Commerce.js

189 Views Asked by At

Please, tell me how can i fetch all images of 1 individual product in commerce js. Cant find anything in documentation.

So, i have a single product, but instead of uploading just 1 photo, I uploaded 20. I can only get the very first photo to be displayed. Is there a way to list all 20? There must be a way since commercejs allows more than 1 photo to be uploaded there [thats images of my product][1]

Thanks! [1]: https://i.stack.imgur.com/Z0eZA.png

1

There are 1 best solutions below

1
scrowler On

You can use the assets list on a product object, see docs here: https://commercejs.com/docs/api/#get-product. You could filter them by is_image if you have other assets attached that aren't images.

const productImages = product.assets.filter((asset) => asset.is_image)

The image object only returns the main image, whereas assets will return the rest.