Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add User's geolocalization data
Pacu28b53f2f568cf
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.pyindex 3ac83b8852..ae1a8daf27 100644--- a/saleor/graphql/shop/types.py+++ b/saleor/graphql/shop/types.py@@ -5,6 +5,7 @@ from graphql_jwt.decorators import permission_requiredfrom phonenumbers import COUNTRY_CODE_TO_REGION_CODEfrom ...core.permissions import get_permissions+from ...core.utils import get_client_ip, get_country_by_ipfrom ...site import models as site_modelsfrom ..core.types.common import (CountryDisplay, LanguageDisplay, PermissionDisplay, WeightUnitsEnum)@@ -38,7 +39,19 @@ class Domain(graphene.ObjectType):description = 'Represents shop\'s domain.'+class Geolocalization(graphene.ObjectType):+ country = graphene.Field(+ CountryDisplay, required=True,+ description='Country of the user acquired by his IP address.')++ class Meta:+ description = 'Represents customers\'s geolocalization data.'++class Shop(graphene.ObjectType):+ geolocalization = graphene.Field(+ Geolocalization,+ description='Customer\'s geolocalization data.')authorization_keys = graphene.List(AuthorizationKey, description='List of configured authorization keys.',required=True)@@ -102,6 +115,15 @@ class Shop(graphene.ObjectType):ssl_enabled=settings.ENABLE_SSL,url=info.context.build_absolute_uri('/'))+ def resolve_geolocalization(self, info):+ client_ip = get_client_ip(info.context)+ country = get_country_by_ip(client_ip)+ if country:+ return Geolocalization(+ country=CountryDisplay(+ code=country.code, country=country.name))+ return Geolocalization(country=None)+def resolve_default_currency(self, info):return settings.DEFAULT_CURRENCY