Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

tRe: Cart token missing from cart object in snippet

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.

banned
Replies 7 (7)

JohnBarton
Shopify Partner
9 1 2

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?!

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 

banned
Gregarican
Shopify Partner
1033 86 292

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
Shopify Partner
9 1 2

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!

_JB
Shopify Staff (Retired)
836 100 223

Hey @JohnBarton @peakengage @Gregarican,

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 | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

_JB
Shopify Staff (Retired)
836 100 223

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 | Solutions Engineer @ Shopify 
 - 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.