Js-buy-sdk: Uncaught (in promise) TypeError: Cannot read property 'checkoutLineItemsAdd' of undefined

Created on 19 Apr 2018  路  4Comments  路  Source: Shopify/js-buy-sdk

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

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 not 1
it was a type casting issue smh

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings