feat: implement periodic shopify sales sync
- automated sales check (default 10 mins) - manual reconciliation menu - updates 'status' and 'shopify_status' in sheet - updated docs
This commit is contained in:
@ -482,6 +482,48 @@ export class Shop {
|
||||
} while (!done)
|
||||
}
|
||||
|
||||
FetchOrders(start: Date, end: Date) {
|
||||
let endpoint = Shop.endpoints.orders
|
||||
let start_str = start.toISOString()
|
||||
let end_str = end.toISOString()
|
||||
var params = {
|
||||
created_at_min: start_str,
|
||||
created_at_max: end_str,
|
||||
fields: "id,created_at,financial_status,name,line_items,subtotal_price,total_price,total_tax",
|
||||
status: "any"
|
||||
}
|
||||
|
||||
var all_orders: any[] = []
|
||||
var done = false
|
||||
var next_link = ""
|
||||
do {
|
||||
var response
|
||||
if (next_link === "") {
|
||||
response = this.shopifyAPI(endpoint, params)
|
||||
} else {
|
||||
response = this.shopifyAPI(endpoint, params, next_link)
|
||||
}
|
||||
let resp = response.content
|
||||
let headers = response.headers
|
||||
var orders_arr = resp["orders"]
|
||||
if (orders_arr.length > 0) {
|
||||
all_orders = all_orders.concat(orders_arr)
|
||||
}
|
||||
|
||||
if (headers["Link"] !== undefined) {
|
||||
var links = parseLinkHeader(headers["Link"])
|
||||
if (links["next"] === undefined) {
|
||||
done = true
|
||||
} else {
|
||||
next_link = links["next"]["href"]
|
||||
}
|
||||
} else {
|
||||
done = true
|
||||
}
|
||||
} while (!done)
|
||||
return all_orders
|
||||
}
|
||||
|
||||
GetProducts() {
|
||||
let done = false
|
||||
let query = ""
|
||||
|
||||
Reference in New Issue
Block a user