spree/spree — pull request #4662 by radar (2014-05-08 06:25:50+00:00)
Title: WIP: Adding retrieve_variants to the Searcher API

Based on some feedback from some of our clients and my own personal experience, the search features provided by `/api/variants` are a bit lacking. This is the endpoint used on the product picker in the admin backend, btw (but you probably knew that already).

There's currently no "neat" way to hook into Spree and define some better searching for variants like there is for products. I propose that the `Spree::Core::Search::Base` class needs to define an API for variant searching, and this patch hints at the kind of API I would expect. The caveat is that this API differs from `retrieve_products` in that it doesn't build the scope inside the method, but rather the scope is provided to it and then it can do searching based on whatever `params[:q]` is.

I'm on the fence about adding a `retrieve_variants` method to `Spree::Core::Search::Base` which has a different API and different functionality to that of the `retrieve_products` method there. It *feels* like I'm trying to squish too much into that one class.

---

So here's what I was thinking: let's keep `Spree::Core::Search::Base` but move all the product searching logic into another class, called `Spree::Core::Search::Product`. Then we could have another class called `Spree::Core::Search::Variant` and I'd be able to define my `retrieve_variants` method in there if I so pleased.

How does this sound?