Intercept product listing and reorder

TDTron
New Member
1 0 1

Hi, 

I'm trying to build an app where the product listing can have its order dinamically changed.

For instance (silly example), when a user clicks on a category, the app intercepts the search call (backend) and sorts the products based on the predominant color in their images, then returns the new sorted listing to the user (for the user it's transparent).

Is there any way to intercept this backend fetching of the products and modify it somehow? 

I know I can include a JS tag with the admin API but that would run after the page is loaded + I would have to somehow parse the website to check what products are listed, which I imagine can change if the store has a custom theme for instance (unless there is an API I'm missing).

Another option might be using a Theme, but as far as I can tell, I'd have to define the whole template, not just the part where I'm sorting (+ the user can't have two themes at the same time).

 

Thanks in advance !