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

Highlighted
Shopify Partner
46 0 3

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

0 Likes
Highlighted
Shopify Expert
15 0 2

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
0 Likes
Highlighted
Shopify Partner
46 0 3

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. 

0 Likes
Highlighted
Shopify Partner
4 0 1

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.

0 Likes