addToCart not adding all products from custom collection to cart

I have a requirement where I create ’ hampers ’ of products which customers can order in one shot. For this, I have setup a custom collection called Hampers and have referenced Stores/Products as below. I know that the screenshot says Sandbox but my data has been synced to Live.


I am not using wix Stores/Collections for this purpose because I don’t know how to add ALL products from a wix Stores/Collection to the cart. (Here’s a separate question explaining why I’m not using a Stores/collection.)

I have a dynamic category page which shows users all the available hampers. Clicking on one hamper takes the user to the hamper details page.

You can see an example of the this flow @ https://chicshop.in/hampers

In the details page, I have an “Add Hamper to Cart” button which should add all items in the hamper into the cart. This is where I have an issue.

The code randomly adds some arbitrary subset of items from the hamper into the cart but not all items. You can try out this behavior as below.

  1. From https://chicshop.in/hampers go into the Healthy Foods Hamper

  2. Click the Add Hamper to Cart button

  3. Notice that all the items from the hamper will not be added to the cart
    Here’s my code:

export async function button1_click(event) { //button1 is the “Add Hamper to Cart” Button
//Add your code for this event here:
let hamper = $w(“#dynamicDataset”).getCurrentItem();
await wixData.query(“Hampers”).eq(“_id”, hamper._id).include(“products”).find()
.then( function (x) {
return x.items.length > 0? x.items[0].products:;
})
.then(hamperProducts => {
hamperProducts.forEach( async p => {
await $w(‘#shoppingCartIcon1’).addToCart(p._id, 1, {})
.then(p2 => {
console.log(${p._id} was added to cart = ${p2} );
})
. catch (ex => {
console.log(ex)
});
});
})
. catch (e => {
console.log(e);
})
}

Note that in the console logs, I get as many success messages as there are products in the hamper like so.

bed55500-c851-7240-942b-4cf0e8a2e456 was added to cart = true
bafc2d0e-d3f2-9610-370e-86eb53338880 was added to cart = true
33611589-4cf0-3dde-4fcb-285953422591 was added to cart = true
698c9f03-4279-b05f-d023-5b0c21a763ad was added to cart = true

Any ideas on what could be going wrong?