(2024)Adding Products to Cart addToCurrentCart( ) function not working?

Okay so this is from Velo documentation, basically the product is not being added to the cart.lineItems array, in short, not being added to cart. I tried to copy and paste everything here however it’s still not adding to lineItems so just wanna know why that is, considering that this is the updated function as written for adding products to cart:

https://dev.wix.com/docs/velo/api-reference/wix-ecom-backend/current-cart/add-to-current-cart

hey Panda :slight_smile:
have you managed to find the issue?

I found the solution, roughly this code should works

wixData.query("Stores/Products")
    .eq("slug", slug)
    .find()
    .then((results) => {
        // Custom add to cart button
        $w("#addToCart").onClick(async () => {
            const size = getState("selectedSize")
            const color = getState("selectedColor")

            // Filter Variant
            const variant = await wixData.query("Stores/Variants")
                .eq("variantName", `${size} | ${color}`)
                .eq("productName", product.name) // to make sure selected variant on the current page
                .find()
            const body = {
                lineItems: [{
                    catalogReference: {
                        appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
                        // ProductId
                        catalogItemId: product._id,
                        options: {
                            // VariantId should be array no 0
                            variantId: variant.items[0].variantId
                        },
                    },
                    quantity: 1,
                }, ],
            }
            addCart(body).then(result => {
                console.log({ result, body }) // make sure the cart updated
            }).catch(err => console.log(err))
        })
    })