Re: How to associate a cart with an order?

How to associate a cart with an order?

dylanpierce
Shopify Partner
277 13 120

Hello,

We're porting our app's `ORDER_STATUS` script tag over to a Checkout UI Extension. The app updates the cart's attributes, and we'll need to sync those same fields to the order's metafields.

The final problem we need to solve is updating the order with details collected from the Checkout UI Extension.

How are you supposed to be able to associate a cart with a specific order? There's no `cartToken` attribute for an order in the Admin Order GraphQL API, and the `cart_token` field is deprecated on the REST Order API.

Is there some other method of associating carts with orders? Or is this an oversight by the API design?

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.

Replies 11 (11)

SBD_
Shopify Staff
1831 273 418

Hey @dylanpierce 

 

Checking with the Checkout UI folks and will report back.

Scott | Developer Advocate @ Shopify 

SBD_
Shopify Staff
1831 273 418

Hey @dylanpierce 

 

From the Checkout UI team:

 

---

 

Scott | Developer Advocate @ Shopify 

dylanpierce
Shopify Partner
277 13 120

Hi @SBD_ 

> Could they use the `checkoutToken`?

Technically for now, yes. But the issue is this field is deprecated, so we can't build around this `checkout_token` property that is being removed in future API versions for the Admin Order REST API:

CleanShot 2024-01-30 at 06.32.32@2x.png

 

or even the attributes API directly?

I couldn't find cart attributes on the order, but it does look like you can leave metafields. So we'll have to generate our own unique token, store it as a metafield, and that would be the connection between our databased stored pre-checkout details and the order.

We're experimenting with this approach now, but seems like a workaround for what `cart_token` or `checkout_token` were supposed to do. Not sure why they're being removed.

Founder of Real ID - Verify your customer's real IDs easily & securely with modern A.I.

Want to see it in action? Check out our demo store.

SBD_
Shopify Staff
1831 273 418

Thanks @dylanpierce - passing along your feedback.

Scott | Developer Advocate @ Shopify 

MathewsJoseph
Shopify Partner
7 0 4

@SBD_ We're also trying to figure out this issue. We're using the checkout token for the time-being, but we can't rely on it since it's due for removal. There are no other keys on the checkout or order which is unique across all orders which we can use to identify the order down the line. Checkout token was solving the issue pretty neatly.

Bloggle_team
Shopify Partner
18 0 0

We also have the issue for our app. Does your team really want to remove checkout_token without any alternative?

the_h
Shopify Partner
9 0 2

We also depend on the `checkoutToken` being kept alive. There is no other way to smoothly identify an order from the Thank You extension on our backend.

 

I would imagine removing the `checkoutToken` will affect thousands of stores so if it is going ahead a replacement value would be vital.

SBD_
Shopify Staff
1831 273 418

Thanks everyone. Passing along your feedback.

Scott | Developer Advocate @ Shopify 

SBD_
Shopify Staff
1831 273 418

From the Checkout Extensibility folks:

The original post trying to solve associating a cart with an order, we suggest writing cart attributes, reading those during checkout, then saving them to order metafields during checkout. Their app already writes cart attributes so this still seems like the best solution. 

For others, there are a few alternatives: cart attributes (for Online Store), cart metafields (for headless), order metafields, etc.

@MathewsJoseph@the_h@Bloggle_team, please let me know if this doesn't cover your use case so I can provide more feedback.

Scott | Developer Advocate @ Shopify 

lasse-contribe
Shopify Partner
2 0 0

Hey SBD, what about cases where cart attributes are discarded - like express checkout and "Pay Now" functionality where there is no cart?

airnote
Shopify Partner
14 0 1

Please don't deprecate or remove checkout and cart token from order. core of our app functionality depends on it.