Checkout UI Extension - detect oversold / back-order items

Hiya,

I’m creating a Checkout Extension which I only want to show when one or more items in the cart have oversold (their resulting inventory is or will be less than 0) this will be for Back-Orders i.e. variants with a ‘Continue selling when out of stock’.

Currently I’m doing this by grabbing all of the Unique Variant IDs and doing a Storefront API lookup, but.. I can’t find a way to do it based upon the Buyer Context (Company Location), which could impact things - as the Customer Token (from what I can see) isn’t available.

Secondly, I feel like I should be querying the cart, rather than the variants separately - but there doesn’t seem to be a way to fetch the Cart ID either..

query VariantData($country: CountryCode! $variantIds: [ID!]!) @inContext(country: $country) {
    nodes(ids: $variantIds) {
        ... on ProductVariant {
            title
            currentlyNotInStock
            quantityAvailable
            product {
                title
            }
        }
    }
}

So, is there a better way to achieve this?

Thanks in Advance

Hey @ceri_waters

Is this currently achieving what you need (checkout extension only being displayed when a cart item <0), but you’re looking for a more robust approach, or the approach you’ve described is not working at all?

Hi @Liam-Shopify thanks for the response.

The query above is working but..

  1. I can’t do things based on the Buyer Context (B2B) - which could potentially impact things. (No Customer Token)
  2. It feels really “hacky” to lookup the Variants Data this way. I’m curious if there’s a way to do a ‘cart’ Storefront Query (and supplement the data that way) but alas no Cart ID (unless I’m being blind) cart - Storefront API

Thanks!

Thanks for the added context - to be honest I have not come across this specific usecase previously. Hopefully other devs in the community with have advice to share :slight_smile:

1 Like