Question

I would like to override or extend some of gallery setting(view.xml) and catalog image size changes with my custom module.

I have tried to override in app/code/<vendor>/<module>/etc/view.xml, but not working.

How can I override etc/view.xml in custom module ?

No correct solution

OTHER TIPS

The doc will show you how to override elements at a class, block, layout or template level. For the product gallery in particular and if you need your changes to be in a module, there are a few options:

  • Theme: override the theme you need to customise from a custom child theme, where you can do whatever you want with a custom view.xml file definition.

  • Template: override vendor/magento/module-catalog/view/frontend/templates/product/gallery.phtml in your custom module.

  • Class: override Magento\Catalog\Block\Product\Gallery block class in your custom module.

If you want to alter the product images before they are displayed, you can retrieve the gallery images using $galleryImages = $product->getMediaGalleryImages() on a product instance.

If you want to (programmatically) go deeper than overriding the product gallery block class, you will have to consider using Magento 2 plugins. They allow you to define "before", "after", and "around" hooks that can help you alter the core logic.

Optionally or alternatively, your custom module can implement CSS and JS files that alter the gallery aspect or behaviour on a UI level, after page load.

You must do the override in app/design directory and not in app/code

app/design/frontend/<Vendor>/<Theme>/etc/view.xml
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top