1

I try to override the \Magento\Catalog\Block\Product\View\Gallery in my module.

I added the below line to my di.xml file for override above block

<preference for="Magento\Catalog\Block\Product\View\Gallery" type="Vendor\Module\Block\Product\View\GalleryXY" />

and I create the GalleryXY.php file and override methods but it does not work.

<?php 
namespace Vendor\Module\Block\Product\View;
class GalleryXY extends \Magento\Catalog\Block\Product\View\Gallery{
public function doDebugg() {
 return 'blub';
 }
 }
?>

can anyone help me on this?

Bilal Usean
10.2k14 gold badges77 silver badges126 bronze badges
asked Mar 8, 2017 at 13:13

1 Answer 1

0

Please try this

<?php 
namespace Vendor\Module\Block\Product\View;
class GalleryXY extends \Magento\Catalog\Block\Product\View\Gallery{
 public function getGalleryImages() {
 die(__METHOD__);
 }
}
answered Mar 8, 2017 at 13:25
3
  • in gallery.phtml file the declation of $block i have to change or? to /app/design/frontend/Wallstyle/wsdefault/Magento_Catalog/templates/product/view/gallery.phtml /** * Product media data template * * @var $block \Magento\Catalog\Block\Product\View\Gallery */ Commented Mar 8, 2017 at 13:28
  • How can i use it now? @var $block \Vendor\Module\Block\Product\View\GalleryXY in phtml? Commented Mar 8, 2017 at 13:47
  • After override Block class, $block->getGalleryImages() this function first call from override Vendor\Module\Block\Product\View\GalleryXY class, if method is not in this class then method call from magento core class. Commented Mar 8, 2017 at 15:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.