-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
63 lines (51 loc) · 1.99 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
import bigcommerce
import pyrebase
bigConfig = {
'client_id': '',
'client_token': '',
'store_hash': ''
}
fireBaseConfig = {}
# BC initialization
api = bigcommerce.api.BigcommerceApi(client_id=bigConfig["client_id"], store_hash=bigConfig["store_hash"],access_token=bigConfig["client_token"])
api_orders = api.Orders.all()
# Firebase initialization
firebase = pyrebase.initialize_app(fireBaseConfig)
fbRef = firebase.database()
extractedOrders = []
for order in api_orders:
data = {}
if order['status'] == "Shipped":
data['orders'] = order
order_details = api.Orders.get(int(order['id'])).products()
for products in order_details:
data['orders']['product_details'] = products['product_options']
extractedOrders.append(data)
print(len(extractedOrders))
for order in extractedOrders:
apiOrders = order['orders']
print('Adding order details')
ordersRef = fbRef.child('bc_incoming_orders')
orderRef = ordersRef.push({
'bc_id': apiOrders.id,
'date_created': apiOrders.date_created,
'customer_id': apiOrders.customer_id,
'status': apiOrders.status,
'total_ex_tax': apiOrders.total_ex_tax
})
print(apiOrders.id)
fb_order_reference_key = orderRef['name']
print(fb_order_reference_key)
productOptionsKeyOrder = []
for options in apiOrders['product_details']:
orderDetails = fbRef.child('incoming_order_details')
print('Adding product details per order')
productOptionsKeyOrder.append(orderDetails.push({
'option_name': options['display_name'],
"option_value": options['display_value'],
'order_id': fb_order_reference_key
})['name'])
print('Associating {} order to product details entries'.format(fb_order_reference_key))
for orderKey in productOptionsKeyOrder:
productsPerOrder = fbRef.child('productsPerOrder').child(orderRef['name']).child(orderKey)
productsPerOrder.set(True)