I am useing shopify Storefront API to create an ecommerce website. When i create a cart with cartCreate mutation, i get an cart id, the graphql mutation is given below:
mutation createCart($input: CartInput!) {
cartCreate(input: $input) {
cart {
id
}
}
}
I can use the cart id to get the cart details. the graphql guery is given below:
query {
cart(
id: "gid://shopify/Cart/1"
) {
id
createdAt
updatedAt
lines(first: 10) {
edges {
node {
id
quantity
merchandise {
... on ProductVariant {
id
}
}
attributes {
key
value
}
}
}
}
attributes {
key
value
}
cost {
totalAmount {
amount
currencyCode
}
}
buyerIdentity {
email
phone
}
}
}
but the problem is, when a user logout or change device then there is any way to get the cart ID using a Customer token or other way, sothat i am able to get the cart details.
2
Answers
Once the user is authenticated, you can use the Storefront API’s customer query to fetch the customer’s cart information. Specifically, you’ll need to query for the id of the cart. Here’s an example GraphQL query,
(Replace "YOUR_CUSTOMER_ACCESS_TOKEN" with the actual customer access token of the logged-in user):
customer
object does not havecart
object.https://shopify.dev/docs/api/admin-graphql/2023-07/objects/Customer