Checking product stock level at checkout

Is there any checkout API (functions, extensions, etc) that can determine if a product is in stock?

Maybe I overlooked something obvious, but I have been stuck on this for a bit.

Hey @Tyler_Fleming , you should be able to use the Storefront API via Checkout UI extensions to query product variant quantities:

The easiest way to grab the variant’s stock info would likely be getting the variant’s SKU through the CartLineItems Checkout Extension API, Cart Lines, and then running a SFAPI query like this:

query getVariantBySku($sku: String!) {
  products(first: 100, query: $sku) {
    edges {
      node {
        id
        title
        handle
        variants(first: 100) {
          edges {
            node {
              id
              sku
              title
              availableForSale
              currentlyNotInStock
              quantityAvailable
            }
          }
        }
      }
    }
  }
}

Hope this helps - let me know if I can clarify anything on my end here!

Thanks so much, Alan! :raising_hands:

1 Like