0

I am trying to override Magento\Catalog\Block\Widget\Link with Anshu\Custom\Block\Catalog\Widget\Link but it is not working.
Anshu/Custom/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\Catalog\Block\Widget\Link" type="Anshu\Custom\Block\Catalog\Widget\Link" />
</config>


Anshu/Custom/Block/Catalog/Widget/Link.php

<?php

namespace Anshu\Custom\Block\Catalog\Widget;

class Link extends \Magento\Catalog\Block\Widget\Link
{

    public function getHref()
    {
        exit('test');
    }

}


Anshu/Custom/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Anshu_Custom" setup_version="1.0.0">
    </module>
</config>


Anshu/Custom/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Anshu_Custom',
    __DIR__
);

It would be helpful, if any one can explain me what I am doing wrong here.

  • have you checked your custom module entry in setup_module table ? – Aasim Goriya Oct 26 '17 at 13:14
  • @AasimGoriya yes custom module entry is there in the setup_module table. – Anshu Mishra Oct 27 '17 at 5:12
  • Please try with move module.xml in Anshu/Custom/etc/frontend/module.xml and check again – Aasim Goriya Oct 27 '17 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.