Predictive Search and Variants returned

SherpasDesign
Shopify Expert
44 0 19

Hi guys,

 

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.

SearchBackpack.png

 

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.

SearchNavy.png

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.

SearchDefault.png

 

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.

 

Best Regards,

Stephen

 

 

0 Likes
JosePila
New Member
3 0 0

Have you figured out a workaround for this? I've been trying to build a search functionality with quick add to cart & it isn't working for me because of the empty variants array.

0 Likes
SherpasDesign
Shopify Expert
44 0 19

Hi Jose,

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.

Regards,

Stephen

 

0 Likes
JosePila
New Member
3 0 0

I guess this solution would involve making a separate call for every product returned by the predictive search API?

0 Likes
SherpasDesign
Shopify Expert
44 0 19

Hi Jose,

Yes. You will need to make a separate call for each product returned. Then use the variants as you need and most probably re-initialize any ajax add to cart or other features you want to have.

Hope that helps.

 

Best regards,

Stephen

0 Likes