Skip to content

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

Shipping method endpoint

Adam Janikb9336db43ba7
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 406ada2f3b..f5f179dffd 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -31,6 +31,8 @@ from .product.resolvers import (
resolve_products, resolve_product_types)
from .product.types import (
Category, Collection, Product, ProductAttribute, ProductType)
+from .shipping.resolvers import resolve_shipping_methods
+from .shipping.types import ShippingMethod
from .utils import get_node
@@ -94,6 +96,11 @@ class Query(graphene.ObjectType):
vouchers = DjangoFilterConnectionField(
Voucher, query=graphene.String(description=DESCRIPTIONS['product']),
description="List of the shop\'s vouchers.")
+ shipping_method = graphene.Field(
+ ShippingMethod, id=graphene.Argument(graphene.ID),
+ description='Lookup a shipping method by ID.')
+ shipping_methods = DjangoFilterConnectionField(
+ ShippingMethod, description='List of the shop\'s shipping methods.')
user = graphene.Field(
User, id=graphene.Argument(graphene.ID),
description='Lookup an user type by ID.')
@@ -160,6 +167,12 @@ class Query(graphene.ObjectType):
def resolve_vouchers(self, info, query=None, **kwargs):
return resolve_vouchers(info, query)
+ def resolve_shipping_method(self, info, id):
+ return get_node(info, id, only_type=ShippingMethod)
+
+ def resolve_shipping_methods(self, info, **kwargs):
+ return resolve_shipping_methods(info)
+
def resolve_user(self, info, id):
return resolve_user(info, id)
diff --git a/saleor/graphql/shipping/__init__.py b/saleor/graphql/shipping/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/graphql/shipping/resolvers.py b/saleor/graphql/shipping/resolvers.py
new file mode 100644
index 0000000000..adae1bcbcc
--- /dev/null
+++ b/saleor/graphql/shipping/resolvers.py
@@ -0,0 +1,5 @@
+from ...shipping import models
+
+
+def resolve_shipping_methods(info):
+ return models.ShippingMethod.objects.all()
diff --git a/saleor/graphql/shipping/types.py b/saleor/graphql/shipping/types.py
new file mode 100644
index 0000000000..602e43d6ab
--- /dev/null
+++ b/saleor/graphql/shipping/types.py
@@ -0,0 +1,37 @@
+import graphene
+from graphene import relay
+from graphene_django import DjangoObjectType
+
+from ...shipping import models
+from ..core.types import CountableDjangoObjectType, MoneyRange
+
+
+class ShippingMethod(CountableDjangoObjectType):
+ price_range = graphene.Field(
+ MoneyRange, description="Lowest and highest prices for the shipping.")
+ countries = graphene.List(
+ graphene.String,
+ description="List of countries available for the method.")
+
+ class Meta:
+ description = 'Represents a shipping method in the shop.'
+ model = models.ShippingMethod
+ interfaces = [relay.Node]
+ filter_fields = {
+ 'name': ['icontains'],
+ 'description': ['icontains'],
+ 'price_per_country__price': ['gte', 'lte']
+ }
+
+ def resolve_price_range(self, info):
+ return self.price_range
+
+ def resolve_countries(self, info):
+ return self.countries
+
+
+class ShippingMethodCountry(DjangoObjectType):
+ class Meta:
+ description = 'Country to which shipping applies.'
+ model = models.ShippingMethodCountry
+ exclude_fields = ['shipping_method', 'orders']