Skip to content
Permalink
Browse files

fixed #370

fixed #370 plus compatibility version bump
  • Loading branch information...
Jon007 committed Dec 27, 2018
1 parent 6f11831 commit 08fe1432fb0981e727409c362c1bbb2892dcb601
@@ -12,9 +12,9 @@
* License: MIT License
* Version: 1.2.0
* Requires At Least: 4.7
* Tested Up To: 4.9.5
* Tested Up To: 5.0.2
* WC requires at least: 3.0.0
* WC tested up to: 3.2.6
* WC tested up to: 3.5.3
* Requires PHP: 5.3
*/
@@ -147,6 +147,10 @@ public function manageProductTranslation(array $types)
$options['post_types'][] = 'product';
update_option('polylang', $options);
}
if ( ! in_array( 'product_variation', $postTypes ) ) {
$options[ 'post_types' ][] = 'product_variation';
update_option( 'polylang', $options );
}
$types [] = 'product';
@@ -170,6 +170,12 @@ public function skipDefaultAttributesMeta($check, $object_id, $meta_key, $meta_v
}
foreach ($meta_value as $key => $value) {
//TODO JM: get_term_by is filtered by Polylang, so
//will not retrieve data if the term is not in the correct language
//so the rest of the check does not execute as expected
//(it is not possible to get the term without knowing the language,
// and not possible to get the translation without getting the term)
// the fix is the additional return false which prevents save of the incorrect version when Polylang attempts to synchronise it
$term = get_term_by('slug', $value, $key);
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
@@ -185,6 +191,8 @@ public function skipDefaultAttributesMeta($check, $object_id, $meta_key, $meta_v
return false;
}
}
// Attribute is in wrong language and must not be saved
return false;
}
}
}
@@ -230,6 +238,7 @@ public function syncDefaultAttributes($post_id, $post, $update)
if (!empty($attributes_translation) && isset($attributes_translation[$_GET['new_lang']])) {
update_post_meta($product->get_id(), '_default_attributes', $attributes_translation[$_GET['new_lang']]);
$product->set_default_attributes( $attributes_translation[ $_GET[ 'new_lang' ] ] );
}
} elseif ($product && 'variable' === $product->get_type()) {
// Variable Product
@@ -267,7 +267,7 @@ protected function copyVariationMetas($from, $to)
$translated = array();
$tax = str_replace('attribute_', '', $key);
foreach ($metas_from[$key] as $termSlug) {
if (pll_is_translated_taxonomy($tax) && !empty($termSlug)) {
if ( pll_is_translated_taxonomy( $tax ) && $termSlug ) {
$term = $this->getTermBySlug($tax, $termSlug);
if ($term) {
$term_id = $term->term_id;
@@ -256,7 +256,19 @@ public static function getDefaultAttributesTranslation($product_id, $lang = '')
$langs = array();
foreach ($default_attributes as $key => $value) {
$term = get_term_by('slug', $value, $key);
// $term = get_term_by('slug', $value, $key);
$args = array(
'get' => 'all',
'number' => 1,
'taxonomy' => $key,
'update_term_meta_cache' => false,
'orderby' => 'none',
'suppress_filter' => true,
'slug' => $value,
'lang' => pll_get_post_language( $product_id )
);
$terms = get_terms( $args );
$term = array_shift( $terms );
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
$terms[] = $term;

0 comments on commit 08fe143

Please sign in to comment.
You can’t perform that action at this time.