Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add countries field to shop query
akjanikb80baaffc123
diff --git a/saleor/graphql/core/resolvers.py b/saleor/graphql/core/resolvers.pyindex 9fc20d8145..5f1b7e04f6 100644--- a/saleor/graphql/core/resolvers.py+++ b/saleor/graphql/core/resolvers.py@@ -1,9 +1,10 @@from django.conf import settings+from django_countries import countriesfrom phonenumbers import COUNTRY_CODE_TO_REGION_CODEfrom ...core.permissions import get_permissionsfrom ..utils import format_permissions_for_display-from .types import LanguageDisplay, Shop+from .types import CountryDisplay, LanguageDisplay, Shopdef resolve_shop(root, info):@@ -13,7 +14,11 @@ def resolve_shop(root, info):languages = [LanguageDisplay(code=language[0], language=language[1]) for language in languages]phone_prefixes = list(COUNTRY_CODE_TO_REGION_CODE.keys())+ countries_map = [+ CountryDisplay(+ code=country[0], country=country[1]) for country in countries]return Shop(permissions=permissions,languages=languages,- phone_prefixes=phone_prefixes)+ phone_prefixes=phone_prefixes,+ countries=countries_map)diff --git a/saleor/graphql/core/types.py b/saleor/graphql/core/types.pyindex eac819f359..d068dc84ec 100644--- a/saleor/graphql/core/types.py+++ b/saleor/graphql/core/types.py@@ -1,11 +1,13 @@import decimalimport graphene-from django_prices.templatetags import prices_i18n+from django_countries import countriesfrom graphene.types import Scalarfrom graphene_django import DjangoObjectTypefrom graphql.language import ast+from django_prices.templatetags import prices_i18n+# FIXME: not yet merged https://github.com/graphql-python/graphene/pull/726class Decimal(Scalar):@@ -29,6 +31,11 @@ class Decimal(Scalar):return cls.parse_value(node.value)+class CountryDisplay(graphene.ObjectType):+ code = graphene.String(description='Country code.')+ country = graphene.String(description='Country.')++class CountableConnection(graphene.relay.Connection):class Meta:abstract = True@@ -125,14 +132,16 @@ class TaxedMoneyRange(graphene.ObjectType):class Meta:description = 'Represents a range of monetary values.'-class Shop(graphene.ObjectType):permissions = graphene.List(PermissionDisplay, description='List of available permissions')languages = graphene.List(LanguageDisplay,description='List of the shops\'s supported languages')- phone_prefixes = graphene.List(graphene.String)+ phone_prefixes = graphene.List(+ graphene.String, description='List of possible phone prefixes.')+ countries = graphene.List(+ CountryDisplay, description='List of countries available in the shop.')class Meta:description = 'Represents a shop resources.'diff --git a/saleor/settings.py b/saleor/settings.pyindex 1b8be3650d..bf8b7c3930 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -5,7 +5,8 @@ import dj_database_urlimport dj_email_urlimport django_cache_urlfrom django.contrib.messages import constants as messages-from django.utils.translation import gettext_lazy as _+from django.utils.translation import gettext_lazy as _, pgettext_lazy+from django_prices.templatetags.prices_i18n import get_currency_fractionfrom . import __version__@@ -291,6 +292,10 @@ DEFAULT_COUNTRY = os.environ.get('DEFAULT_COUNTRY', 'US')DEFAULT_CURRENCY = os.environ.get('DEFAULT_CURRENCY', 'USD')DEFAULT_DECIMAL_PLACES = get_currency_fraction(DEFAULT_CURRENCY)AVAILABLE_CURRENCIES = [DEFAULT_CURRENCY]+COUNTRIES_OVERRIDE = {+ 'EU': pgettext_lazy(+ 'Name of political and economical union of european countries',+ 'European Union')}OPENEXCHANGERATES_API_KEY = os.environ.get('OPENEXCHANGERATES_API_KEY')