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

Commit

Permalink
Fix #317
Browse files Browse the repository at this point in the history
  • Loading branch information
hyyan committed Apr 16, 2018
1 parent e3a8db6 commit c7eb1f7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
33 changes: 22 additions & 11 deletions src/Hyyan/WPI/Product/Variable.php
Expand Up @@ -30,7 +30,7 @@ public function __construct()
// Handle variations duplication
add_action('save_post', array($this, 'duplicateVariations'), 10, 3);
add_action('save_post', array($this, 'syncDefaultAttributes'), 10, 3);

// Remove variations
add_action('wp_ajax_woocommerce_remove_variations', array($this, 'removeVariations'), 9);

Expand Down Expand Up @@ -75,7 +75,7 @@ public function duplicateVariations($ID, \WP_Post $post, $update)
if ($product->get_parent_id()) {
$product = wc_get_product($product->get_parent_id());
}

$from = null;

if (pll_get_post_language($product->get_id()) == pll_default_language()) {
Expand All @@ -87,11 +87,13 @@ public function duplicateVariations($ID, \WP_Post $post, $update)
* created for brand new products which are not saved yet by user
*/
$from = Utilities::getProductTranslationByID(
esc_attr($_GET['from_post']), pll_default_language()
esc_attr($_GET['from_post']),
pll_default_language()
);
} else {
$from = Utilities::getProductTranslationByObject(
$product, pll_default_language()
$product,
pll_default_language()
);
}
}
Expand All @@ -104,12 +106,13 @@ public function duplicateVariations($ID, \WP_Post $post, $update)
foreach ($langs as $lang) {
remove_action('save_post', array($this, __FUNCTION__), 10);
$variation = new Variation(
$from, Utilities::getProductTranslationByObject($product, $lang)
$from,
Utilities::getProductTranslationByObject($product, $lang)
);
$variation->duplicate();
add_action('save_post', array($this, __FUNCTION__), 10, 3);
}

/*
remove_action('save_post', array($this, __FUNCTION__), 10);
$translations = Utilities::getProductTranslationsArrayByObject($from, true);
Expand All @@ -121,7 +124,7 @@ public function duplicateVariations($ID, \WP_Post $post, $update)
*
*/
}

/**
* Prevents plugins (like Polylang) from overwriting default attribute meta sync.
* TODO: split and correct: this function is now covering multiple concepts, not just skipping default attributes
Expand Down Expand Up @@ -169,7 +172,7 @@ public function skipDefaultAttributesMeta($check, $object_id, $meta_key, $meta_v
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
if ($translated_term_id = pll_get_term($term->term_id, $lang)) {
$translated_term = get_term_by('id', $translated_term_id, $term->taxonomy);

// If meta is taxonomy managed by Polylang and is in the
// correct language continue, otherwise return false to
// stop execution
Expand Down Expand Up @@ -335,7 +338,10 @@ public function handleVariableLimitation()
.' title : "%s" ,'
.' content : "%s" ,'
.' defaultLang : "%s"'
.'};', __('Wrong Language For Variable Product', 'woo-poly-integration'), __("Variable product must be created in the default language first or things will get messy. <br> <a href='https://github.com/hyyan/woo-poly-integration/tree/master#what-you-need-to-know-about-this-plugin' target='_blank'>Read more , to know why</a>", 'woo-poly-integration'), pll_default_language()
.'};',
__('Wrong Language For Variable Product', 'woo-poly-integration'),
__("Variable product must be created in the default language first or things will get messy. <br> <a href='https://github.com/hyyan/woo-poly-integration/tree/master#what-you-need-to-know-about-this-plugin' target='_blank'>Read more , to know why</a>", 'woo-poly-integration'),
pll_default_language()
);

Utilities::jsScriptWrapper($jsID, $code, false);
Expand All @@ -347,7 +353,11 @@ public function handleVariableLimitation()
wp_enqueue_script('jquery-effects-core');
wp_enqueue_script('jquery-ui-dialog');
wp_enqueue_script(
'woo-poly-variables', plugins_url('public/js/Variables' . $suffix . '.js', Hyyan_WPI_DIR), array('jquery', 'jquery-ui-core', 'jquery-ui-dialog'), \Hyyan\WPI\Plugin::getVersion(), true
'woo-poly-variables',
plugins_url('public/js/Variables' . $suffix . '.js', Hyyan_WPI_DIR),
array('jquery', 'jquery-ui-core', 'jquery-ui-dialog'),
\Hyyan\WPI\Plugin::getVersion(),
true
);
}, 100);
}
Expand Down Expand Up @@ -379,7 +389,8 @@ public function shouldDisableLangSwitcher()
.'});'
.' $("#options-lang").prepend('
.' "<p class=\'update-nag\'>%s</p>"'
.');', __('You can not change the default language ,Becuase you are using variable products', 'woo-poly-integration')
.');',
__('You can not change the default language because you are using variable products', 'woo-poly-integration')
);
Utilities::jsScriptWrapper($jsID, $code);
}, 100);
Expand Down
24 changes: 18 additions & 6 deletions src/Hyyan/WPI/Taxonomies/Attributes.php
Expand Up @@ -26,13 +26,19 @@ public function __construct()
{
/* Manage attributes label translation */
add_action(
'init', array($this, 'manageAttrLablesTranslation'), 11, 2
'init',
array($this, 'manageAttrLablesTranslation'),
11,
2
);
add_filter(
'woocommerce_attribute_label', array($this, 'translateAttrLable')
'woocommerce_attribute_label',
array($this, 'translateAttrLable')
);
add_action(
'admin_print_scripts', array($this, 'addAttrsTranslateLinks'), 100
'admin_print_scripts',
array($this, 'addAttrsTranslateLinks'),
100
);
}

Expand All @@ -56,7 +62,9 @@ public function manageAttrLablesTranslation()
$section = __('Woocommerce Attributes', 'woo-poly-integration');
foreach ($attrs as $attr) {
pll_register_string(
$attr->attribute_label, $attr->attribute_label, $section
$attr->attribute_label,
$attr->attribute_label,
$section
);
}
}
Expand Down Expand Up @@ -105,7 +113,9 @@ public function addAttrsTranslateLinks()
$buttonID = 'attrs-label-translation-button';
$buttonCode = sprintf(
'$("<a href=\'%s\' class=\'button button-primary button-large\'>%s</a><br><br>")'
.' .insertBefore(".attributes-table");', $stringTranslationURL, __('Translate Attributes Lables', 'woo-poly-integration')
.' .insertBefore(".attributes-table");',
$stringTranslationURL,
__('Translate Attributes Labels', 'woo-poly-integration')
);

/* Add attribute translate search link */
Expand All @@ -121,7 +131,9 @@ public function addAttrsTranslateLinks()
.' + "<a href=\'"+attrTranslateUrl+"\'>%s</a>"'
.' + "</span>";'
.' $this.append(attrTranslateHref);'
."\n});\n", $stringTranslationURL, __('Translate', 'woo-poly-integration')
."\n});\n",
$stringTranslationURL,
__('Translate', 'woo-poly-integration')
);

/* Output code */
Expand Down

0 comments on commit c7eb1f7

Please sign in to comment.