Question:
I am using the WIX Orders and Products CMS for managing my customer orders. I see that the productIds is buried under the lineItems column of the Orders CMS. I need to process orders by productIds, so I end up running a http-functions query to retrieve the orders, however I only get 50 items at a time, and they’re not going to be for the product that I’m processing.
Wondering what is the best practice here in setting up the orders CMS such that the lineItems doesn’t include every field and some of these fields are exposed as columns that can be filtered on when retrieving.
Product:
Wix Stores API
What are you trying to achieve:
Need to retrieve All orders of type fulfillmentStatus = “UNFULFILLED” orders from the Orders CMS for a specific ProductId. However the productId is buried inside the lineItem json column
What have you already tried:
I am currently running a http-function that allows me to retrieve orders and then I filter them on client side. However, the retrieval only returns 50 items at a time. So I’m going to have to provide a loop and use the skip function to retrieve the entire set of orders, and then filter them to check the json for the correct productId. I have to do something like this and this doesn’t sound like a correct mechanism to filter orders …
for order in _orders['items']:
print("Processing order: ", order['number'])
# Iterate through the line items
for line_item in order['lineItems']:
print(line_item)
if line_item['productId'] in yearbook_products:
print("Found a product to process...")
# Let's process this order
Additional information:
The orders is retrieved via a query that looks like this on the Orders CMS
wixData.query("Stores/Orders")
.ne("fulfillmentStatus", "FULFILLED") // ne stands for "not equals"
.eq("paymentStatus", "PAID")
.skip(skip)
.find({ "suppressAuth": true })
.then(results => {
if(results.items.length > 0) {
response.body = {
"items" : results.items
};
return ok(response);
} else {
response.body = {
"items": []
};
return notFound(response);
}
})
.catch(error => {
response.body = {
"items": [],
"error": error
};
badRequest(response)
});