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

Issue with fields locker #545

Closed mrleemon closed 3 years ago

mrleemon commented 3 years ago

Can you reproduce this issue on default Wordpress theme (eg Storefront)?

Yes

Can you reproduce this issue when all other plugins are disabled except WooCommerce, Polylang and Hyyan WooCommerce Polylang Integration?

Yes

What product versions and settings are you using when this issue occurs?

Steps to Reproduce

  1. Add a couple of languages in Polylang (English and Spanish, for example)
  2. Set English as the default language
  3. Activate the Fields Locker checkbox in the WooPoly options
  4. Add a product in the secondary language (Spanish) and save it

What I Expected

The product fields should be able to be edited/selected/checked.

What Happened Instead

The product fields are locked and cannot be edited/selected/checked.

It seems that the Fields Locker script is always active when editing products in a secondary language even if there is no product in the default language to synchronize to. This is a fringe case, as usually one adds products in the default language first and then adds its translations. But, I think that the addFieldsLocker() function in the Meta.php file should check this.

https://github.com/hyyan/woo-poly-integration/blob/139469117798fc87a14863eb71c7c64ded49487f/src/Hyyan/WPI/Product/Meta.php#L724

mrleemon commented 3 years ago

Instead of modifying the addFieldsLocker() function, I think that the following line in the syncProductsMeta() function should be updated to reflect the case I'm talking about:

https://github.com/hyyan/woo-poly-integration/blob/139469117798fc87a14863eb71c7c64ded49487f/src/Hyyan/WPI/Product/Meta.php#L166

Maybe change it to this:

$disable = $ID && ( pll_get_post_language($ID) != pll_default_language() ) && pll_get_post( $ID, pll_default_language() );

I tried this in one of my sites, and it's working apparently. I can open a PR if you want.

Jon007 commented 3 years ago

Hi, In the way this plugin works for variable products, the secondary language variations are always overwritten from the primary language, the primary language must be created first. If not I think anything previously created in a secondary language would be wiped out as soon as you start drafting a translation in the primary language. So creating variable products in secondary language could lead to 'unexpected behaviour' hence discouraged... Fields Locker is optional feature so can also just be turned off when it is necessary to do something special in a secondary language.