Skip to content

Commit 60a3292

Browse files
authored
Merge pull request grll#2 from AdamQuadmon/shop-options
add Shop Settings Update
2 parents 0916ffd + 03de7b6 commit 60a3292

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ As of now, `saleor-gql-loader` allows to create the following entities:
1515
- [x] product
1616
- [x] product_variant
1717

18+
and update the following entities:
19+
20+
- [x] shop
21+
1822
PR for supporting more graphQL mutations and/or queries are more than welcome.
1923

2024
In it's current state, the project is in very early alpha, might be unstable

saleor_gql_loader/data_loader.py

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,166 @@ def __init__(self, auth_token, endpoint_url="http://localhost:8000/graphql/"):
6565
self.headers = {"Authorization": "Bearer {}".format(auth_token)}
6666
self.endpoint_url = endpoint_url
6767

68+
def update_shop_settings(self, **kwargs):
69+
"""update shop settings.
70+
71+
Parameters
72+
----------
73+
**kwargs : dict, optional
74+
overrides the default value set to update the shop settings refer to the
75+
ShopSettingsInput graphQL type to know what can be overriden.
76+
77+
Raises
78+
------
79+
Exception
80+
when shopErrors is not an empty list
81+
"""
82+
83+
variables = {
84+
"input": kwargs
85+
}
86+
87+
query = """
88+
mutation ShopSettingsUpdate($input: ShopSettingsInput!) {
89+
shopSettingsUpdate(input: $input) {
90+
shop {
91+
headerText
92+
description
93+
includeTaxesInPrices
94+
displayGrossPrices
95+
chargeTaxesOnShipping
96+
trackInventoryByDefault
97+
defaultWeightUnit
98+
automaticFulfillmentDigitalProducts
99+
defaultDigitalMaxDownloads
100+
defaultDigitalUrlValidDays
101+
defaultMailSenderName
102+
defaultMailSenderAddress
103+
customerSetPasswordUrl
104+
}
105+
shopErrors {
106+
field
107+
message
108+
code
109+
}
110+
}
111+
}
112+
"""
113+
114+
response = graphql_request(
115+
query, variables, self.headers, self.endpoint_url)
116+
117+
errors = response["data"]["shopSettingsUpdate"]["shopErrors"]
118+
handle_errors(errors)
119+
120+
return response["data"]["shopSettingsUpdate"]["shop"]
121+
122+
def update_shop_domain(self, **kwargs):
123+
"""update shop domain.
124+
125+
Parameters
126+
----------
127+
**kwargs : dict, optional
128+
overrides the default value set to update the shop domain refer to the
129+
SiteDomainInput graphQL type to know what can be overriden.
130+
131+
Raises
132+
------
133+
Exception
134+
when shopErrors is not an empty list
135+
"""
136+
137+
variables = {
138+
"siteDomainInput": kwargs
139+
}
140+
141+
query = """
142+
mutation ShopDomainUpdate($siteDomainInput: SiteDomainInput!) {
143+
shopDomainUpdate(input: $siteDomainInput) {
144+
shop {
145+
domain {
146+
host
147+
sslEnabled
148+
url
149+
}
150+
}
151+
shopErrors {
152+
field
153+
message
154+
code
155+
}
156+
}
157+
}
158+
"""
159+
160+
response = graphql_request(
161+
query, variables, self.headers, self.endpoint_url)
162+
163+
errors = response["data"]["shopDomainUpdate"]["shopErrors"]
164+
handle_errors(errors)
165+
166+
return response["data"]["shopSettingsUpdate"]["shop"]["domain"]
167+
168+
def update_shop_address(self, **kwargs):
169+
"""update shop address.
170+
171+
Parameters
172+
----------
173+
**kwargs : dict, optional
174+
overrides the default value set to update the shop address refer to the
175+
AddressInput graphQL type to know what can be overriden.
176+
177+
Raises
178+
------
179+
Exception
180+
when shopErrors is not an empty list
181+
"""
182+
183+
variables = {
184+
"addressInput": kwargs
185+
}
186+
187+
query = """
188+
mutation ShopAddressUpdate($addressInput: AddressInput!) {
189+
shopAddressUpdate(input: $addressInput) {
190+
shop {
191+
companyAddress {
192+
id
193+
firstName
194+
lastName
195+
companyName
196+
streetAddress1
197+
streetAddress2
198+
city
199+
cityArea
200+
postalCode
201+
country {
202+
code
203+
country
204+
}
205+
countryArea
206+
phone
207+
isDefaultShippingAddress
208+
isDefaultBillingAddress
209+
}
210+
}
211+
shopErrors {
212+
field
213+
message
214+
code
215+
}
216+
}
217+
}
218+
"""
219+
220+
response = graphql_request(
221+
query, variables, self.headers, self.endpoint_url)
222+
223+
errors = response["data"]["shopAddressUpdate"]["shopErrors"]
224+
handle_errors(errors)
225+
226+
return response["data"]["shopAddressUpdate"]["shop"]["companyAddress"]
227+
68228
def create_warehouse(self, **kwargs):
69229
"""create a warehouse.
70230

0 commit comments

Comments
 (0)