0

I tried to create a simple plugin (magento 2.4.3-p1) :

But when I run the compiler, I have the following error :

In PluginListGenerator.php line 326: Plugin class Fseb\ModuleA\Plugin\Catalog\Model\Product doesn't exist

Here is the code:

app\code\Fseb\ModuleA\registration.php

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Fseb_ModuleA',
    __DIR__
);

app\code\Fseb\ModuleA\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="Fseb_ModuleA" setup_version="1.1.0"/>
</config>

app\code\Fseb\ModuleA\etc\frontend\di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="Fseb_ModuleA" type="Fseb\ModuleA\Plugin\Catalog\Model\Product"/>
    </type>
</config>

app\code\Fseb\ModuleA\Plugin\Catalog\Model\Product.php

class Product
{
    public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
    {
        $title = 'lalalala';
        return $title;
    }
}

Could you help ?

2 Answers 2

0

In your Plugin, the namespace is missing.

Here is the code you should have :

<?php
namespace Fseb\ModuleA\Plugin\Catalog\Model;

class Product
{
    public function afterGetName(\Magento\Catalog\Model\Product $subject, $result)
    {
        $title = 'lalalala';
        return $title;
    }
}

Also, as told by Matt H., you should fix the config node in your di.xml file.

Note : For more informations about Plugins, here is the official doc : https://developer.adobe.com/commerce/php/development/components/plugins/

0

On your di.xml change the config to: <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

Then run setup:upgrade before setup:di:compile

Everything else seems right.

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.