1

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 ?

2

2 Answers 2

0

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.

-1

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

app/design/frontend/<Vendor>/<Theme>/etc/view.xml
3
  • he clearly mentioned that he want to use it in custom module not a theme brother. so please remove your answer. Commented Sep 26, 2019 at 15:20
  • i see it not possible to do it from app/code, never seen something like that or read it. Commented Sep 26, 2019 at 15:28
  • i know that it's not possible to do so we can close this question if want answer as you suggest then magento.stackexchange.com/questions/144518/… Commented Sep 26, 2019 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.