Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I'd like to ask how long the checkout object created with Storefront API exists.
I'd like to create checkout object using storefront API and keep the object ID in my localstorage
My goal is to get total price where discount code is applied.
To do this, I create checkout object, add line items there and apply discount. So three GraphQL calls are being made, which are too slow to get final price.
Is it possible to create checkout object only once per web session and keep in localStorage?
Solved! Go to the solution
This is an accepted solution.
Hey @paulcooksome
To do this, I create checkout object, add line items there and apply discount. So three GraphQL calls are being made, which are too slow to get final price.
You should be able to do this with a single call:
mutation createCart($cartInput: CartInput) {
cartCreate(input: $cartInput) {
cart {
id
checkoutUrl
lines(first: 10) {
edges {
node {
id
merchandise {
... on ProductVariant {
id
}
}
}
}
}
cost {
totalAmount {
amount
currencyCode
}
}
}
}
}
Variables:
{
"cartInput": {
"lines": [{...}],
"discountCodes": ["code"]
}
}
It's ok to keep the cart ID in local storage, but given the cart might change (discounts, line items, etc) it's probably best to look up the cart each time to confirm prices and retrieve the checkout URL.
I believe checkouts live for ~3 months.
Scott | Developer Advocate @ Shopify
This is an accepted solution.
Hey @paulcooksome
To do this, I create checkout object, add line items there and apply discount. So three GraphQL calls are being made, which are too slow to get final price.
You should be able to do this with a single call:
mutation createCart($cartInput: CartInput) {
cartCreate(input: $cartInput) {
cart {
id
checkoutUrl
lines(first: 10) {
edges {
node {
id
merchandise {
... on ProductVariant {
id
}
}
}
}
}
cost {
totalAmount {
amount
currencyCode
}
}
}
}
}
Variables:
{
"cartInput": {
"lines": [{...}],
"discountCodes": ["code"]
}
}
It's ok to keep the cart ID in local storage, but given the cart might change (discounts, line items, etc) it's probably best to look up the cart each time to confirm prices and retrieve the checkout URL.
I believe checkouts live for ~3 months.
Scott | Developer Advocate @ Shopify