0

Hi dears I want to override taxvat.phtml in vendor > magento > module-customer > view > frontend > templates > widget

Before I try to create a file Vendor > Module > etc > di.xml with this code :

<type name="Magento\Customer\Block\Widget\Name">
    <plugin name="vatcode" type="Vendor\Module\Plugin\Customer\Block\Widget\Taxvat"/>
</type>

and in Taxvat code :

namespace Vendor\Module\Plugin\Customer\Block\Widget;

use Magento\Customer\Block\Widget\Taxvat as Taxobj;

class Taxvat
{

    public function after_construct(Taxobj $result)
    {
        $result->setTemplate('Vendor_Module::widget/taxvat.phtml');
        return $result;
    }

}

after run but i have below error :

Type Error occurred when creating object: Magento\Customer\Block\Widget\Name\Interceptor, Argument 1 passed to Vendor\Module\Plugin\Customer\Block\Widget\Taxvat::after_construct() must be an instance of Magento\Customer\Block\Widget\Taxvat, instance of Magento\Customer\Block\Widget\Name\Interceptor given, called in /public_html/vendor/magento/framework/Interception/Interceptor.php on line 146

3 Answers 3

1

Use Before Plugin type for set your custom template.

public function beforeSetTemplate(\Magento\Customer\Block\Widget\Taxvat $subject, $template): array
    {
        $template = 'Vendor_Module::widget/taxvat.phtml';
        return [$template];
    }
3
  • Hi Madani I tried. shown below error : Type Error occurred when creating object: Magento\Customer\Block\Widget\Name\Interceptor, Argument 1 passed to Vendor\Module\Plugin\Customer\Block\Widget\Taxvat::beforeSetTemplate() must be an instance of Magento\Customer\Block\Widget\Taxvat, instance of Magento\Customer\Block\Widget\Name\Interceptor given, called in /public_html/vendor/magento/framework/Interception/Interceptor.php on line 121
    – Peren
    Commented Sep 23, 2022 at 9:59
  • Did you ran the magento commands ? And also make sure you defined the proper type name in di.xml for plugin. Commented Sep 23, 2022 at 11:23
  • Yes i ran this command : rm -rf pub/static/* && rm -rf var/view_preprocessed/* && bin/magento se:up && bin/magento se:stat:de -f && bin/magento c:f and i have find problem now
    – Peren
    Commented Sep 23, 2022 at 11:34
0

Your code need to like this :

class Taxvat
{
    public function after_construct(\Magento\Customer\Block\Widget\Name $subject, $result)
    {
        $result->setTemplate('Vendor_Module::widget/taxvat.phtml');
        return $result;
    }
}
1
  • Hi dhiren I tried. shown below error : Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Magento\Customer\Block\Widget\Name\Interceptor::isRequired
    – Peren
    Commented Sep 23, 2022 at 9:52
0

You can just add the taxvat.phtml file in your theme. app/design/frontend/theme_vendor/theme_name/Magento_Customer/templates/widget/taxtvat.phtml

1
  • Thank you dear wang. I need Add it in module
    – Peren
    Commented Sep 23, 2022 at 15:43

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.