New Shopify Certification now available: Liquid Storefronts for Theme Developers

How long checkout object exists?

Solved
paulcooksome
Shopify Partner
1 0 0

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?

 

Accepted Solution (1)
SBD_
Shopify Staff
Shopify Staff
1671 235 344

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 

View solution in original post

Reply 1 (1)
SBD_
Shopify Staff
Shopify Staff
1671 235 344

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