Skip to content

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

Add checkout filed to User type in GraphQl

fowczarek6527bc410ad7
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index ff8b788d35..8cf4592adf 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -5,7 +5,9 @@ from graphene import relay
from graphql_jwt.decorators import permission_required
from ...account import models
+from ...checkout.utils import get_user_cart
from ...core.permissions import get_permissions
+from ..checkout.types import Checkout
from ..core.connection import CountableDjangoObjectType
from ..core.fields import PrefetchingConnectionField
from ..core.types import CountryDisplay, PermissionDisplay
@@ -45,6 +47,9 @@ class User(CountableDjangoObjectType):
addresses = gql_optimizer.field(
graphene.List(Address, description='List of all user\'s addresses.'),
model_field='addresses')
+ checkout = graphene.Field(
+ Checkout,
+ description='Returns the last open checkout of this user.')
note = graphene.String(description='A note about the customer')
orders = gql_optimizer.field(
PrefetchingConnectionField(
@@ -64,6 +69,9 @@ class User(CountableDjangoObjectType):
def resolve_addresses(self, info, **kwargs):
return self.addresses.all()
+ def resolve_checkout(self, info, **kwargs):
+ return get_user_cart(self)
+
def resolve_permissions(self, info, **kwargs):
if self.is_superuser:
permissions = get_permissions()