We currently use the predictive search API to power the main search on our stores.
When a user starts typing, we return a list of 10 matching products showing the min and max price for a collection
e.g. Item Name [ $0.30 - $10.50]
The min and max prices are obtained from the price_min and price_max fields in the returned products.
However, we've had some complaints as these min and max prices are for all variants and not just those in stock. So a customer clicks seeing a minimum price of $0.30 but finds the cheapest available product is $3.00.
I thought that I would be able to work around this by iterating over the variants in the returned products (looking for those where available was true and grabbing the price). However the variants array doesn't return all variants for a product, just the closest match (if any) to the search term.
I would appreciate some guidance as to either:
- if there is any way to modify the predictive search query so that the price_min and price_max fields only contain prices for in-stock variants
- if there's a way to get all the variants for a product listed in the response.