Developers/Order plugins/Implementation/Decorator

For the general principle of a decorator see decorator design pattern. For your convenience there is also an example implementation for a plugin provider decorator in lib/mshoplib/src/MShop/Plugin/Provider/Decorator/Example.php. All you need to do is extend MShop_Plugin_Provider_Decorator_Abstract and overwrite method update where you can apply additional rules to the execution of the original method. The advantage of this approach is, that multiple decorators can be used for one plugin and that one decorator can be used by multiple plugins. In this way the common rules are available for all plugins and you can add or remove those rules from your plugins without touching the code of your plugins. Instead, just add or remove decorators in the plugin records.

These rules can be for example


 * execute only for certain locales
 * execute only for registered and logged in customers who already ordered multiple times
 * execute only when the products in the basket exceed a certain amount of money
 * execute only when the amount of products in the basket exceeds a certain threshold
 * and everything else you can image and express in PHP ...

<< Previous: Register plugin and perform actions | Next: Write a unit test for your plugin >>