$w('#thankYouPage1').getOrder()

Why am I receiving: The current user does not have permissions to find on the Stores/Orders collection? If they made it, it must be usable, right? I also tried moving it to the backend, but I’m clueless as to retrieving the correct order number from the thank you page or anywhere else. I can’t go with the last order number created, because of the possibility of multiple orders around the same time frame. Does anyone have any suggestions?

$w.onReady(async function () {
$w(‘#thankYouPage1’).getOrder()
.then( (order) => {
email = order.shippingInfo.shipmentDetails.email;
firstName = order.shippingInfo.shipmentDetails.firstName;
lastName = order.shippingInfo.shipmentDetails.lastName;
company = order.shippingInfo.shipmentDetails.company;
paidOrderId = order.number;
purchaseDt = order._updatedDate;
orderNumber = order.number;

	let OrderIDItems = [], OrderIDItem = {}, lineItem = {}; 
	let lineItems = order.lineItems; 
	for (var i = 0; i < lineItems.length; i++) { 
		lineItem = lineItems[i]; 
		OrderIDItem = { 
			email: email, 
			...}; 
		OrderIDItems.push(OrderIDItem); 
	} 
	let options = {"suppressAuth": true}; 
	wixData.bulkInsert("paidLineItems", OrderIDItems, options) 
		.then((bulkResults) => { 
			console.log(bulkResults); 
		})		 
	.catch((error) => { 
		console.log(error); 
	});				 
}) 

await getSeqNbrs(); 
await writeLineItems(); 

});

Hi @michelehobson ,

the getOrder() function only works with thank you page element, and it is NOT the same as the Wix collection where orders are stored.

This function only works if the user is belonged to that checkout session, which means if other shared the link of thank you page, the other person will see error in the console with no object (order data) retrieved.

It is secured.

Does it solve your questions?

Certified Code