Use Plugins Interceptors instead of such outdated approaches as Magento® rewrites and events!
OverviewBack to top
Plugins interceptors extension is intended for Magento developers only. As developers know, there are 2 main means to change existing functionality in Magento 1, namely events and rewrites.
A plugin, or interceptor, is an XML-construction in config.xml of an extension that enables a developer to modify the behavior of class functions. This is achieved by intercepting a function call and running code before, after or around that function call. This allows a developer to substitute or extend the behavior of original methods for any blocks, helpers and models.
- events > - a proper/recommended approach, but 'events' are not always available where they are needed.
- rewrite > - not a better solution since there might be several extensions fighting for the same overrided class, which often leads to a conflict between extensions.
- plugin > - a new solution we have developed for everyone and for free. Plugins interceptors, similarly to Magento 2, helps you avoid conflicts, rewrites and makes development process more flexible. This extension is going to bring Magento 1 to life. Again.
This interception approach reduces conflicts among extensions that change the behavior of the same class or method. What is it that makes these plugins work with one another without conflicts? The interceptors can be called one by one in accordance with a specified sort order.
The extension enables intercepting public and protected methods. Obviously, the final and private methods as well as final classes are not supported.
Plugin syntax is similar to that of both rewrite and events. Add the code below in the current module’s ModuleName/etc/config.xml:
(See image 2)
ModuleName/Model/Plugin.php file needs to be created (like Observer.php for events):
(See image 3)
To download more examples, click on the link: SafeMage_PluginExample.zip
How it works
The extension includes a setting:
- System > Config > Advanced > System > Plugins Interceptors
where one can see a full list of plugins and their sort order, and enable/disable all plugins.
For each class (for example, Mage_Catalog_Block_Product_List) the plugins work with, a new file of Plugged-class is being generated located in: MagentoRoot/var/cache/plugins/Mage_Catalog_Block_Product_List_Plugged.php
(See image 4)
This Plugged-class is performed autoload() and used by Magento instead of the original Mage_Catalog_Block_Product_List to call plugins upon affected methods.
With cache disabled, the file is generated anew when the target class has been addressed. But with Cache Type = Configuration enabled, the file is generated only once and then is being pulled from cache, which doesn’t drain your system’s performance, until this cache type has been refreshed (or 'Flush all cache' has been activated).
- Speeds up development process
- Works with blocks, helpers and models
- Runs code before, after or around that method call
- Adds plugins to public and protected methods
- Ability to enable/disable plugins
- Preview listing of all plugins and their sort order
- Does not affect Magento performance
- Works with/without Magento cache running
- Compatible with compilation mode
Should you have any remarks or suggestions about enhancing the plugin’s functionality, don’t hesitate to Contact us.
Release NotesBack to top
- Compatible with CE: 1.4 18.104.22.168 1.4.2 1.5 1.6 1.6.1 22.214.171.124 1.7 1.8 1.8.1 1.9 1.9.1 1.9.2 1.9.3
- Stability: Stable Build