Skip to content

How to get products with category filter logic #63

Answered by ericingram
jezzzm asked this question in Help
Discussion options

You must be logged in to vote

@jezzzm It looks like there's no simplified way to do the $and/$or logic you need, but you can fetch the sub-categories and make the query work as you described.

There is a special operator on the product model that does retrieve products from sub-categories of a parent, but it doesn't support your mix of logical operators (note $in is effectively like $or in this case).

In any case here's how it works:

swell-get('/products', {
  categories: [ 'category1', 'category2', 'category3', ... ]
})

The above will return products in any of those top or sub-categories. Internally the code does something like this:

async function queryByCategoriesDeep(categoryIds) {
  const allCategoryIds = await f…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@jezzzm
Comment options

@jezzzm
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jezzzm
Comment options

Answer selected by jezzzm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants