Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
fixed #370
Browse files Browse the repository at this point in the history
fixed #370 plus compatibility version bump
  • Loading branch information
Jon007 committed Dec 27, 2018
1 parent 6f11831 commit 08fe143
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions __init__.php
Expand Up @@ -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
*/

Expand Down
4 changes: 4 additions & 0 deletions src/Hyyan/WPI/Product/Product.php
Expand Up @@ -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';

Expand Down
9 changes: 9 additions & 0 deletions src/Hyyan/WPI/Product/Variable.php
Expand Up @@ -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)) {
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Hyyan/WPI/Product/Variation.php
Expand Up @@ -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;
Expand Down
14 changes: 13 additions & 1 deletion src/Hyyan/WPI/Utilities.php
Expand Up @@ -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;
Expand Down

0 comments on commit 08fe143

Please sign in to comment.