1

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

Simon Buryat
  • 15
  • 1
  • 7

1 Answers1

0

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.

scrowler
  • 24,273
  • 9
  • 60
  • 92
  • Thanks! I will try and let u know! Are u good at commerce js? I might have another question re image gallery. How would u create a grid image gallery? Not all libraries work in react 18 – Simon Buryat Nov 08 '22 at 04:36