Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add descriptions to basic methods of BasePlugin

Maciej Korycinskif65af3cf2505
diff --git a/saleor/extensions/base_plugin.py b/saleor/extensions/base_plugin.py
index 5f0a47960f..ff77699bf7 100644
--- a/saleor/extensions/base_plugin.py
+++ b/saleor/extensions/base_plugin.py
@@ -36,6 +36,7 @@ class BasePlugin:
return self.PLUGIN_NAME
def _initialize_plugin_configuration(self):
+ """Initialize plugin by fetching configuration from internal cache or DB."""
plugin_config_qs = PluginConfiguration.objects.filter(name=self.PLUGIN_NAME)
plugin_config = self._cached_config or plugin_config_qs.first()
@@ -49,6 +50,11 @@ class BasePlugin:
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
+ """Calculate the total for checkout.
+
+ Overwrite this method in case you need to apply specific logic for
+ calculation of checkout total. Return TaxedMoney.
+ """
return NotImplemented
def calculate_checkout_subtotal(
@@ -57,6 +63,11 @@ class BasePlugin:
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
+ """Calculate the subtotal for checkout.
+
+ Overwrite this method in case you need to apply specific logic for
+ calculation of checkout subtotal. Return TaxedMoney.
+ """
return NotImplemented
def calculate_checkout_shipping(
@@ -65,11 +76,21 @@ class BasePlugin:
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
+ """Calculate the shipping costs for checkout.
+
+ Overwrite this method in case you need to apply specific logic for
+ calculation of shipping costs. Return TaxedMoney.
+ """
return NotImplemented
def calculate_order_shipping(
self, order: "Order", previous_value: TaxedMoney
) -> TaxedMoney:
+ """Calculate the shipping costs for the order.
+
+ Update shipping costs in the order in case of changes in shipping address or
+ changes in draft order. Return TaxedMoney.
+ """
return NotImplemented
def calculate_checkout_line_total(
@@ -78,32 +99,69 @@ class BasePlugin:
discounts: List["DiscountInfo"],
previous_value: TaxedMoney,
) -> TaxedMoney:
+ """Calculate checkout line total.
+
+ Overwrite this method in case you need to apply specific logic for
+ calculation of checkout line total. Return TaxedMoney.
+ """
return NotImplemented
def calculate_order_line_unit(
self, order_line: "OrderLine", previous_value: TaxedMoney
) -> TaxedMoney:
+ """Calculate order line unit price.
+
+ Update order line unit price in the order in case of changes in draft order.
+ Return TaxedMoney.
+ Overwrite this method in case you need to apply specific logic for calculation
+ of order line unit price.
+ """
return NotImplemented
def get_tax_rate_type_choices(
self, previous_value: List["TaxType"]
) -> List["TaxType"]:
+ """Return list of all tax categories.
+
+ The returned list will be used to provide staff users with the possibility to
+ assign tax categories to a product. It can be used by tax plugins to properly
+ calculate taxes for products.
+ Overwrite this method in case your plugin provides a list of tax categories.
+ """
return NotImplemented
def show_taxes_on_storefront(self, previous_value: bool) -> bool:
+ """Define if storefront should add info about taxes to the price.
+
+ It is used only on the old storefront. The returned value determines if
+ storefront should append info to the price about "including/excluding X% Vat".
+ """
return NotImplemented
def taxes_are_enabled(self, previous_value: bool) -> bool:
+ """Define if checkout should add info about included taxes.
+
+ It is used only on the old storefront. It adds tax section to the checkout view.
+ """
return NotImplemented
def apply_taxes_to_shipping_price_range(
self, prices: MoneyRange, country: Country, previous_value: TaxedMoneyRange
) -> TaxedMoneyRange:
+ """Provide the estimation of shipping costs based on country.
+
+ It is used only in the old strofront in cart view.
+ """
return NotImplemented
def apply_taxes_to_shipping(
self, price: Money, shipping_address: "Address", previous_value: TaxedMoney
) -> TaxedMoney:
+ """Apply taxes to the shipping costs based on the shipping address.
+
+ Overwrite this method if you want to show available shipping methods with
+ taxes.
+ """
return NotImplemented
def apply_taxes_to_product(
@@ -113,47 +171,97 @@ class BasePlugin:
country: Country,
previous_value: TaxedMoney,
) -> TaxedMoney:
+ """Apply taxes to the product price based on the customer country.
+
+ Overwrite this method if you want to show products with taxes.
+ """
return NotImplemented
def preprocess_order_creation(
self, checkout: "Checkout", discounts: List["DiscountInfo"], previous_value: Any
):
+ """Trigger directly before order creation.
+
+ Overwrite this method in case you need to trigger specific logic before the
+ order will be created.
+ """
return NotImplemented
def order_created(self, order: "Order", previous_value: Any):
+ """Trigger when order is created.
+
+ Overwrite this method in case you need to trigger specific logic after order
+ creation.
+ """
return NotImplemented
def assign_tax_code_to_object_meta(
self, obj: Union["Product", "ProductType"], tax_code: str, previous_value: Any
):
+ """Assign tax code dedicated to plugin."""
return NotImplemented
def get_tax_code_from_object_meta(
self, obj: Union["Product", "ProductType"], previous_value: "TaxType"
) -> "TaxType":
+ """Return tax code from object meta."""
return NotImplemented
def get_tax_rate_percentage_value(
self, obj: Union["Product", "ProductType"], country: Country, previous_value
) -> Decimal:
+ """Return tax rate percentage value for given tax rate type in the country.
+
+ It is used only on the old storefront.
+ """
return NotImplemented
def customer_created(self, customer: "User", previous_value: Any) -> Any:
+ """Trigger when user is created.
+
+ Overwrite this method in case you need to trigger specific logic after user
+ creation.
+ """
return NotImplemented
def product_created(self, product: "Product", previous_value: Any) -> Any:
+ """Trigger when product is created.
+
+ Overwrite this method in case you need to trigger specific logic after product
+ creation.
+ """
return NotImplemented
def order_fully_paid(self, order: "Order", previous_value: Any) -> Any:
+ """Trigger when order is fully-paid.
+
+ Overwrite this method in case you need to trigger specific logic when the order
+ is fully-paid.
+ """
return NotImplemented
def order_updated(self, order: "Order", previous_value: Any) -> Any:
+ """Trigger when order is updated.
+
+ Overwrite this method in case you need to trigger specific logic when order is
+ changed.
+ """
return NotImplemented
def order_cancelled(self, order: "Order", previous_value: Any) -> Any:
+ """Trigger when order is cancelled.
+
+ Overwrite this method in case you need to trigger specific logic when order is
+ cancelled.
+ """
return NotImplemented
def order_fulfilled(self, order: "Order", previous_value: Any) -> Any:
+ """Trigger when order is fulfilled.
+
+ Overwrite this method in case you need to trigger specific logic when order is
+ fulfilled.
+ """
return NotImplemented
def authorize_payment(
@@ -212,7 +320,7 @@ class BasePlugin:
def validate_plugin_configuration(cls, plugin_configuration: "PluginConfiguration"):
"""Validate if provided configuration is correct.
- Raise django.core.exceptions.ValidationError in the other cases
+ Raise django.core.exceptions.ValidationError in the other cases.
"""
return
@@ -236,15 +344,28 @@ class BasePlugin:
@classmethod
def _get_default_configuration(cls):
+ """Return default configuration for plugin.
+
+ Each configurable plugin has to provide the default structure of the
+ configuration. If plugin configuration is not found in DB, the manager will use
+ the config structure to create a new one in DB.
+ """
defaults = None
return defaults
@classmethod
def _hide_secret_configuration_fields(cls, configuration: List[dict]):
+ """Hide secret values of the configuration fields."""
return
@classmethod
def _append_config_structure(cls, configuration):
+ """Append configuration structure to config from the database.
+
+ Database stores "key: value" pairs, the definition of fields should be declared
+ inside of the plugin. Based on this, the plugin will generate a structure of
+ configuration with current values and provide access over API.
+ """
config_structure = getattr(cls, "CONFIG_STRUCTURE") or {}
for configuration_field in configuration: