Chapter 6. Plugins
In this chapter, we will take a look at a feature of Magento called plugins. Before we start with plugins, we first need to understand the term interception because the two terms are used somewhat interchangeably when dealing with Magento.
Interception is a software design pattern that is used when we want to insert code dynamically without necessarily changing the original class behavior. This works by dynamically inserting code between the calling code and the target object.
The interception pattern in Magento is implemented via plugins. They provide the before, after, and around listeners, which help us extend the observed method behavior.
In this chapter, we will cover the following topics:
- Creating a plugin
- Using the
before
listener - Using the
after
listener - Using the
around
listener - The plugin sort order
Before we start creating a plugin, it is worth noting their limitations. Plugins cannot be created for just any class or method, as they do not work for the following...