Skip to main content
1 of 3
Tu Van
  • 7.8k
  • 2
  • 14
  • 24

The correct answer is A.

The sortOrder property from the plugin node declared in di.xml determines the plugin's prioritization when more than one plugin is observing the same method.

The Magento\Framework\Interception\PluginListInterface which is implemented by Magento\Framework\Interception\PluginList\PluginList is responsible to define when to call the before, around, or after methods respecting this prioritization.

If two or more plugins have the same sortOrder value or do not specify it, the component load order declared in the sequence node from module.xml and area will define the merge sequence. Check the component load order in app/etc/config.php file.

The application executes plugins using these rules during each plugin execution in two main flows:

  • Before the execution of the observed method, starting from lowest to highest sortOrder.
    • The application executes the current plugin’s before method.
    • Then the current plugin's around method is called.
      • The first part of the plugin's around method is executed.
      • The around method executes the callable.
        • If there is another plugin in the chain, all subsequent plugins are wrapped in an independent sequence loop and the execution starts another flow.
        • If the current plugin is the last in the chain, the observed method is executed.
      • The second part of the around method is executed.
    • The application moves on to the next plugin.
  • Following the execution flow, starting from lowest to highest sortOrder in the current sequence plugins loop.
    • The current plugin's after method is executed.
    • The application moves on to the next plugin.

As a result of these rules, the execution flow of an observed method is affected not only by the prioritization of the plugins, but also by their implemented methods.

You can read more about Prioritizing plugins and many scenarios from the official document: https://developer.adobe.com/commerce/php/development/components/plugins/#prioritizing-plugins

You also can write code and test it in your Magento project.

Tu Van
  • 7.8k
  • 2
  • 14
  • 24