Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Run method on plugins only for checkout or order channel (#10792)
Iga Karbowiakae4489e64bfc
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex cf34cb0878..aac7293901 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -313,6 +313,7 @@ class PluginsManager(PaymentInterface):default_value,order,lines,+ channel_slug=order.channel.slug,),currency,)@@ -371,6 +372,7 @@ class PluginsManager(PaymentInterface):lines,order,lines,+ channel_slug=order.channel.slug,)return lines@@ -538,12 +540,15 @@ class PluginsManager(PaymentInterface):def get_taxes_for_checkout(self, checkout_info, lines) -> Optional[TaxData]:return self.__run_plugin_method_until_first_success(- "get_taxes_for_checkout", checkout_info, lines+ "get_taxes_for_checkout",+ checkout_info,+ lines,+ channel_slug=checkout_info.channel.slug,)def get_taxes_for_order(self, order: "Order") -> Optional[TaxData]:return self.__run_plugin_method_until_first_success(- "get_taxes_for_order", order+ "get_taxes_for_order", order, channel_slug=order.channel.slug)def apply_taxes_to_product(@@ -1337,8 +1342,9 @@ class PluginsManager(PaymentInterface):self,method_name: str,*args,+ channel_slug: Optional[str] = None,):- plugins = self.get_plugins()+ plugins = self.get_plugins(channel_slug=channel_slug)for plugin in plugins:result = self.__run_method_on_single_plugin(plugin, method_name, None, *args@@ -1560,6 +1566,7 @@ class PluginsManager(PaymentInterface):[],order,available_shipping_methods,+ channel_slug=order.channel.slug,)def excluded_shipping_methods_for_checkout(@@ -1572,6 +1579,7 @@ class PluginsManager(PaymentInterface):[],checkout,available_shipping_methods,+ channel_slug=checkout.channel.slug,)def perform_mutation(diff --git a/saleor/plugins/tests/test_manager.py b/saleor/plugins/tests/test_manager.pyindex f7d13c5f93..f99844d9d8 100644--- a/saleor/plugins/tests/test_manager.py+++ b/saleor/plugins/tests/test_manager.py@@ -1035,6 +1035,43 @@ def test_run_method_on_plugins_only_on_active_ones(assert called_plugins_id == expected_active_plugins_id+ "saleor.plugins.manager.PluginsManager._PluginsManager__run_method_on_single_plugin"+)+def test_run_method_on_plugins_only_for_given_channel(+ mocked_run_on_single_plugin, plugins_manager, channel_USD, channel_PLN+):+ # given+ default_value = "default"++ usd_plugin_1 = ActiveDummyPaymentGateway(+ active=True, channel=channel_USD, configuration=[]+ )+ usd_plugin_2 = ActivePaymentGateway(+ active=True, channel=channel_USD, configuration=[]+ )+ pln_plugin = ChannelPluginSample(active=True, channel=channel_PLN, configuration=[])++ plugins_manager.plugins = [usd_plugin_1, usd_plugin_2, pln_plugin]++ plugins_manager.plugins_per_channel[channel_USD.slug] = [usd_plugin_1, usd_plugin_2]+ plugins_manager.plugins_per_channel[channel_PLN.slug] = [pln_plugin]++ # when+ plugins_manager._PluginsManager__run_method_on_plugins(+ method_name="test_method",+ default_value=default_value,+ channel_slug=channel_USD.slug,+ )++ # then+ assert mocked_run_on_single_plugin.call_count == 2+ called_plugins_id = {+ arg.args[0].PLUGIN_ID for arg in mocked_run_on_single_plugin.call_args_list+ }+ assert called_plugins_id == {usd_plugin_1.PLUGIN_ID, usd_plugin_2.PLUGIN_ID}++def test_run_method_on_single_plugin_method_does_not_exist(plugins_manager):default_value = "default_value"method_name = "method_does_not_exist"