Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Update documentation with extension plugin section
Maciej Korycinski6c9c3c0f1229
diff --git a/docs/customization.rst b/docs/customization.rstindex 51ffb8e6c9..22515ced26 100644--- a/docs/customization.rst+++ b/docs/customization.rst@@ -9,6 +9,7 @@ Customizing Saleorcustomization/emailscustomization/frontendcustomization/backend+ customization/extensionscustomization/i18ncustomization/testscustomization/cidiff --git a/docs/customization/extensions.rst b/docs/customization/extensions.rstnew file mode 100644index 0000000000..e3e7877223--- /dev/null+++ b/docs/customization/extensions.rst@@ -0,0 +1,75 @@+Extensions+==========+Saleor has implemented extensions architecture.+It includes hooks for most basic operations like calculation of prices in the checkout or+calling some actions when an order has been created.+++ExtensionsManager+-----------------+ExtensionsManager is located in ``saleor.core.extensions.base_plugin``.+It is a class responsible for handling all declared plugins and serving a response from them.+It serves a default response in case of a non-declared plugin. There is a possibility to overwrite ExtensionsManager+class by implementing it on its own. Saleor will discover the manager class by taking declared path from+``settings.EXTENSIONS_MANAGER``.+Each Django request object has its own manager included as the ``extensions`` field. It is attached in the Saleor middleware.+++BasePlugin+----------+BasePlugin is located in ``saleor.core.extensions.base_plugin``. It is an abstract class for storing all methods+available for any plugin. All methods take the ``previous_value`` parameter. ``previous_value`` contains a value+calculated by the previous plugin in the queue. If the plugin is first, it will use the default value calculated by+the manager.+++Plugins+-------+Saleor has some plugins implemented by default. These plugins are located in ``saleor.core.extensions.plugins``.+The ExtensionManager needs to receive a list of enabled plugins. It can be done by including the plugin python path in the+``settings.PLUGINS`` list.+++Celery Tasks+------------+Some plugin operations should be done asynchronously. If Saleor has celery enabled, it will discover all tasks+declared in ``tasks.py`` in the plugin directories.+++``plugin.py``+++.. code-block:: python++ def postprocess_order_creation(self, order: "Order", previous_value: Any):+ if not self._enabled:+ return+ data = {}+ transaction_url = urljoin(get_api_url(), "transactions/createoradjust")++ api_post_request_task.delay(transaction_url, data)+++``tasks.py``++.. code-block:: python++ from celery import shared_task++ from . import api_post_request+++ @shared_task+ def api_post_request_task(transaction_url, data):+ api_post_request(transaction_url, data)+++++Writing Your Own Plugin+-----------------------+Acustom plugin has to inherit from the BasePlugin class. It should overwrite base methods. The plugin needs to be added+to the ``settings.PLUGINS``++.. note::+ There is no need to implement all base methods. ``ExtensionManager`` will use default values for methods that are not implemented.