How can I manipulate a checkout created with the Storefront API using cart.js when in checkout flow?

kyleparade
New Member
5 0 0

We're on Plus and have a customized checkout.liquid wherein we offer an in-checkout product upsell. This works by using cart.js endpoints to add the product/variant to cart. However, we noticed when creating and redirecting to checkouts created using the Storefront API, cart.js still updates the *main site cart* and not the checkout cart (i.e. line items).

I don't see in the docs how to change the checkout/cart contents for the *current* checkout. Any insight is appreciated.

Replies 4 (4)

CalD
Shopify Staff
140 22 36

Hey @kyleparade!

Have you looked at the the checkoutLineItemsReplace (/Add/Remove/Update) mutations in the Storefront API yet?

CalD | 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

kyleparade
New Member
5 0 0
Hey there. Not quite what I was asking. My question was how I can
manipulate the cart/checkout present when you visit our site. The API
created checkout is a different checkout. The API docs aren’t clear how to
target one or the other.

kyleparade
New Member
5 0 0

Any ideas? This is specifically to be able to manipulate the cart/checkout you would access by browsing our storefront, *not* a checkout created via API. The cart.js blocks cross origin requests even from a subdomain of our store, so that won't work. Looking forward to your reply.

CalD
Shopify Staff
140 22 36

Hey @kyleparade,

I don't believe this is possible. Check out this similar forum thread: https://community.shopify.com/c/Shopify-APIs-SDKs/How-do-I-use-the-AJAX-API-in-a-headless-Shopify-Re...

 

CalD | 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