Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter a product by nested object array values #56

Closed
tiavina-mika opened this issue Jan 11, 2022 · 2 comments
Closed

Filter a product by nested object array values #56

tiavina-mika opened this issue Jan 11, 2022 · 2 comments

Comments

@tiavina-mika
Copy link

I have a products like this:

[
  {
    name: 'Product 1',
    attributes: {
      width: '15',
      minimum_required_images: '1',
      height: '20',
      channels: ['web', 'mobile']
    }
  },
    {
    name: 'Product 2',
    attributes: {
      width: '25',
      minimum_required_images: '2',
      height: '30',
      channels: ['mobile']
    },
  }
]

I want to filter it by a channel or list of channels,
for ex. I want to list only products with channels : ['mobile']

how should I achieve this?

@ericingram
Copy link
Contributor

With Swell.js, you can filter products by attributes using the following syntax:

await swell.products.list({
  $filters: {
    channel: ['mobile']
  }
})

See more examples in the docs https://developers.swell.is/frontend-api/products#filtering

@tiavina-mika
Copy link
Author

tiavina-mika commented Jan 12, 2022

It worked.
Another workaround is:

await swell.products.list({
  "attributes.channels": 'web',
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants