#RemoteQuery - filter by linked table

1 messages · Page 1 of 1 (latest)

tawny widget
#

Is it possible to filter by linked table fields in remoteQuery?

For example I want linked attributes table to products table and I want to get all products with specific attribute_id linked to it

robust yacht
#

This cross-module filtering/sorting will come in a few weeks as another module (Index).
At the moment you will have to start querying by your custom module and expand products, or 2 queries.

solemn reef
#

@robust yacht Any idea when the cross-module filtering will be released? Also, Can you give an example of the workaround you mentioned above?

native copper
#

I have solved it by creating my own custom products endpoint (/store/custom-products), it fetches all products and variants including calculated price and then performs filters and sorting using javascript before responding with the edited list. Simple, easy. I will cache the products in the future if this needs to go to production

wispy agate
#

can you provide example?

native copper
#

Sure! This is my entire route.ts linked below. Im building a single language/currency commerce so I have the values defaulted at 65 and 66. Edit as needed or send own values using query params (it does not support region.id). Edit fields on line 77 as needed, you can then see data by console logging on 88 and perform your own logic. SortProducts method is stolen from the nextjs starter template and that is why the data type is overwritten on line 100. But it should be pretty much the same as a store product 🙂 What I like about this is that I dont need to sort my products in my storefront

This is an example call:

API/store/custom-products?limit=12&skip=0&sortBy=created_at

https://pastebin.com/umjiGVUd

solemn reef
#

@native copper Thanks for this, I have also implemented the same but my only worry is that pagination would break with this approach when certain products are filtered out by the filter method in js. I'm not using pagination for my custom route as of now but that's something to solve for production

wispy agate
#

I cannot implement search by first name and last name in order->customer and order->shipping_address, any suggestions?

native copper
wispy agate
#

@native copper any suggestions for search/filtering in customer and shipping address of an order like this?

native copper
#

Whats $ilike? Isnt the operator just $like ?

wispy agate
#

it is for ignoring uppercase

native copper
#

I have no suggestions other than what you already have