Cart token missing from cart object in snippet

peakengage
Tourist
4 0 3

Hi, we are developing a webpush notification app for abandoned carts. For this, we need to capture the cart token on the front end so we can connect a checkout with a push subscription. Initially, we were able to capture the cart token by inserting a snippet with {{ cart | json }} and that JSON would have the token. Recently we are seeing that cart token is missing from this object. Even if items are added to the cart, the token doesn't show up in the cart object. 

Was there a recent change that has caused this? Is there another way to capture the cart token on the store frontend?

Thanks in advance.

JohnBarton
New Member
2 0 0

We have seen the same issue. The cart object used to contain the token - but since ~ 12th/13th Aughust 2020 it no longer does.

Shopify - please can you confirm that this is no longer available, as oppose to being dropped accidentally?

What alternatives do we have to get access to the cart token from the liquid snippet?

Has anyone else got a workaround?!

0 Likes
peakengage
Tourist
4 0 3

Not really a work around for the liquid snippet, but we switched to using the theme AJAX api to get the cart data.

https://shopify.dev/docs/themes/ajax-api/reference/cart 

Greg_Kujawa
Shopify Partner
1016 83 227

It's disappointing the your original post was 2 weeks ago, yet there is no response from anyone at Shopify. If support calls are redirected to clients posting here then I'd hope a reply would come a bit sooner?

JohnBarton
New Member
2 0 0

Thanks for the response. For reference, this is what we ended up doing as well.

It seems crazy to have to make another API call to get the cart - just to get the cart token, when the cart is already present (just without the token!).

 

Oh well - at least we have a workaround!

0 Likes
_JB
Shopify Staff
Shopify Staff
822 97 178

Hey @JohnBarton @peakengage @Greg_Kujawa,

The behaviour that recently changed on that liquid drop wasn't listed in our documentation, so it's not unexpected for undocumented behaviour to change without notice. Right now the best way to get the token is from cart.js as was already mentioned.

I agree that having the token available in the liquid drop is a better solution than having to make an AJAX call, I'll bring this up with our teams to see whether it's possible to have this added as an officially documented liquid attribute.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
_JB
Shopify Staff
Shopify Staff
822 97 178

Hi all,

Just wanted to follow up here. I've received clarification that the token property was intentionally removed from the cart liquid drop object earlier this year. The decision to remove it was related to storefront performance and how our infrastructure handles caching, and was necessary to allow other projects to ship. It was removed without notice since it wasn't documented to begin with, so for now the best way to get the token is through the AJAX call. I've provided feedback on the change either way, so our teams have this information for if/when there's an opportunity to implement this again in the future.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

jeffse
Shopify Partner
2 0 1

This may also be an unsupported way to get at the cart token, but it seems to be available under the "cart" cookie.