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

Category filtering not working in some specific queries. #730

Open
lbenevento opened this issue Apr 14, 2023 · 2 comments
Open

Category filtering not working in some specific queries. #730

lbenevento opened this issue Apr 14, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@lbenevento
Copy link

lbenevento commented Apr 14, 2023

Describe the bug
The category filter on products doesn't work in some use cases. Specifically when trying to retrieve products using the query related to a product attribute.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new product attribute.
  2. Query the products using the subfield of your paYourProductAttribute query.
  3. Try to filter by category.
  4. See error (hopefully)

Expected behavior
The filter should work no matter where it's applied (unless I'm missing something).

Plugin Versions

  • WooGraphQL Version: 0.12.1
  • WPGraphQL Version: 1.14.1
  • WordPress Version: 6.2
  • WooCommerce Version: 7.6.0

Additional context
Those are some example queries ran on my end:

Operation:

query Categories {
  productCategories {
    nodes {
      slug
      databaseId
    }
  }
}

Results in:

{
  "data": {
    "productCategories": {
      "nodes": [
        { "slug": "fruits", "databaseId": 23 },
        { "slug": "uncategorized", "databaseId": 16 },
        { "slug": "vegetables", "databaseId": 22 }
      ]
    ...

Operation where category filters are working:

query CategoryFiltering_Working {
  products(where: {categoryId: 23}){
    nodes {
      productCategories {
        nodes {
          slug
          databaseId
        }
    ...

Results in (result cut but the complete version indeed contains just the products with the correct category):

{
  "data": {
    "products": {
      "nodes": [
        {
          "productCategories": {
            "nodes": [{ "slug": "fruits", "databaseId": 23 }]
          }
        },
        {
          "productCategories": {
            "nodes": [{ "slug": "fruits", "databaseId": 23 }]
          }
        }
     ...

Operation where category filters are NOT working.

query CategoryFiltering_NotWorking {
  paSellerid(id: "dGVybToyMA==") {
    products(where: {categoryId: 23}) {
      nodes {
        productCategories {
          nodes {
            slug
            databaseId
          }
    ...

Results in (again, cut to avoid useless code but it's enough to notice that even the first product has the wrong category):

{
  "data": {
    "paSellerid": {
      "products": {
        "nodes": [
          {
            "productCategories": {
              "nodes": [{ "slug": "vegetables", "databaseId": 22 }]
            }
          }
    ...
@kidunot89
Copy link
Member

kidunot89 commented May 16, 2023

@lbenevento and the product queried isn't under both the vegetables and fruits categories? Because where.categoryId param on the ProductAttribute.products connection will only filter the products not their productCategories.

@kidunot89 kidunot89 added the awaiting author response Awaiting response from Issue/PR author label May 19, 2023
@lbenevento
Copy link
Author

lbenevento commented May 21, 2023

Thank you for the answer but I'm not sure I got what you mean.
Anyway no product has both categories and the queried product's category is visible in the example queries I posted!

@kidunot89 kidunot89 added bug Something isn't working and removed awaiting author response Awaiting response from Issue/PR author labels May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants