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

[release 0.6.1] Querying a Custom Taxonomy on Product will list all terms, not just the ones associated to the product #348

Closed
ardiewen opened this issue Oct 21, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@ardiewen
Copy link
Contributor

Describe the bug
I have a custom taxonomy on Product called: Collections.

For collections, I have the terms Spring/Summer, and Fall/Winter.

I have a single product and have assigned the term Spring/Summer to it.

However, when I query the product like so:

{
    products {
        collections {
            nodes {
                name
            }
        }
    }
}

I receive both Spring/Summer and Fall/Winter instead of just Spring/Summer. I believe this is a regression from v0.5.1 since the expected behaviour was to return only the linked terms of the taxonomy.

@ardiewen
Copy link
Contributor Author

Swapped over to the develop branch of the plugin with #346 applied and the opposite is actually happening now.

When querying a custom taxonomy, like above, the result is an empty array of nodes even when there are terms associated with the product. E.g.

Query:

{
  products {
    nodes {
      collections {
        nodes {
          name
        }
      }
    }
  }
}

Result:

{
  "data": {
    "products": {
      "nodes": [
        {
          "collections": {
            "nodes": []
          }
        },
        {
          "collections": {
            "nodes": []
          }
        },
        {
          "collections": {
            "nodes": []
          }
        },
        {
          "collections": {
            "nodes": []
          }
        },
        {
          "collections": {
            "nodes": []
          }
        },
        {
          "collections": {
            "nodes": []
          }
        }
      ]
    }
  }
}

@jacobarriola
Copy link
Contributor

@ardiewen I think I see the issue with my PR. I mistakenly assumed all requests coming through would be $attributes, not taxonomies.

@kidunot89 Using get_the_terms() works better for this issue and my issue. Want me to get another PR rolling?

$resolver = new TermObjectConnectionResolver( $source, $args, $context, $info, $tax_object->name );

$terms = wp_list_pluck( get_the_terms( $source->ID, $tax_object->name ), 'term_id' );

$resolver->set_query_arg( 'term_taxonomy_id', ! empty( $terms ) ? $terms : array( '0' ) );

return $resolver->get_connection();

@jacobarriola
Copy link
Contributor

@ardiewen I've got the PR up, so hopefully it solves both of our issues once it's merged in. It's testing good for me (both attributes and product categories).

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

3 participants