Add to Cart from Database

I’m trying to simulate a repeat order functionality by maintaining a database containing customer’s last order.

Now on the page that extracts the data, i cant seem to get all data to load to cart. Below is the code i used.

I already used async and await on each line, tried query.then but still cant seem to get the behavior needed, sometimes only 1 or two products are added.


$w.onReady( async function (event) {
const results = await wixData.query(“LastOrder”)
.eq(“userId”, “28b79157-05c1-420d-955f-a39c0d33959f”)
.limit(15)
.find();
await addItems(results.items);
});

async function addItems(items)
{
await items.forEach( async item =>
{
await $w(‘#shoppingCartIcon1’).addToCart(item.productId,item.qty);
} );
}