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

Commit

Permalink
fixes #534
Browse files Browse the repository at this point in the history
fixes #534 new variable translation, variations not visible until save
  • Loading branch information
Jon007 committed Feb 7, 2021
1 parent d3b0837 commit e0be02c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,7 @@
* [fixes #522, #529 and other JQuery deprecation issues props @mrleemon](https://github.com/hyyan/woo-poly-integration/issues/522)
* [fixes #475 variation stock issues](https://github.com/hyyan/woo-poly-integration/issues/475)
* [fixes #527 default form value for variation lost when creating new translation](https://github.com/hyyan/woo-poly-integration/issues/527)

* [fixes #534 new variable translation, variations not visible until save](https://github.com/hyyan/woo-poly-integration/issues/534)

### 1.4.4

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Expand Up @@ -142,6 +142,7 @@ Just make sure to setup your permalinks , and every thing will be fine , I promi
* [fixes #522, #529 and other JQuery deprecation issues props @mrleemon](https://github.com/hyyan/woo-poly-integration/issues/522)
* [fixes #475 variation stock issues](https://github.com/hyyan/woo-poly-integration/issues/475)
* [fixes #527 default form value for variation lost when creating new translation](https://github.com/hyyan/woo-poly-integration/issues/527)
* [fixes #534 new variable translation, variations not visible until save](https://github.com/hyyan/woo-poly-integration/issues/534)


== 1.4.4 ==
Expand Down
15 changes: 11 additions & 4 deletions src/Hyyan/WPI/Product/Meta.php
Expand Up @@ -144,7 +144,8 @@ public function syncProductsMeta()
// new code to synchronise Taxonomies and Product attributes applied to WooCommerce 3.0
// which now moves product_visibility from meta to taxonomy
// (includes Catalog Visibility, Featured Product previously in meta)
add_action('wp_insert_post', array($this, 'syncTaxonomiesAndProductAttributes'), 10, 3);
//JM2021: switch from wp_insert_post to save_post_product, and higher priority than variable hook
add_action('save_post_product', array($this, 'syncTaxonomiesAndProductAttributes'), 5, 3);

$ID = false;
$disable = false;
Expand Down Expand Up @@ -211,8 +212,14 @@ public function syncTaxonomiesAndProductAttributes($post_id, $post, $update)
$source_id = isset($_GET['from_post']) ? absint($_GET['from_post']) : false;

if ($source_id) {
$this->copyTerms($source_id, $post_id, $_GET['new_lang'], $taxonomies);
$this->syncCustomProductAttributes($source_id, $_GET['new_lang']);
//JM2021: ensure new language is set on new translation early as lack of language taxonomy
//causes some subsequent queries to fail
$new_lang = $_GET['new_lang'];
if (! pll_get_post_language( $post_id )){
pll_set_post_language ($post_id, $new_lang);
}
$this->copyTerms($source_id, $post_id, $new_lang, $taxonomies);
$this->syncCustomProductAttributes($source_id, $new_lang);
}
} else {
// Product edit - update terms of all product translations
Expand Down Expand Up @@ -860,7 +867,7 @@ public function suppressInvalidDuplicatedSKUErrorMsg($sku_found, $product_id, $s
FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
WHERE $wpdb->posts.post_type IN ( 'product', 'product_variation' )
AND $wpdb->posts.post_status != 'trash'
AND $wpdb->posts.post_status NOT IN ('trash', 'auto-draft')
AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = %s
AND $wpdb->postmeta.post_id <> %d
", wp_slash( $sku ), $product_id
Expand Down
3 changes: 2 additions & 1 deletion src/Hyyan/WPI/Product/Variable.php
Expand Up @@ -122,7 +122,8 @@ public function duplicateVariations($ID, \WP_Post $post, $update)
return false;
}

$langs = pll_languages_list();
//if creating a new translation, process the target language only, otherwise check all languages
$langs = isset($_GET['new_lang']) ? array($_GET['new_lang']) : pll_languages_list();
//JM2021: remove default lang since this should always be source not destination for copy (for variable products)
if (($key = array_search($def_lang, $langs)) !== false) {
unset($langs[$key]);
Expand Down
19 changes: 16 additions & 3 deletions src/Hyyan/WPI/Product/Variation.php
Expand Up @@ -177,16 +177,29 @@ protected function insert(\WC_Product_Variation $variation, array $metas)
// just in case the product was created before plugin acivation.
$this->addDuplicateMeta($variation->get_id());
$data = (array) get_post($variation->get_id());
$newParentId = $this->to->get_id();
unset($data['ID']);
$data['post_parent'] = $this->to->get_id();
$data['post_parent'] = $newParentId;
$ID = wp_insert_post($data);
if ($ID) {
pll_set_post_language( $ID, pll_get_post_language( $this->to->get_id() ) );
//JM2021: extra protection to ensure language set as early as possible
//as had been failing on parent language [though now fixed]
$targetLang = pll_get_post_language( $newParentId );
if ( (! $targetLang) && isset($_GET['new_lang'])) {
$targetLang=$_GET['new_lang'];
}
if ($targetLang){
pll_set_post_language( $ID, pll_get_post_language( $targetLang ) );
}
update_post_meta(
$ID, self::DUPLICATE_KEY, $metas['variation_id']
);
$this->copyVariationMetas($variation->get_id(), $ID);
Utilities::flushCacheUpdateLookupTable( $ID );
//JM2021:within current execution woo may cache the fact that the new product does not have children
//so force flush transients etc on the *parent*
//wc_delete_product_transients($this->to->get_id());
Utilities::flushCacheUpdateLookupTable( $ID );
Utilities::flushCacheUpdateLookupTable( $newParentId );
}
}
/**
Expand Down
1 change: 1 addition & 0 deletions src/Hyyan/WPI/Utilities.php
Expand Up @@ -520,6 +520,7 @@ public static function flushCacheUpdateLookupTable( $the_product ) {
$id = $product->get_id();
wc_delete_product_transients( $id );
wp_cache_delete( $id, 'post_meta' );
wp_cache_delete( $id, 'posts' );
wp_cache_delete( 'lookup_table', 'object_' . $id );
$productType = $product->get_type();

Expand Down

0 comments on commit e0be02c

Please sign in to comment.