O'Reilly logo

Magento 2 Developer's Guide by Branko Ajzele

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The plugin sort order

Looking back, when we defined a plugin in the di.xml file, one of the attributes that we set for every plugin definition was sortOrder. It was set to 100, 200 to 300 for foggyPlugin1, foggyPlugin2 and foggyPlugin3 respectively.

The flow of the code execution for the preceding plugins is as follows:

  • Plugin1 - beforeGetAddToCartUrl
  • Plugin1 - aroundGetAddToCartUrl
  • Plugin2 - beforeGetAddToCartUrl
  • Plugin2 - aroundGetAddToCartUrl
  • Plugin3 - beforeGetAddToCartUrl
  • Plugin3 - aroundGetAddToCartUrl
  • Plugin3 - afterGetAddToCartUrl
  • Plugin2 - afterGetAddToCartUrl
  • Plugin1 - afterGetAddToCartUrl

In other words, if multiple plugins are listening to the same method, the following execution order is used:

  • The before plugin functions with the lowest sortOrder ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required