I want override Block Magento\Catalog\Block\Product\View\Gallery
this is code in file di.xml
Edited
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<preference for="Magento\Catalog\Block\Product\View\Gallery" type="Xyaddons\Productzoom\Block\Product\View\Gallery" />
</config>
Code file Gallery.php
namespace Xyaddons\Productzoom\Block\Product\View;
use Magento\Framework\View\Element\Template;
class Gallery extends \Magento\Catalog\Block\Product\View\Gallery
{
protected function _toHtml()
{
$this->setModuleName($this->extractModuleName('Magento\Catalog\Block\Product\View\Gallery'));
return parent::_toHtml();
}
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_scopeConfig;
/**
* Template image only
*
* @var string
*/
protected $_templateImage = 'Xyaddons_Productzoom::product/image.phtml';
protected function _prepareLayout()
{
$this->getLayout()->createBlock('Xyaddons\Productzoom\Block\Product\View\Gallery', 'xyaddons.productzoom')->setTemplate('Xyaddons_Productzoom::produtc/image.phtml');}
}
when run code don't running image.phtml and not override Block Magento\Catalog\Block\Product\View\Gallery. What wrong?
Best Answer
Did you removed cache?
Why your extended class
\Magento\Catalog\Block\Product\Gallery
but try override\Magento\Catalog\Block\Product\View\Gallery
? (I think you have error in classfor
in preferences)Why you don't rewrite block
<block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="product/view/gallery.phtml"/>
and try override class?