I am trying to override product view controller and display a message on top by following this tutorial

The message is not shown in product page and there is no error as well. Below are the code. Please advise.


<?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="Company_Custom" setup_version="1.0.0" >
            <module name="Magento_Catalog"/>


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Controller\Product\View">
    <plugin name="company-custom" type="Company\Custom\Controller\Catalog\Product\View" sortOrder="10"/>


namespace Company\Custom\Controller\Catalog\Product;

class View extends \Magento\Catalog\Controller\Product\View
    public function execute()
        echo "Local controller";
        $this->messageManager->addSuccess('Message from new controller.');      
        return parent::execute();
  • 3
    It looks to me like you are not following the tutorial you mention. You are mixing preferences with plugins.
    – Marius
    Jun 6 '16 at 6:26

In di.xml

Instead of plugin ,preference needs to be used     

<preference for="Magento\Catalog\Controller\Product\View" type="Company\Custom\Controller\Catalog\Product\View" />

you are wrong step 3:

Step:3 Overriding xml file
File path: magento2\app\code\Jute\Customer\etc\di.xml enter image description here

<?xml version=”1.0″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd”>
<preference for=”Magento\Customer\Block\Address\Book” type=”Jute\Customer\Block\Address\Book” />
<preference for=”Magento\Customer\Controller\Address\Index” type=”Jute\Customer\Controller\Address\Index” />

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.