How to Manage Configurable Product Gallery Switch Strategy

Would you like to replace or prepend configurable product images on visual swatch change in product detail page? Let's see how easily you can define the gallery switch strategy.

By default in magento the gallery switch strategy is set by default to replace. That means when you select a visual swatch option in configurable product detail page, the images of the configurable product are replaced with the images of the simple product that is in reference with your selection. You can find the definition of that behaviour directly in the file under vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml.

You can simply now override that default functionality be defining another gallery switch strategy in the view.xml of your custom theme. This is what exactly also the Magento's luma theme is doing setting it to prepend, meaning that the images of the simple product by the selected swatch will be prepend to the images of the configurable product. What you need is to add the following configuration in the etc/view.xml file of your theme.

Feel free to share this post and ask your questions in the comments below.

Till next time!