سؤال

I need to override the widget template file /vendor/magento/module-catalog/view/frontend/templates/product/widget/new/content/new_grid.phtml but in xml file the phtml file was not mentioned at any where except on /etc folder.

<parameter name="template" xsi:type="select" required="true" visible="true">
    <label translate="true">Template</label>
    <options>
        <option name="default" value="product/widget/new/content/new_grid.phtml" selected="true">
            <label translate="true">New Products Grid Template</label>
        </option>
    </options>
</parameter>

How can I override the vendor-widget-phtml file new_grid.phtml to my custom module.

هل كانت مفيدة؟

المحلول

this way i get changes of phtml by my custom module

app/code/VendorName/ModuleName/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">

    <preference for="Magento\Catalog\Block\Product\Widget\NewWidget" type="MyModule\WidgetOverride\Block\Product\Widget\NewWidget" />

</config>

app/code/VendorName/ModuleName/Block/Product/Widget/NewWidget.php

<?php
namespace MyModule\WidgetOverride\Block\Product\Widget;

class NewWidget extends \Magento\Catalog\Block\Product\Widget\NewWidget
{
  protected function _construct()
    {
      parent::_construct();
      $this->setTemplate('VendorName_ModuleName::product/widget/content/new_grid.phtml');
    }
}

now add your phtml file this path app/code/VendorName/ModuleName/view/frontend/templates/product/widget/new/content/new_grid.phtml

frontend shows my changes on product page by override phtml file

enter image description here hope this help you :) Happy coding.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top