How to get all gallery images collection of the product Magento 2?

You can Retrieve the list of gallery image entries associated with given product by SKU value in Magento 2.

Using the ProductAttributeMediaGalleryManagement Interface, You can use getList($sku) method to achieve the all the media entry for the product.

Result will be array of the images with details of image path, position, type assigned like small thumbnail or swatch, label and id.

You can get the all the images assigned to the product, Iterate over a loop to the gallery array to fetch the specific image details.

Take a SKU from the Native Sample data Product, 24-MB03

Output:

You can see the result of the images as array with all the details.

2 Replies to “How to get all gallery images collection of the product Magento 2?”

Leave a Reply