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

Get Products by taxonomyFilter - Multiple Terms #821

Open
Kapitan-Nemo opened this issue Dec 7, 2023 · 2 comments
Open

Get Products by taxonomyFilter - Multiple Terms #821

Kapitan-Nemo opened this issue Dec 7, 2023 · 2 comments
Labels
question Further information is requested

Comments

@Kapitan-Nemo
Copy link

Kapitan-Nemo commented Dec 7, 2023

I just want to simple pass more than one terms to get all products related to my taxonomy PA_COLOR.
Passing many terms: ["zielony", "kremowy"] gives me always only products for first term "zielony"

query getProducts {
  products(
    where: {taxonomyFilter: {filters: {taxonomy: PA_COLOR, terms: ["zielony","kremowy"]}}}
  ) {
    nodes {
      name
      ...SimpleProduct
    }
  }
}

fragment SimpleProduct on SimpleProduct {
  name
}
Zrzut ekranu 2023-12-7 o 18 39 08

What i do wrong?
Any help appreciated :)

@kidunot89
Copy link
Member

Ensure that the products all utilize global product attributes.

@kidunot89 kidunot89 added the question Further information is requested label Dec 12, 2023
@imdimasan
Copy link

imdimasan commented Apr 27, 2024

I found the solution. I don't know why it's not described, but you need to pass ids of terms. So first of all, get all terms ids, like so:

query GetFrameIds {
  terms(last: 9999) {
    nodes {
      ... on PaFrame {
        name
        databaseId
      }
    }
  }
}

Then add these IDs to array, like [10, 11, 12, 13, ...], after that you can add this arrray to your filtering query. Moreover, you may combine multiple taxanomies, like so:

  products(
    where: {
      taxonomyFilter: {
        relation: OR,
        filters: [
          {
            taxonomy: PA_LENS,
            terms: ["Black", "Red"],
            ids: [127, 133]
          },
          {
            taxonomy: PA_FRAME,
            terms: ["Nylon"],
            ids: [74]
          }
        ]
      }
    }
  ) {
    nodes {
    ...
  }
}``` 
  
  Don't forget to use relarion files properly (OR / AND).
  Happy codding!

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

No branches or pull requests

3 participants