user1736357
user1736357

Reputation: 35

Shopify Using Cart Cookie to track cart id

This is cross posted from the shopify api forum-

I have an app that relies on identifying the cart order as it is created, and then matching up that id with any order that comes in (assuming that a cart ultimately becomes an order). Per @HunkyBill's advice, this is accomplished by reading the 'cart' cookie. This does work, however it seems like a fragile way to do something that seems like it should be done with the cart object. I have two questions:

What happens if the user has cookies turned off (is there no way then to access cart id while it is still a cart.. pre-order)?

and

Is it possible to simply add the CartId as a variable to the cart object?

Every other object has its own id, which can be accessed through Liquid... EVERY one. Except for the cart object- which is the ONLY object that links directly to another object, the Order. I do fully understand that Shopify may need a cookie variable to perform some of its functionality- and I am not suggesting modifying that process in any way. However the addition of the Cart Id to the cart object would solve all of these issues (for app developers) and provide a simple way to line up cart activity with converted orders. It also would not affect any products already built using the cart cookie.

If there is a better solution/technique for identifying a cart and then later associating it with a order, I am all ears. I am a bit stunned that this critical functionality (essentially tracking conversion) is not handled in a more robust and consistent way.

Upvotes: 0

Views: 4064

Answers (1)

David Underwood
David Underwood

Reputation: 4966

If the user has cookies turned off, then you're hosed regardless. They won't be able to build a cart without the session id from the cookie.

For the cart: You're correct, on the front end the liquid cart object doesn't have the token included. It's only available through the cookie.

This is for a couple of reasons for the omission:

  • First, there's only ever one cart active in a view at the time, so there's no need to differentiate it while rendering a page.

  • Second: Within the context of the view, the token is meaningless. The user is never going need to see it.

Personally I don't buy the argument that relying on cookies for data is fragile. Indeed, the cart variable that pops up in liquid is loaded based on the session id found in the very same cookie.

That said, I can't think of a good reason for it NOT to be included in the liquid object. I'm going to file it as a low priority feature request.

Upvotes: 5

Related Questions