Why is this happening im doing everything the docs want me to do?!
var lineItemsToAdd = [{ variant_id: variant.id, quantity: 1 }];
var checkoutId = Cart.data.checkout.id;
Cart.data.client.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => {
// Do something with the updated checkout
console.log('add to cart',checkout.lineItems); // Array with one additional line item
});
gets
Uncaught (in promise) TypeError: Cannot read property 'checkoutLineItemsAdd' of undefined
Double check the key for the Variant ID. In my case it was wrong. It has to be:
const lineItemsToAdd = [{'variantId': variant.id, quantity:1 }]
You also have variant_id instead of variantId
I had the same issue. Passing shopifyId as the variants id seemed to do the trick. Not the variants id (exposed from graphQL in my scenario)
what is the shopifyId that you are referring to? the product objects id?
Update:
In my case all of the id's I was passing were correct, however the function couldn't handle that I was passing quantity as "1" and not 1
it was a type casting issue smh
Most helpful comment
Update:
In my case all of the id's I was passing were correct, however the function couldn't handle that I was passing quantity as
"1"and not1it was a type casting issue smh