Other Extensions by SafeMage

Overview

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.

Implementation example

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):

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).