A space to discuss online store customization, theme development, and Liquid templating.
Hi !
If my customer had already a cart with products, how can I get this cart for add other product with my custom app ?
In the Storefront API, I seen cart query but with an id (that I don't know) 😕
Kind regards
Hey @Marconino
Your app would need to read the Cart ID - one approach would be to use the AJAX API. Keep in mind cart interoperability is only just starting to roll out (share a cart with Liquid/Storefront API) and wont be available on all stores yet, so it's safest to also update the cart using the AJAX API too.
Scott | Developer Advocate @ Shopify
Hi, thank you for the reply.
I've seen that you can use AJAX API like this : https://shopify.dev/docs/api/ajax#making-requests-to-the-api
But I'm using a Unity webGL application that makes HTTP requests (UnityWebRequest)
Is it possible to use HTTP requests with the AJAX API?
(Sorry if this is a dumb question, I'm a beginner)
Hey @Marconino,
I'm not familiar with Unity webGL, but you'll need the session/cookie to access the cart via AJAX - so I suspect Storefront API will be your best bet!
Scott | Developer Advocate @ Shopify
But it is possible to get current cart of my customer with Storefront API ? 😕
I don't understand how 😔
For more context, I have php script which execute a request to Shopify and I want to get current cart of my customer
Hello @Marconino did you find a way to get the current user cart? i'm facing the same problem.
Hello @scerelli ! I use this code in Javascript for add product to current user cart ! 🙂
(This request is on one of my Shopify pages, if you want to add product from custom app, you have to create a proxy between Shopify and your app)
function addToCart(variantId, quantity) {
let data = {
'items': [{
'id': variantId,
'quantity':quantity
}]
};
fetch('/cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
}
Thanks, it’s the same I’m using. I wanted to find a way to add to cart from the backend as there are important calculations and price cart transformations to be done before adding products to cart, if using my app, but so far I could find a way, only frontend side.
You should to check about Shopify proxy : https://shopify.dev/docs/apps/online-store/app-proxies
In "Proxy URL" you put your url backend like this https://siteweb/add_product_to_cart.php for example, and in this script you use addToCart function !
I will check it out! thanks
is there any API which gets the cart information using the customer token for the user
I'm also facing the same issue, need guidance to get the API which gets the cart information using the customer token for the user, can anyone help me Out
Did anyone get any solution?