I have created a plugin in my custom module to override the default method getName() in Magento\Catalog\Model\Product.php

I've created my custom module named Firstmodule inside app\code\Magento. I am using the after listener of plugins.

The file app\code\Magento\Firstmodule\etc\frontend\di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="Magento_Firstmodule::before" type="Magento\Firstmodule\Model\Basic" sortOrder="1" />

And the Model app\code\Magento\Firstmodule\Model\Basic.php

namespace Magento\Firstmodule\Model;

class Plugin {

    public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
        return '|' . $result . '|';

Still there is no result on the frontend product view page.

Can anyone tell me what is missing.? thanks in advance.


You have specified a type of Magento\Firstmodule\Model\Basic but called the class 'Plugin' in your Basic.php file. It needs to be

class Basic {

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.