I am trying to send the data from each order to my collection ‘Orders’. Each product gets its own row. Everything is working except for sending the product options. I have tried so many variations of code. What am I doing wrong??
import wixData from 'wix-data';
export function wixStores_onOrderPaid(event) {
for (let i = 0; i < event.lineItems.length; i++) {
let toInsert = {
"productName": event.lineItems[i].name,
"playerfName": event.lineItems[i].customTextFields[0].value,
"playerlName": event.lineItems[i].customTextFields[1].value,
"paymentStatus": event.lineItems[i].paymentStatus,
"parentfName": event.buyerInfo.firstName,
"parentlName": event.buyerInfo.lastName,
"orderDate": event._dateCreated,
"orderId": event._id,
"school": event.lineItems[i].options[0].description,
}
wixData.insert("Orders", toInsert)
console.log(toInsert)
}
}
Dumb mistake on my part . ISSUE SOLVED with some sleep and a clear head. Use the below code and it works like a charm.
"school": event.lineItems[i].options[0].selection,
#onOrderPaid #eventlineItemsoptions #productOptions