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?

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__);
    }
}
  • 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 Mar 8 '17 at 13:28
  • How can i use it now? @var $block \Vendor\Module\Block\Product\View\GalleryXY in phtml? – Huzur Polat Mar 8 '17 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. – gelanivishal Mar 8 '17 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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