Developers/Order plugins/Basics

Structure of an order plugin
All order plugin providers and the classes belonging to them are located in lib/mshoplib/src/MShop/Plugin/Provider/ or in lib/custom/src/MShop/Plugin/Provider/ of your extension. In order to notify the plugins of events in the basket and to execute the desired actions, the basket and the plugin providers establish the observer design pattern. The basket is the publisher and all order plugins are listeners. This means, when a certain event occurs in the basket, all order plugins that have registered for that event are executed. The basket methods take care to "publish" these events before and after certain code is executed.

Each order plugin is configured by a record in the database. The record stores information about the name of the plugin provider which is used, about the names of the plugin provider decorators to be added and about the configuration for that provider. Please see the user manual for more.

An order plugin is built by the following classes:


 * MShop_Plugin_Provider_Order_&lt;plugin-provider&gt;
 * Implements the functionality of &lt;plugin-provider&gt; which executes certain actions on defined events the provider has registered for in the basket.


 * MShop_Plugin_Provider_Decorator_&lt;decorator&gt;
 * Adds constraints to the execution of an order plugin or functionality that should be available for multiple plugin providers. Decorators are added in the administration interface by adding their name after the plugin name, separated by a comma.


 * MShop_Plugin_Item_Interface
 * Represents a plugin holding information about the configuration, provider and decorators


 * MShop_Plugin_Manager_Interface
 * Manages plugin items, instantiates the plugin providers and registers them in the basket.


 * MShop_Order_Item_Base_Interface
 * Provides the basket acting as publisher and notifying the order plugins on events.

Plugin process
Within each user session an instance of the basket is created as soon as the customer puts an article into it. The getSession</tt> method of managers implementing MShop_Order_Manager_Base_Interface</tt> instantiates the basket (MShop_Order_Item_Base_Interface</tt>) and triggers the registration of the plugins:

A plugin manager is created and its register</tt> method is executed, which instantiates all configured plugins, i.e. all active plugin records are used. For each plugin item, the configured plugin provider object (MShop_Plugin_Provider_Order_&lt;plugin-provider&gt;</tt>) is created and the listed decorators are applied. The register</tt> method of the manager also takes care of registering the plugin provider objects at the new basket object calling the register</tt> method of each provider. The order in which the plugins register themselves on the basket and they are executed on an event can be influenced by the position property of the record in the admin interface. The plugin item with the lowest number is executed first, when two or more plugins use the same number, the order is arbitrary.

When an event occurs all plugin providers that have been registered for it are notified by the basket, i.e. the update</tt> method of the plugin is executed. Take a look at the observer design pattern for more information about how this works.

Note: It is possible to apply decorators to providers globally using the configuration string mshop/plugin/provider/order/decorators</tt>. Named decorators listed in this configuration array are applied to all plugin providers.

Next: Example plugin provider >>