hyyan / woo-poly-integration

Looking for maintainers! - Wordpress WooCommerce Polylang Integration
https://wordpress.org/plugins-wp/woo-poly-integration/
MIT License
183 stars 66 forks source link

When creating new variable translation, variations not visible until save #534

Closed Jon007 closed 3 years ago

Jon007 commented 3 years ago

commented by @charalampospapadop on #430 "Seems to work fine the only thing is that when i translate the product first time before i publish it , it does not show the variable products, then i publish it but they still wont show, i had to do 1 extra update after the publish, then they showed up. Thanks again."

Root cause is that get_children() no longer works when in new translation because Polylang adds filter for language taxonomy in wp_term_relationships even though a left join, because the where clause does not allow for no value, items with no taxonomy are filtered out, example WP_Query sql:

SELECT   wp_posts.* FROM wp_posts  
LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND wp_posts.post_parent = 644  
 AND ( 
  wp_term_relationships.term_taxonomy_id IN (173)
) 
AND wp_posts.post_type = 'product_variation' AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC 

on publishing the new translation, the hyyan synchronisation process re-synchronises so everything is resolved on refresh.

Jon007 commented 3 years ago

root cause of this is that - with latest plugin versions - on save of new variable product, at the time the variation is created, the language of the parent is not set yet, thus although variation.php insert includes: pll_set_post_language( $ID, pll_get_post_language( $this->to->get_id() ) ); at this stage the post language returned is false so language setting fails and child posts are not picked up by subsequent queries.