0

This is my code but the block is not overrided

My di file :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <preference for="Magento\Directory\Block\Data" type="Vendor\Module\Block\Rewrite\Directory\Data" />    
</config>

My PHP file :

<?php

namespace Vendor\Module\Block\Rewrite\Directory;

class Data extends \Magento\Framework\View\Element\Template
{
    public function getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country')
    {
        echo "test"; exit;

    }
}
0

in your app/code/Vendor_name/MOdule_name/etc/di.xml

    <?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Directory\Block\Data" type="Vendor_name\Module_name\Block\Data" />
</config>

and in your file app/code/Vendor_name\Module_name\Block\Data.php

 <?php

namespace Vendor_name\Module_name\Block;

class Data extends \Magento\Directory\Block\Data
{
    //overrider you file here
}
?>

hope this helps if yes then up vote please

| improve this answer | |

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.