wp-graphql-woocommerce
wp-graphql-woocommerce copied to clipboard
`set_page_by_path` on Product resolver returns wrong post id (WPML specific)
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:
- Install WPML
- Install both graph plugins needed
- translate a product
- 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
@kidunot89 so any idea? :) Please...
Please guys anyone, how should i handle this situtation. Is there any way to override this on my wordpress functions.php or another file?