The plugin system for SilverCart objects
In our last projects, we realized that customizing while maintaining the ability to upgrade easily would be even easier if we had a plugin system for SilverCart.
Guess what? We proudly announce our new plugin system for SilverCart objects.
The plugin system will be released after the Mail Order World tradeshow where we will present our shopsoftware SilverCart.
Here is an excerpt from the documentation which provides a great overview (thanks to Sascha):
Why don't we just use decorators?
The plugin system has some advantages to just using decorators:
- All pluggable methods are put together in one file (the plugin provider) that can easily be found via the naming convention, e.g. for "SilvercartOrder" the plugin provider is called "SilvercartOrderPluginProvider".
Otherwise you would have to check the source code of SilvercartOrder and find out, what methods are extendable. - We can gather common methods for all plugins in the base class "SilvercartPlugin".
- When multiple plugins are decorated into one plugin provider method their output is merged automatically.
- The gates are open for later developments like priorities when multiple plugins are decorated into one plugin provider method
As long as you don't want to write your own plugin providers the mechanism for decorating is exactly the one you know from Silverstripe: use a DataObjectDecorator object, add it as extension and provide the methods you want to decorate.
The structure of the SilverCart plugin system
The most basic object for plugins is the class "SilvercartPlugin". It provides methods that can and should be used by all plugins.
This basic object is extended by specialized objects that are plugin-providers for SilverCart classes. Among those are e.g. "SilvercartPluginOrder", "SilvercartPluginShoppingCart", etc. The plugin-provider objects can be decorated with your own specialized plugins. They expose all possible hooks that you can implemented to provide additional functionality and outputs to the original SilverCart classes.