ProjectNami / projectnami

WordPress powered by Microsoft SQL Server
http://projectnami.org
Other
270 stars 138 forks source link

WooCommerce Unable To Retrieve Terms #311

Open Kysluss opened 6 years ago

Kysluss commented 6 years ago

Hi Project Nami team! I hope you are doing well

I am unable to retrieve attributes/terms created for items in WooCommerce. WP version is 4.9.8 and PN version 1.9.8. The error logged shows "incorrect syntax near the keyword as". It looks like PN is adding commas to the CAST statement added by the translations.php on line 586. I'm not 100% certain which function after that is applying the commas.

Below is the output from translate.log

2018-10-31 17:06:18 Error Code: 8120 -- Begin Query translation attempt: SELECT t., tt., tr.object_id, tm.meta_value FROM wptx_terms AS t INNER JOIN wptx_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wptx_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN wptx_termmeta AS tm ON (t.term_id = tm.term_id AND tm.meta_key = 'order') WHERE tt.taxonomy IN ('product_type', 'product_visibility', 'product_cat', 'product_tag', 'product_shipping_class') AND tr.object_id IN (16319, 16335, 16355, 16367, 16381, 16386) GROUP BY t.term_id, tr.object_id ORDER BY tm.meta_value+0 ASC, t.name ASC

2018-10-31 17:06:18 -- Translation result: SELECT t., tt., tr.object_id, tm.meta_value FROM wptx_terms AS t INNER JOIN wptx_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wptx_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id LEFT JOIN wptx_termmeta AS tm ON (t.term_id = tm.term_id AND tm.meta_key = 'order') WHERE tt.taxonomy IN ('product_type', 'product_visibility', 'product_cat', 'product_tag', 'product_shipping_class') AND tr.object_id IN (16319, 16335, 16355, 16367, 16381, 16386) GROUP BY t.term_id, tr.object_id ORDER BY CAST(tm.meta_value, as, numeric) ASC, t.name ASC

I'm not 100% familiar with how WooCommerce generates the queries, but any insight you can provide would be greatly appreciated.

Kysluss commented 5 years ago

After some digging, I found this is being created by the translate_sort_casting function in translations.php.

It is turning CAST(tm.meta_value as numeric) into CAST(tm.meta_value, as, numeric)