Skip to main content
added 761 characters in body
Source Link

Well,My guess after looking at the native plugins is that you should create your plugin path in youron di.xmlMagento\Catalog\Api\ProductRepositoryInterface is wronginstead.

InsteadIf you check the native plugins linked to Repository classes, almost all of them are not linked to the repository class directly but to the preference interface.

Quick example:

<type name="Magento\Customer\Api\GroupRepositoryInterface">
    <plugin name="MyListener"name="invalidatePriceIndexerOnCustomerGroup" type="MyCo\MyExt\ProductOverride"type="Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup"/>
</type>

This plugin is linked to the repository interface and the preference for this class is the repository class itself:

<preference sortOrder="1"for="Magento\Customer\Api\GroupRepositoryInterface"
            type="Magento\Customer\Model\ResourceModel\GroupRepository" />

It shouldI'm not sure if this is a restriction regarding plugins but my suggestion would be to change your code to this and try again:

<type name="Magento\Catalog\Api\ProductRepositoryInterface">
    <plugin name="MyListener" type="MyCo\MyExt\Plugin\ProductOverride" sortOrder="1" />
</type>

Assuming that your plugin class is located under app/code/MyCo/MyExt/Plugin/ProductOverride.

Well, your plugin path in your di.xml is wrong.

Instead of:

<plugin name="MyListener" type="MyCo\MyExt\ProductOverride" sortOrder="1" />

It should be:

<plugin name="MyListener" type="MyCo\MyExt\Plugin\ProductOverride" sortOrder="1" />

Assuming that your plugin class is located under app/code/MyCo/MyExt/Plugin/ProductOverride.

My guess after looking at the native plugins is that you should create your plugin on Magento\Catalog\Api\ProductRepositoryInterface instead.

If you check the native plugins linked to Repository classes, almost all of them are not linked to the repository class directly but to the preference interface.

Quick example:

<type name="Magento\Customer\Api\GroupRepositoryInterface">
    <plugin name="invalidatePriceIndexerOnCustomerGroup" type="Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup"/>
</type>

This plugin is linked to the repository interface and the preference for this class is the repository class itself:

<preference for="Magento\Customer\Api\GroupRepositoryInterface"
            type="Magento\Customer\Model\ResourceModel\GroupRepository" />

I'm not sure if this is a restriction regarding plugins but my suggestion would be to change your code to this and try again:

<type name="Magento\Catalog\Api\ProductRepositoryInterface">
    <plugin name="MyListener" type="MyCo\MyExt\Plugin\ProductOverride" sortOrder="1" />
</type>
Source Link

Well, your plugin path in your di.xml is wrong.

Instead of:

<plugin name="MyListener" type="MyCo\MyExt\ProductOverride" sortOrder="1" />

It should be:

<plugin name="MyListener" type="MyCo\MyExt\Plugin\ProductOverride" sortOrder="1" />

Assuming that your plugin class is located under app/code/MyCo/MyExt/Plugin/ProductOverride.