Skip to content

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

Extract applicable shipping methods to utils

fowczareka2b2d746fc70
diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.py
index fbfa9bd60b..9c0682d339 100644
--- a/saleor/graphql/checkout/types.py
+++ b/saleor/graphql/checkout/types.py
@@ -5,7 +5,7 @@ from ...checkout import models
from ...core.utils.taxes import get_taxes_for_address
from ..core.connection import CountableDjangoObjectType
from ..core.types.money import TaxedMoney
-from ..order.resolvers import resolve_shipping_methods
+from ..order.utils import applicable_shipping_methods
from ..shipping.types import ShippingMethod
@@ -84,7 +84,7 @@ class Checkout(CountableDjangoObjectType):
taxes = get_taxes_for_address(self.shipping_address)
price = self.get_subtotal(
taxes=taxes, discounts=info.context.discounts)
- return resolve_shipping_methods(self, info, price.gross.amount)
+ return applicable_shipping_methods(self, info, price.gross.amount)
def resolve_is_shipping_required(self, info):
return self.is_shipping_required()
diff --git a/saleor/graphql/order/resolvers.py b/saleor/graphql/order/resolvers.py
index 151eccb8e8..b37019469b 100644
--- a/saleor/graphql/order/resolvers.py
+++ b/saleor/graphql/order/resolvers.py
@@ -3,10 +3,10 @@ import graphene_django_optimizer as gql_optimizer
from ...order import OrderEvents, OrderStatus, models
from ...order.utils import sum_order_totals
-from ...shipping import models as shipping_models
from ..utils import filter_by_period, filter_by_query_param
from .enums import OrderStatusFilter
from .types import Order
+from .utils import applicable_shipping_methods
ORDER_SEARCH_FIELDS = (
'id', 'discount_name', 'token', 'user_email', 'user__email')
@@ -50,15 +50,7 @@ def resolve_order(info, id):
def resolve_shipping_methods(obj, info, price):
- if not obj.is_shipping_required():
- return None
- if not obj.shipping_address:
- return None
-
- qs = shipping_models.ShippingMethod.objects
- return qs.applicable_shipping_methods(
- price=price, weight=obj.get_total_weight(),
- country_code=obj.shipping_address.country.code)
+ return applicable_shipping_methods(obj, info, price)
def resolve_homepage_events(info):
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index ab6d1bd10e..3a8b2b59dd 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -10,7 +10,7 @@ from ..core.types.money import Money, TaxedMoney
from ..payment.types import OrderAction, Payment, PaymentChargeStatusEnum
from ..shipping.types import ShippingMethod
from .enums import OrderEventsEmailsEnum, OrderEventsEnum
-from .utils import can_finalize_draft_order
+from .utils import applicable_shipping_methods, can_finalize_draft_order
class OrderEvent(CountableDjangoObjectType):
@@ -299,8 +299,7 @@ class Order(CountableDjangoObjectType):
@staticmethod
def resolve_available_shipping_methods(self, info):
- from .resolvers import resolve_shipping_methods
- return resolve_shipping_methods(
+ return applicable_shipping_methods(
self, info, self.get_subtotal().gross.amount)
def resolve_is_shipping_required(self, info):
diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.py
index 223f786d98..1c0e27049b 100644
--- a/saleor/graphql/order/utils.py
+++ b/saleor/graphql/order/utils.py
@@ -1,3 +1,4 @@
+from ...shipping import models as shipping_models
from ..core.types.common import Error
@@ -25,3 +26,15 @@ def can_finalize_draft_order(order, errors):
message='Shipping method is not valid for chosen shipping '
'address'))
return errors
+
+
+def applicable_shipping_methods(obj, info, price):
+ if not obj.is_shipping_required():
+ return None
+ if not obj.shipping_address:
+ return None
+
+ qs = shipping_models.ShippingMethod.objects
+ return qs.applicable_shipping_methods(
+ price=price, weight=obj.get_total_weight(),
+ country_code=obj.shipping_address.country.code)