Pardon newbie stuff. I am trying to run the example code found here:
My similar code is this:
import { orders } from “wix-pricing-plans-frontend”;
$w(‘#button4’).onClick((event) => {
orders
.listCurrentMemberOrders()
.then((ordersList) => {
const firstOrder = ordersList[0];
const firstOrderStatus = ordersList[0].status;
console.log("Your orders:", ordersList);
return ordersList;
})
.catch((error) => {
console.error(error);
});
return true;
});
I do not get a list. I’d think sample code should work, but upon stepping through with google developer tools, these errors occur:
Uncaught (in promise) Error: Access to storage is not allowed from this context.
The resource was preloaded using link preload but not used within a few seconds from the window’s load event. Please make sure it has an appropriate as
value and it is preloaded intentionally.
Ultimately I am attempting to see if the logged-in user has purchased a specific plan (I will loop through the results once I can get them).
I tried to understand the AI explanation as to how to fix, but I need help.
TIA
Hi, @Webmaster_Webmaster !!
Your code probably doesn’t need return true;
. 
listCurrentMemberOrders()
is an asynchronous operation (one where you don’t know exactly when the result will return), so you need to wait for the result. However, in your code, return true;
causes the function to finish execution before the asynchronous process completes(meaning the function exits before the list is retrieved).
Additionally, the code inside .then()
runs only after the asynchronous operation is complete, but any code outside .then()
runs immediately without waiting for the async process to finish (in this case, return true;
executes right away). In other words, your function exits before receiving the result of the asynchronous operation.
If you want the function to execute synchronously from top to bottom, you should replace .then()
with await
and make the function async
. 
With the help of AI, I have rewritten your code to use async/await
for handling the process. Please refer to it for guidance.
$w("#button4").onClick(async (event) => {
try {
const ordersList = await orders.listCurrentMemberOrders();
if (ordersList.length === 0) {
console.log("No orders found.");
return;
}
console.log("Your orders:", ordersList);
} catch (error) {
console.error("Error fetching orders:", error);
}
});
Also, I believe this process requires the user to be logged in for it to execute. 
1 Like