I am using the below code above to onReady of a page. The code will add the product to the cart but it is doubling the quantity. For example, when I leave the quantity at 1, 2 of the products are added. When I change to 2, 4 are added.
Thoughts?
cart.getCurrentCart()
.then((currentCart) => {
const cartId = currentCart._id;
const cartLineItems = currentCart.lineItems;
})
.catch((error) => {
console.error(error);
});
const products = [
{
“productId”: “3d5e0fcc-d4fa-5210-aa43-28a7678560eb”,
“quantity”: 1
}
]
cart.addProducts(products)
.then((updatedCart) => {
// Products added to cart
const cartId = updatedCart._id;
const cartLineItems = updatedCart.lineItems;
})
.catch((error) => {
// Products not added to cart
console.error(error);
});