Saleor arrives with some plugins already implemented by default. These plugins are located in
To provide the
PluginsManager with a list of enabled plugins, include the Python plugin path in the
PluginsManager is located in the
saleor.plugins.manager. It is a class responsible for handling all declared plugins and serving a response from them. In case of a non-declared plugin, it serves a default response.
It is possible to overwrite an
PluginsManager class by implementing it on its own. Saleor will discover the manager class by taking the declared path from
Base plugin class
BasePlugin class is located in the
saleor.plugins.base_plugin. It serves as an abstract class for storing all callback methods available to plugins.
Multiple plugins are executed as a pipeline: each callback receives a
previous_value parameter, the first plugin receives the default value, each consecutive plugin receives the output of the previous one.
Saleor allows you to change the configuration of any given plugin over API.
CONFIG_STRUCTURE describes the shape of the configuration: field names, their types, and labels to use in the user interface.
DEFAULT_CONFIGURATION provides initial values for those fields.
The plugin configuration can be further validated by overwriting the
validate_plugin_configuration method like in the following example:
Saleor will use this data to create default configuration in DB which will be served by the API.
Writing your own plugins
Make sure that each plugin inherits from the
BasePlugin class and that it overwrites base methods.
You can write your plugin as a class which has callable instances, like the one below:
There is no need to implement all base methods as the
PluginsManager will use default values for methods that are not implemented.
Loading your plugin
To activate the new plugin, add it to the
settings.PLUGINS list in your Django settings:
Some plugin operations should be done asynchronously. Saleor uses Celery and will discover all Celery tasks declared in
tasks.py in the plugin directories.