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

Commit 08fe143

Browse files
committed
fixed #370
fixed #370 plus compatibility version bump
1 parent 6f11831 commit 08fe143

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

__init__.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
* License: MIT License
1313
* Version: 1.2.0
1414
* Requires At Least: 4.7
15-
* Tested Up To: 4.9.5
15+
* Tested Up To: 5.0.2
1616
* WC requires at least: 3.0.0
17-
* WC tested up to: 3.2.6
17+
* WC tested up to: 3.5.3
1818
* Requires PHP: 5.3
1919
*/
2020

src/Hyyan/WPI/Product/Product.php

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public function manageProductTranslation(array $types)
147147
$options['post_types'][] = 'product';
148148
update_option('polylang', $options);
149149
}
150+
if ( ! in_array( 'product_variation', $postTypes ) ) {
151+
$options[ 'post_types' ][] = 'product_variation';
152+
update_option( 'polylang', $options );
153+
}
150154

151155
$types [] = 'product';
152156

src/Hyyan/WPI/Product/Variable.php

+9
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ public function skipDefaultAttributesMeta($check, $object_id, $meta_key, $meta_v
170170
}
171171

172172
foreach ($meta_value as $key => $value) {
173+
//TODO JM: get_term_by is filtered by Polylang, so
174+
//will not retrieve data if the term is not in the correct language
175+
//so the rest of the check does not execute as expected
176+
//(it is not possible to get the term without knowing the language,
177+
// and not possible to get the translation without getting the term)
178+
// the fix is the additional return false which prevents save of the incorrect version when Polylang attempts to synchronise it
173179
$term = get_term_by('slug', $value, $key);
174180

175181
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
@@ -185,6 +191,8 @@ public function skipDefaultAttributesMeta($check, $object_id, $meta_key, $meta_v
185191
return false;
186192
}
187193
}
194+
// Attribute is in wrong language and must not be saved
195+
return false;
188196
}
189197
}
190198
}
@@ -230,6 +238,7 @@ public function syncDefaultAttributes($post_id, $post, $update)
230238

231239
if (!empty($attributes_translation) && isset($attributes_translation[$_GET['new_lang']])) {
232240
update_post_meta($product->get_id(), '_default_attributes', $attributes_translation[$_GET['new_lang']]);
241+
$product->set_default_attributes( $attributes_translation[ $_GET[ 'new_lang' ] ] );
233242
}
234243
} elseif ($product && 'variable' === $product->get_type()) {
235244
// Variable Product

src/Hyyan/WPI/Product/Variation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected function copyVariationMetas($from, $to)
267267
$translated = array();
268268
$tax = str_replace('attribute_', '', $key);
269269
foreach ($metas_from[$key] as $termSlug) {
270-
if (pll_is_translated_taxonomy($tax) && !empty($termSlug)) {
270+
if ( pll_is_translated_taxonomy( $tax ) && $termSlug ) {
271271
$term = $this->getTermBySlug($tax, $termSlug);
272272
if ($term) {
273273
$term_id = $term->term_id;

src/Hyyan/WPI/Utilities.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,19 @@ public static function getDefaultAttributesTranslation($product_id, $lang = '')
256256
$langs = array();
257257

258258
foreach ($default_attributes as $key => $value) {
259-
$term = get_term_by('slug', $value, $key);
259+
// $term = get_term_by('slug', $value, $key);
260+
$args = array(
261+
'get' => 'all',
262+
'number' => 1,
263+
'taxonomy' => $key,
264+
'update_term_meta_cache' => false,
265+
'orderby' => 'none',
266+
'suppress_filter' => true,
267+
'slug' => $value,
268+
'lang' => pll_get_post_language( $product_id )
269+
);
270+
$terms = get_terms( $args );
271+
$term = array_shift( $terms );
260272

261273
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
262274
$terms[] = $term;

0 commit comments

Comments
 (0)