wp-graphql-woocommerce icon indicating copy to clipboard operation
wp-graphql-woocommerce copied to clipboard

Bug: productCategories could not be detected with different IDs in wp_term_taxonomy table

Open realsamanrad opened this issue 2 years ago • 3 comments

WP-GraphQL-Woocommerce can't detect the product categories with different term_id and term_taxonomy_id IDs in wp_term_taxonomy table.

By default, the term_id and term_taxonomy_id have the same ID value in wp_term_taxonomy table. For example:

term_taxonomy

term_taxonomy_id term_id taxonomy
1 1 product_cat
2 2 product_cat
3 3 product_cat

This works in WP-GraphQL-Woocommerce:

{
    "data": {
        "product": {
            "name": "Test",
            "productCategories": {
                "nodes": [
                    {
                        "name": "Foo",
                        "databaseId": 1

                    },
                    {
                        "name": "Bar",
                        "databaseId": 2
                    }
                ]
            }
        }
    }
}

But in some situation, The table's auto increment may be asynchronous and the term_id and term_taxonomy_id may have different IDs:

term_taxonomy_id term_id taxonomy
3 1 product_cat
4 2 product_cat
5 3 product_cat

In this case, the productCategories could not be detected by the wp-graphql-woocommerce:

{
    "data": {
        "product": {
            "name": "Test",
            "productCategories": null
        }
    }
}

Plugin Versions

  • WooGraphQL Version: 0.10.6
  • WPGraphQL Version: 1.6.11
  • WordPress Version: 5.8.3
  • WooCommerce Version: 6.1.0

realsamanrad avatar Jan 13 '22 15:01 realsamanrad

@samyrooster This is most likely an issue with the connection resolver here.

Do you know of a way to recreate your scenario?

kidunot89 avatar Jan 13 '22 21:01 kidunot89

@kidunot89 This issue is also the same about productTags and product_tag taxonomy.

There is no problem in Woocommerce main plugin and its functionalities. But just in wp-graphql.

I don't know how the terms made and stored. Because it's an old database from some years ago.

realsamanrad avatar Jan 14 '22 08:01 realsamanrad

@kidunot89 iirc you can replicate this by creating a a category and a product cat with the same name. The term id is shared by any terms with the same name regardless of tax, while the term tax id is unique to the term+tax combo

justlevine avatar Jan 15 '22 11:01 justlevine