Closed tonysilva16 closed 2 years ago
Not clear to me. Can you explain in detail:
Also please copy/paste complete code/outputs here.
Based on a comment in the code i was expecting to recieve the raw data in every webhook.
Dealing with webhooks, which should always send information in Raw ML format
This is the webhook payload from a variable product update. The product name is in raw format, but the attributes are translated. In the following payload one of the attributes with the id 25 is called "Cor Traduções" with the following options "Amarelo, castanho, Preto"
EDIT: The expected result would be "[:pt]Cor Traduções 2[:en]Color traductions 1[:]" for the attribute name. Categories name are also translated in the default language. I am not sure about the remaining fields like description, short_description etc.
{"id":3962,"name":"[:pt]ee[:en]123131321[:]","slug":"ee","permalink":"https:\/\/www.****.com\/produto\/ee\/","date_created":"2022-06-01T12:20:03","date_created_gmt":"2022-06-01T12:20:03","date_modified":"2022-06-02T09:55:29","date_modified_gmt":"2022-06-02T09:55:29","type":"variable","status":"publish","featured":false,"catalog_visibility":"visible","description":"","short_description":"","sku":"","price":"213","regular_price":"","sale_price":"","date_on_sale_from":null,"date_on_sale_from_gmt":null,"date_on_sale_to":null,"date_on_sale_to_gmt":null,"on_sale":true,"purchasable":true,"total_sales":0,"virtual":false,"downloadable":false,"downloads":[],"download_limit":-1,"download_expiry":-1,"external_url":"","button_text":"","tax_status":"taxable","tax_class":"","manage_stock":false,"stock_quantity":null,"backorders":"no","backorders_allowed":false,"backordered":false,"low_stock_amount":null,"sold_individually":false,"weight":"","dimensions":{"length":"","width":"","height":""},"shipping_required":true,"shipping_taxable":true,"shipping_class":"","shipping_class_id":0,"reviews_allowed":true,"average_rating":"0.00","rating_count":0,"upsell_ids":[],"cross_sell_ids":[],"parent_id":0,"purchase_note":"","categories":[{"id":15,"name":"Promo\u00e7\u00f5es","slug":"promocoes"}],"tags":[],"images":[],"attributes":[{"id":25,"name":"Cor Tradu\u00e7\u00f5es 2","position":0,"visible":true,"variation":true,"options":["Amarelo","castanho","Preto"]}],"default_attributes":[],"variations":[3963,3964],"grouped_products":[],"menu_order":0,"price_html":"<span class=\"woocommerce-Price-amount amount\"><bdi>213,00<span class=\"woocommerce-Price-currencySymbol\">€<\/span><\/bdi><\/span> – <span class=\"woocommerce-Price-amount amount\"><bdi>2 132,00<span class=\"woocommerce-Price-currencySymbol\">€<\/span><\/bdi><\/span>","related_ids":[1857,1856,1702,1442,192],"meta_data":[{"id":91150,"key":"_last_editor_used_jetpack","value":"classic-editor"}],"stock_status":"instock","_links":{"self":[{"href":"https:\/\/www.****.com\/wp-json\/wc\/v3\/products\/3962"}],"collection":[{"href":"https:\/\/www.****.com\/wp-json\/wc\/v3\/products"}]}}
When the webhook payload is related to one variation and not about the parent product, the name is translated in the default language "ee - Amarelo"
EDIT: The expected webhook would be to have all fields with the raw ml format. The attribute field is also translated in default language
{"id":3963,"name":"ee - Amarelo","slug":"auto-draft-yellow-7","permalink":"https:\/\/www.****.com\/produto\/ee\/?attribute_pa_cor-traducoes=amarelo","date_created":"2022-06-01T12:19:16","date_created_gmt":"2022-06-01T12:19:16","date_modified":"2022-06-02T09:55:29","date_modified_gmt":"2022-06-02T09:55:29","type":"variation","status":"publish","featured":false,"catalog_visibility":"visible","description":"","short_description":"","sku":"","price":"2132","regular_price":"2132","sale_price":"","date_on_sale_from":null,"date_on_sale_from_gmt":null,"date_on_sale_to":null,"date_on_sale_to_gmt":null,"on_sale":false,"purchasable":true,"total_sales":"0","virtual":false,"downloadable":false,"downloads":[],"download_limit":-1,"download_expiry":-1,"external_url":"","button_text":"","tax_status":"taxable","tax_class":"","manage_stock":false,"stock_quantity":null,"backorders":"no","backorders_allowed":false,"backordered":false,"low_stock_amount":null,"sold_individually":false,"weight":"","dimensions":{"length":"","width":"","height":""},"shipping_required":true,"shipping_taxable":true,"shipping_class":"","shipping_class_id":0,"reviews_allowed":false,"average_rating":"0.00","rating_count":0,"upsell_ids":[],"cross_sell_ids":[],"parent_id":3962,"purchase_note":"","categories":[],"tags":[],"images":[],"attributes":[{"id":25,"name":"Cor Tradu\u00e7\u00f5es 2","option":"Amarelo"}],"default_attributes":[],"variations":[],"grouped_products":[],"menu_order":1,"price_html":"<span class=\"woocommerce-Price-amount amount\"><bdi>2 132,00<span class=\"woocommerce-Price-currencySymbol\">€<\/span><\/bdi><\/span>","related_ids":[],"meta_data":[{"id":91211,"key":"_alg_currency_switcher_per_product_regular_price_ETB","value":""},{"id":91212,"key":"_alg_currency_switcher_per_product_sale_price_ETB","value":""},{"id":91213,"key":"_alg_currency_switcher_per_product_regular_price_FKP","value":""},{"id":91214,"key":"_alg_currency_switcher_per_product_sale_price_FKP","value":""}],"stock_status":"instock","_links":{"self":[{"href":"https:\/\/www.****.com\/wp-json\/wc\/v3\/products\/3963"}],"collection":[{"href":"https:\/\/www.****.com\/wp-json\/wc\/v3\/products"}],"up":[{"href":"https:\/\/www.****.com\/wp-json\/wc\/v3\/products\/3962"}]}}
My guess is that get_term is returning the field already translated and not in raw format i guess.
My initial thoughts was the more fields were translated, but the main problem right know is the attributes value. Is there anything beeing done in the admin page to get terms in the raw format that are not beeing done when a cron job is running?
Thanks
@tonysilva16 can you test this branch
Hello @spleen1981 ,
For what i could test, one of the problems remains. When the product is a variation type, the returning data has translated attributes. I installed xdebug and the data used in the webhook is retrieved in get_product_data function inside WC_REST_Products_V2_Controller class.
The function in the screenshoot bellow is called to get the attributes field.
The result of the get_attribute_taxonomy_name function is this one, that contains the translated attribute
If the product type is not a variation, the attribute name is correct.
ok, it seems under some circumnstances (e.g. variations updates) the webhook is generated through AJAX instead of cron, and in that case qwc-admin.php
is loaded instead of qwc-front.php
(would not work anyways as needed filter is added only if wp_doing_cron()
is true
).
Added a fix in the same branch above, let me know if it's working now.
Hello,
Its seems that is fixed, at least for what i could tried it was working allright. Tomorrow i am gonna test it better and i will give you feedback. Thanks.
Hello,
I am getting an error on a coupon update. I am not sure, but the webhook must be trigger using the admin page and the webhook function is using a function only available when doing frontend
[23-Jun-2022 10:59:07 UTC] PHP Fatal error: Uncaught Error: Call to undefined function qtranxf_get_front_page_config() in /wp-content/plugins/qtranslate-xt/modules/woo-commerce/woo-commerce.php:50
Stack trace:
#0 /wp-includes/class-wp-hook.php(307): qtranxf_wc_deliver_webhook_async()
#1 /wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#2 /wp-includes/plugin.php(524): WP_Hook->do_action()
#3 /wp-content/plugins/woocommerce/packages/action-scheduler/classes/actions/ActionScheduler_Action.php(22): do_action_ref_array()
#4 /wp-content/plugins/woocommerce/packages/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php(65): ActionScheduler_Action->execute()
#5 /wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(162): ActionScheduler_Abstract_QueueRunner->process_action()
#6 /wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_QueueRunner.php(132): ActionScheduler_QueueRunner->do_batch()
#7 /wp-includes/class-wp-hook.php(307): ActionScheduler_QueueRunner->run()
#8 /wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#9 /wp-includes/plugin.php(476): WP_Hook->do_action()
#10 /wp-content/plugins/woocommerce/packages/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php(52): do_action()
#11 /wp-content/plugins/woocommerce/includes/libraries/wp-async-request.php(147): ActionScheduler_AsyncRequest_QueueRunner->handle()
#12 /wp-includes/class-wp-hook.php(307): WP_Async_Request->maybe_handle()
#13 /wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#14 /wp-includes/plugin.php(476): WP_Hook->do_action()
#15 /wp-admin/admin-ajax.php(187): do_action()
#16 {main}
thrown in /wp-content/plugins/qtranslate-xt/modules/woo-commerce/woo-commerce.php on line 50
Right, that part shouldn't be needed if not doing frontend. That's a confirmation filters are working as expected anyways. Fixed now in the same branch
Thanks. It seems that is fixed now.
Merged in master.
Hello,
With a variable product, if i update the variation price and click on save changes, woocommerce will send two webhooks, one of them have the raw data (parent product update), and the other webhook (variation update) all the fields are translated.
Example: https://i.imgur.com/IBz5MiE.png
I already tried with the latest published version, and also with the current plugin files on the master branch.
Thanks.