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
1 Answer 1
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
gelanivishal
1,3461 gold badge12 silver badges25 bronze badges
-
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 */Huzur Polat– Huzur Polat2017年03月08日 13:28:19 +00:00Commented Mar 8, 2017 at 13:28
-
How can i use it now? @var $block \Vendor\Module\Block\Product\View\GalleryXY in phtml?Huzur Polat– Huzur Polat2017年03月08日 13:47:07 +00:00Commented Mar 8, 2017 at 13:47
-
After override Block class,
$block->getGalleryImages()this function first call from overrideVendor\Module\Block\Product\View\GalleryXYclass, if method is not in this class then method call from magento core class.gelanivishal– gelanivishal2017年03月08日 15:42:25 +00:00Commented Mar 8, 2017 at 15:42
default