Shopify.getCart() returns undefined but open a alert message with cart item count

tsuj
Shopify Partner
46 0 4

I am trying to get product info that is added to cart. Shopify.getCart() function returns undefined but opens an alert message saying "there is 1 item in the cart". How to get the cart details using this? any help appreciated Screenshot 2019-07-16 at 2.17.46 PM.png

Replies 3 (3)
Jesse_Michel
Shopify Expert
21 0 6

Hey @tsuj. Thanks for this question! I had the exact same one. Did you ever get this sorted out?

 

I can call the function but it always alerts the value, I just want to set it to a variable!

- Jesse Michel | Shopify Expert
tsuj
Shopify Partner
46 0 4

Turns out it's actually useless unless you do any tweak on the theme. I have used the ajax API for the same functionality. It's pretty flexible. 

MathewsJoseph
Shopify Partner
4 0 3

Shopify.getCart() returns a promise. So, you can use the following to get data:
Shopify.getCart(function (cart){

//here you have the cart object.

console.log(cart);

})

 

This won't fire up the alert.