Question

I'm having trouble creating a plugin to execute an around interception on a shipping configuration file.

Running on version M2.0.7

Here's the excerpt from my di.xml file showing the class I wish to intercept

<type name="Magento\Shipping\Model\Config\Source\AllMethods">
    <plugin name="allmethodsplugin"
        type="Somevendor\Somemodule\Plugin\Shipping\AllMethodsPlugin"
        sortOrder="1"
        disabled="false"/>
</type>

Below is an excerpt from my AllMethodsPlugin file showing the method I wish to intercept via the "around" mechanism

namespace Somevendor\Somemodule\Plugin\Shipping;

class AllMethodsPlugin
{

...

public function aroundToOptionArray(\Magento\Shipping\Model\Config\Source\AllMethods $subject, \Closure $proceed)
{
    $result = $proceed();
    //do some custom processing here
    return $result
}

It appears this interception is ignored.

I can see from stepping through the code that the configuration is loaded from my di.xml file and I have other working plugins configured in the same file. I can't see any errors in my configuration but welcome to any feedback here.

I don't see any generated class for the AllMethods class, which makes me suspect there is a config error here or it is ignored for interceptors.

I can work around this using argument replacement for the AllMethods variable passed into the calling class. However, I would like to know if this is in fact a limitation in M2?

Was it helpful?

Solution

It looks like you're trying to intercept the class

Magento\Shipping\Model\Config\Source\AllMethods

However, Magento doesn't have a class by that name. You may be thinking of the class

Magento\Shipping\Model\Config\Source\Allmethods

Notice the lowercase m in methods. Give that a try instead and you should be good to go (or at least moving on the the next problem)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top