Shopify Graphql how to get available products for specific collection based on location
It is true. Variants do not in fact have a location. But they do have an inventory item ID. And when you leverage that, you'll find you can get the inventory levels of any particular inventory item ID at locations.
So if you were to extract the availability of an item at a location, ie) a variant, you would also know that the product the variant belongs to, is stocked at that location.
Your approach of starting with a collection, and then getting the products in that collection, and then getting the variants of each product, and then checking if the variant is stocked at one or more locations, is really really clunky.
I think instead you should extract the inventory at each location. That would then give you products. With those products you might be able to create a collection to hold them. But since location is not a criteria, you're going to have to make up something.
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.