0

Issue: When attempting to test a plugin "after" method with $objectManager->create('Shopgate\Base\Model\Config')->startup(), the original startup() method is called but not my plugins afterStartup()

Steps Taken:

  • [✔] Confirm module enabled & loaded
  • [✔] Clear cache with magento cache:clean config
  • [✔] Empty generated code with rm -r generated/*
  • [✔] Register plugin as shown below:

In my etc/di.xml, I have the following:

<?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="Shopgate\Base\Model\Config">
        <plugin name="bugFixEnableGetSettings" type="MoninGlobal\ShopgateBugfix\Plugin\ShopgateConfig" sortOrder="9999" />
    </type>
</config>

In MoninGlobal\ShopgateBugfix\Plugin\ShopgateConfig I have:

    public function afterStartup($subject, $result){
        var_dump(get_class($subject));
        var_dump($result);

        return $result;
    }

The same occurs when using get() instead of create() on the object manager.

Any insight into what I am missing here would be greatly appreciated.

1 Answer 1

0

Despite Magento showing that the module had been loaded and enabled, my registration.php was incorrect:

Bad

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'MoninGlobal_Template', # <--- BAD REFERENCE
    __DIR__
);

Good

use \Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'MoninGlobal_ShopgateBugfix',
    __DIR__
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.