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

`set_page_by_path` on Product resolver returns wrong post id (WPML specific)

Open leftis opened this issue 4 years ago • 2 comments

Describe the bug This might not be a bug & more something like a feature request or a question regarding how i should handle it.

Using WPML for translations and the same slug on both translations, when i try to resolve product through graph the response is always the first translation.

This happens on whatever idType i choose to resolve with (slug, databaseId, sku, etc).

After some research i found that on interafe/class-product.php on the product resolver especially for slug the get_page_by_path is used but this function according to wpml doesn't return the appropriate content and neither does any other idType.

I figured out that by applying a wpml filter right after the $post = get_page_by_path( $id, OBJECT, 'product' );

i am able to get the content i need from wpml $product_id = apply_filters('wpml_object_id', $post->ID, 'product' );

but i want to figure out the correct way of doing it and not touching the plugin code, is there any way to override the resolver on functions.php or another way i could get the appropriate product content the right way?

When resolving for a collection of products then the translations work just fine.

Thanks

To Reproduce Steps to reproduce the behavior:

  1. Install WPML
  2. Install both graph plugins needed
  3. translate a product
  4. make a call to get the product, keep in mind that you should alter the graphql to include the lang parameter

endpoint:graphql?lang=el query that fails:

query MyQuery {
    product(id: <the_slug_here>, idType: SLUG) {
      name
    }
}

Expected behavior Get back the translated content instead of the original one

leftis avatar Dec 12 '20 08:12 leftis

@kidunot89 so any idea? :) Please...

leftis avatar Dec 16 '20 09:12 leftis

Please guys anyone, how should i handle this situtation. Is there any way to override this on my wordpress functions.php or another file?

leftis avatar Dec 30 '20 14:12 leftis