0

I've been battling with this one for a while but can't figure out how to disable, in order to override, a plugin in the Amasty Shop by extension. I need to override a couple of methods in the plugin, but as they're set to private and use private variables declared within the class, I think I have to just disable that specific plugin and override it with my own.

The issue I have is that the plugin doesn't appear to be declared/named in the di.xml files present in the extension, but there are some additional plugins in the extension which extend it, and these plugins are named in di.xml.

The plugin I am trying to override is here: vendor/amasty/shopby/Plugin/Ajax/Ajax.php

There are 2 plugins (in the same directory as the above) which extend it, and are named in vendor/amasty/shopby/etc/frontend/di.xml as below:

<type name="Magento\Catalog\Controller\Category\View">
        <plugin name="Amasty_Shopby::ajaxInject" type="Amasty\Shopby\Plugin\Ajax\CategoryViewAjax"/>
    </type>

I've created and registered my module, and my attempt to disable and override the plugin is as follows:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Amasty\Shopby\Plugin\Ajax\Ajax">
        <plugin name="Amasty\Shopby\Plugin\Ajax\Ajax" disabled="true" />
        <plugin name="my_ajax" type="MyNamespace\Shopby\Plugin\Ajax\Ajax" />
    </type>
</config>

It's likely I'm missing something obvious here, grateful for any pointers in the right direction.

0

Your di.xml code is wrong.

Why

Amasty\Shopby\Plugin\Ajax\CategoryViewAjax is plugin type and it is plugin of Magento\Catalog\Controller\Category\View. Amasty_Shopby::ajaxInject is plugin name.

A plugin Type is disabled by Plugin name means Amasty_Shopby::ajaxInject not plugin Type Amasty\Shopby\Plugin\Ajax\CategoryViewAjax.

Also, <type name="Amasty\Shopby\Plugin\Ajax\Ajax"> is wrong it should be <type name="Magento\Catalog\Controller\Category\View">

So, your di.xml will be

<?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\Category\View">
        <plugin name="Amasty_Shopby::ajaxInject" disabled="true" />
        <plugin name="my_ajax" type="MyNamespace\Shopby\Plugin\Ajax\Ajax" />
    </type>
</config>

Also, make your MyNamespace_Shopby should depend on Amasty_Shopby.

So, you have to modify your module.xml like:

<?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="MyNamespace_Shopby"  setup_version="1.0.1">
        <sequence>
            <module name="Amasty_Shopby"/>
        </sequence>
    </module>
</config>
| improve this answer | |

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.