Instagram

About Me

Photo Profile
Meetanshi Architecture Designer

Meetanshi is found based on providing the best Magento Extensions and Customized eCommerce Business Solutions perfected to the users’ needs. Our Happy users make us Happy. Complete satisfaction to our clients is what drives and motivates us to work hard. Read More

Sunday, May 22, 2022

How to Create Plugin in Magento 2

A plugin or interceptor can be defined as a way of inserting code dynamically without making any changes in the original class behaviour. Facilitates extending the core functionalities without making any changes in the core files. 



Magento 2 comes with interceptors and plugins. In this method, I will tell you how to use, its restrictions, types and the method to create plugin in Magento 2

Reasons to Use Interceptors or Plugins in Magento 2

  • The change in the behaviour of same class or method is because of minimum conflicts among extensions. 

  • With the help of sort order attribute plugin, make sure that collisions are avoided between the plugins. 

  • Ensure that the plugin is called sequentially as per the sort order and so the conflict with other plugins is avoided.

  • Facilitates to customize the similar method in different modules.

  • Can easily change the return value of any method call that can be used on an object manager controlled object. 

Magento 2 Plugins can’t be used with

  • Non-public methods

  • Static methods

  • Final methods

  • Final classes

Types of Interceptors in Magento 2

  • Before listener

  • After listener

  • Around listener


It is crucial to follow certain steps to create Plugin in Magento 2. To get detailed information, refer to the tutorial at: https://meetanshi.com/blog/create-plugin-interceptor-in-magento-2/


No comments:
Write comments


Get more of our update !