-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
149 lines (131 loc) · 4.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from dotenv import load_dotenv
import os
from api_client import APIClient
from store_setup import StoreSetup
def main():
load_dotenv()
API_URL = os.getenv("API_URL")
EMAIL = os.getenv("EMAIL")
PASSWORD = os.getenv("PASSWORD")
api_client = APIClient(API_URL, EMAIL, PASSWORD)
api_client.login()
# Initialize the StoreSetup with the API client
store_setup = StoreSetup(api_client)
# Clean previous data
# consider search by slug and delete
warehouse_id_to_remove = (
"V2FyZWhvdXNlOjQ4MTRmZDYyLWI0MTktNGQyOS05ZTE1LTM1Y2MzNDcyMGMzMA=="
)
channel_id_to_remove = "Q2hhbm5lbDo1MA=="
shipping_zone_id_to_remove = "U2hpcHBpbmdab25lOjE1"
_shipping_method_id_to_remove = "U2hpcHBpbmdNZXRob2RUeXBlOjI3"
remove_channel_input = {"id": channel_id_to_remove}
store_setup.remove_channel(remove_channel_input)
print(f"Channel removed: {channel_id_to_remove}")
remove_warehouse_input = {"id": warehouse_id_to_remove}
store_setup.remove_warehouse(remove_warehouse_input)
print(f"Warehouse removed: {warehouse_id_to_remove}")
remove_shipping_zone_input = {"id": shipping_zone_id_to_remove}
store_setup.remove_shipping_zone(remove_shipping_zone_input)
print(f"Shipping zone removed: {shipping_zone_id_to_remove}")
# Create the warehouse
warehouse_input = {
"input": {
"name": "Main Warehouse",
"slug": "main-warehouse",
"email": "[email protected]",
"address": {
"country": "US",
"countryArea": "AL",
"city": "New Sandraburgh",
"postalCode": "35969",
"companyName": "Green Ltd",
"streetAddress1": "302 Matthew Glen",
"streetAddress2": "",
},
"shippingZones": [],
}
}
warehouse = store_setup.create_warehouse(warehouse_input)
warehouse_id = warehouse["id"]
print(f"Warehouse created: {warehouse_id}")
# Create the channel
channel_input = {
"input": {
"name": "Test Channel",
"slug": "test-channel",
"defaultCountry": "US",
"currencyCode": "USD",
"isActive": True,
"addShippingZones": [],
"addWarehouses": [warehouse_id],
"stockSettings": {"allocationStrategy": "PRIORITIZE_SORTING_ORDER"},
"paymentSettings": {"defaultTransactionFlowStrategy": "AUTHORIZATION"},
"orderSettings": {
"allowUnpaidOrders": True,
"automaticallyConfirmAllNewOrders": True,
"automaticallyFulfillNonShippableGiftCard": True,
"expireOrdersAfter": 1440,
"deleteExpiredOrdersAfter": 120,
"markAsPaidStrategy": "TRANSACTION_FLOW",
"includeDraftOrderInVoucherUsage": True,
},
"checkoutSettings": {
"automaticallyCompleteFullyPaidCheckouts": True,
},
}
}
channel = store_setup.create_channel(channel_input)
channel_id = channel["id"]
print(f"Channel created: {channel_id}")
# Create the shipping zone
shipping_zone_input = {
"input": {
"name": "US - USA Shipping",
"description": "",
"countries": ["US"],
"default": False,
"addWarehouses": [warehouse_id],
"addChannels": [channel_id],
}
}
shipping_zone = store_setup.create_shipping_zone(shipping_zone_input)
shipping_zone_id = shipping_zone["id"]
print(f"Shipping zone created: {shipping_zone_id}")
# Create the shipping method
shipping_price_input = {
"input": {
"shippingZone": shipping_zone_id,
"name": "USPS Priority Mail",
"type": "PRICE",
"description": None,
"maximumDeliveryDays": None,
"minimumDeliveryDays": None,
"addPostalCodeRules": [],
"deletePostalCodeRules": [],
"inclusionType": "EXCLUDE",
"taxClass": "",
}
}
shipping_method = store_setup.create_shipping_method(shipping_price_input)
shipping_method_id = shipping_method["id"]
print(f"Shipping method created: {shipping_method_id}")
# Update shipping method channels and prices
shipping_method_price_input = {
"id": shipping_method_id,
"input": {
"addChannels": [
{
"channelId": channel_id,
"price": 19.99,
"minimumOrderPrice": 0,
"maximumOrderPrice": 666,
}
],
"removeChannels": [],
},
}
store_setup.update_shipping_method_channel_listing(shipping_method_price_input)
print("Shipping pricing updated")
if __name__ == "__main__":
main()