All things Shopify and commerce
Iv'e searched high and low on answers how to use add items to Cart. I'm building a headless storefront (challenging, I know), and I need to understand how the items are being added to Cart.
I've look here and see no mentioning of "Cart". My backend for this setup is using the Ruby gem.
Based on how I see carts work, a customer, authenticated or not, can add something to cart, they can refresh their browser and it's still there so something unique is happening and I see no documentation on how to "add to cart".
Solved! Go to the solution
This is an accepted solution.
Hi @MayneWeb
I don't know if this is the exact solution. I'm guessing Shopify manages Cart by storing the information about products in browser cookies and then creates checkout at the backend once the user proceeds for checkout. You can do similarily, here is the doc for storefront checkout API https://help.shopify.com/en/api/storefront-api/guides/checkout-guide#creating-the-checkout
This is an accepted solution.
Hi @MayneWeb
I don't know if this is the exact solution. I'm guessing Shopify manages Cart by storing the information about products in browser cookies and then creates checkout at the backend once the user proceeds for checkout. You can do similarily, here is the doc for storefront checkout API https://help.shopify.com/en/api/storefront-api/guides/checkout-guide#creating-the-checkout
So it seems like you are suggesting that a headless store should maintain and manage their own cart, and only rely on shopify when the user is going to "checkout" and pay... am I clear on that?
it seems @MayneWeb is trying to implement using the shopify native cart. (only product pages are headless, and add to cart ideally sends them to the shopify hosted cart).
This is old but I don't see that the other answers point to a specific solution.
Shopify does manage all the contents of a cart on the backend inside their system.
To add an item to the cart you are doing a mutation to the checkout, this specific API call
checkoutLineItemsAdd here: https://shopify.dev/docs/api/storefront/2023-04/mutations/checkoutLineItemsAdd
I'm using something like this example in javascript here: https://github.com/Shopify/js-buy-sdk/blob/master/src/graphql/checkoutLineItemsAddMutation.graphql
User | RANK |
---|---|
19 | |
17 | |
17 | |
14 | |
13 |
We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023