1

I create new Block Xyaddons\Productzoom\Block\Product\View\Gallery override Block \Magento\Catalog\Block\Product\View\Gallery. I want set template image.phtml in Xyaddons_Productzoom::product/image.phtml override template product/view/base-image.phtml in core. I try create function in block new Block. But i not success. so any help me? thank so much!

public function beforeToHtml(\Magento\Catalog\Block\Product\Gallery $originalBlock) {       
        $originalBlock->setTemplate('Xyaddons_Productzoom::produtc/image.phtml');
    }
3
  • what is the error ? Commented Nov 4, 2015 at 5:02
  • it don't run template Xyaddons_Productzoom::produtc/image.phtml
    – xanka
    Commented Nov 4, 2015 at 5:24
  • I'm assuming "produtc" is a typo?
    – Andy Myers
    Commented Dec 11, 2016 at 20:37

2 Answers 2

2
<referenceBlock name="catalog_product_gallery">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Xyaddons_Productzoom::produtc/image.phtml</argument>
    </action>
</referenceBlock>
2

In your function, Template path spelling mistake.

public function beforeToHtml(\Magento\Catalog\Block\Product\Gallery $originalBlock) {       
        $originalBlock->setTemplate('Xyaddons_Productzoom::produtc/image.phtml');
    }

check directory path spelling mistake produtc/image.phtml instead of product/image.phtml.

Check folder name with product not produtc and try again.

Moreover, you have to define the plugin in the di.xml file of your module

<type name="\Magento\Catalog\Block\Product\Gallery">
    <plugin name="xyaddons-productzoom-product-gallery" type="Xyaddons\Productzoom\Block\Product\View\Gallery" sortOrder="10"/>
</type>

Thanks.

1
  • Template path is true. but code don't run to function beforeToHtml().
    – xanka
    Commented Nov 4, 2015 at 6:51

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.