Magento 2 has no ability to order an event's obververs execution

See the events.xsd.

An event’s declaration:
https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/lib/internal/Magento/Framework/Event/etc/events.xsd#L36-L46

An observers’s subdeclaration:
https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/lib/internal/Magento/Framework/Event/etc/events.xsd#L48-L58

Why is it wrong?

For example, look at the catalog_block_product_status_display event:

https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/app/code/Magento/Catalog/Block/Product/AbstractProduct.php#L374-L379

So, an observer can set display_status to true or false, for example:
https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/app/code/Magento/CatalogInventory/Observer/DisplayProductStatusInfoObserver.php#L37-L41

If there are mutiple observers for the catalog_block_product_status_display event then the Magento 2 behavior becomes unpredictable because we can not set observer’s ordering.

https://github.com/magento/magento2/issues/2354

See also How does Magento 2 process «events.xml» configuration files?

The unalterable order is:

  • global scope observers have lower priority than other scope observers (frontend, adminhtml)
  • Observers of the same scope has priority of reverse alphabet module names order. For example, the obserers from Zzz module has priority on the the Aaa module.

I have found a workaround:

  1. Use the <sequence> tag to set the modules loading order.
  • Run setup:upgrade console command to apply the modules loading order.

Observers are applied according to the modules loading order.

1 Like