I have an issue where the variants and the Shopify support advised me to ask my question here, so I hope to find a solution for my issue.
My problem is that the variants of a product are returned only when the variant title matches the search query. Otherwise, the variants array is empty. For my custom design, I need to have the id of the first_or_default_variant. To better explain this, I will post some pictures with examples. For my test, I will be using the default Debut theme demo.
1. When you search for a product title "Backpack" as you can see the variants array is empty.
2. When you search for the title of a variant "Navy" and the search is configured to check the variant titles, the variant array is filled with the matched variant.
3. Now following this logic, if you search for the word "Default", you will get the list of all products with just the default variant.
So does anyone think this is an issue with the returned results and have an idea of how to get the id of the first variant every time.
Thank you all in advance.
Unfortunately, I got no reply from Shopify support or here in the forums. The only workaround I have been thinking of is to get the product by handle via the public api (Shopify.getProduct) and from the returned object to get the variants, but it is far from a perfect solution. So not much we can do here.
Hope that helps.