Plugins vs Observers in Magento 2

In short, plugins are everywhere since it is possible to modify/replace behavior of any public method in the system.

On the other hand, observers is legacy extension mechanism inherited from Magento 1, it is very limited. so, it is better to avoid them.

For plugins, Customization should be done using plugins for public methods/classes marked with @api annotation whenever possible. Otherwise, you don’t take any guarantees that customization will stay functional after new Magento releases. In addition to before/afterplugins mentioned in the question, it is possible to create around plugins to substitute original behavior.

The conclusion is use plugins whenever possible, then observers, this will allow you to avoid conflicts with other extensions(3rd party modules.)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s