Changeset 2475778
- Timestamp:
- 02/16/2021 05:09:13 PM (5 years ago)
- Location:
- woo-poly-integration
- Files:
-
- 92 added
- 8 edited
-
tags/1.5.0 (added)
-
tags/1.5.0/CHANGELOG.md (added)
-
tags/1.5.0/LICENSE (added)
-
tags/1.5.0/README.md (added)
-
tags/1.5.0/__init__.php (added)
-
tags/1.5.0/composer.json (added)
-
tags/1.5.0/index.php (added)
-
tags/1.5.0/languages (added)
-
tags/1.5.0/languages/woo-poly-integration-ar.mo (added)
-
tags/1.5.0/languages/woo-poly-integration-ar.po (added)
-
tags/1.5.0/languages/woo-poly-integration-es_ES.mo (added)
-
tags/1.5.0/languages/woo-poly-integration-es_ES.po (added)
-
tags/1.5.0/languages/woo-poly-integration.pot (added)
-
tags/1.5.0/public (added)
-
tags/1.5.0/public/js (added)
-
tags/1.5.0/public/js/Cart.js (added)
-
tags/1.5.0/public/js/Cart.min.js (added)
-
tags/1.5.0/public/js/Variables.js (added)
-
tags/1.5.0/public/js/Variables.min.js (added)
-
tags/1.5.0/readme.txt (added)
-
tags/1.5.0/src (added)
-
tags/1.5.0/src/Hyyan (added)
-
tags/1.5.0/src/Hyyan/WPI (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin/AbstractSettings.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin/Features.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin/MetasList.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin/Settings.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin/SettingsInterface.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Admin/StatusReport.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Ajax.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Autoloader.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Breadcrumb.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Cart.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Coupon.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Emails.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Endpoints.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Gateways (added)
-
tags/1.5.0/src/Hyyan/WPI/Gateways.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Gateways/GatewayBACS.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Gateways/GatewayCOD.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Gateways/GatewayCheque.php (added)
-
tags/1.5.0/src/Hyyan/WPI/HooksInterface.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Language.php (added)
-
tags/1.5.0/src/Hyyan/WPI/LocaleNumbers.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Login.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Media.php (added)
-
tags/1.5.0/src/Hyyan/WPI/MessagesInterface.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Order.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Pages.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Permalinks.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Plugin.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Privacy.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Product (added)
-
tags/1.5.0/src/Hyyan/WPI/Product/Duplicator.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Product/Meta.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Product/Product.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Product/Stock.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Product/Variable.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Product/Variation.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Reports.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Shipping.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Tax.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies/Attributes.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies/Categories.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies/ShippingCalss.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies/Tags.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies/Taxonomies.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Taxonomies/TaxonomiesInterface.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Tools (added)
-
tags/1.5.0/src/Hyyan/WPI/Tools/FlashMessages.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Tools/TranslationsDownloader.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Utilities.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Admin (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Admin/about.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Admin/getHelp.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Admin/main.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Admin/support.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Messages (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Messages/activateError.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Messages/endpointsTranslations.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/Messages/support.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/admin.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/badges.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Views/social.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Widgets (added)
-
tags/1.5.0/src/Hyyan/WPI/Widgets/LayeredNav.php (added)
-
tags/1.5.0/src/Hyyan/WPI/Widgets/SearchWidget.php (added)
-
tags/1.5.0/vendor (added)
-
tags/1.5.0/vendor/class.settings-api.php (added)
-
trunk/CHANGELOG.md (modified) (1 diff)
-
trunk/__init__.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/Hyyan/WPI/Product/Meta.php (modified) (1 diff)
-
trunk/src/Hyyan/WPI/Product/Stock.php (modified) (1 diff)
-
trunk/src/Hyyan/WPI/Product/Variable.php (modified) (6 diffs)
-
trunk/src/Hyyan/WPI/Product/Variation.php (modified) (8 diffs)
-
trunk/src/Hyyan/WPI/Utilities.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-poly-integration/trunk/CHANGELOG.md
r2475760 r2475778 1 1 # Changelog 2 2 3 ### 1.5.0 4 5 * correction to fix #527 6 * fixes #536 avoid over-setting product type on edit 7 * re- fixes #534 new variation not visible until save 8 * re- fixes #527 variation form default values 9 * fixes #535 variation stock issues 3 10 4 11 ### 1.4.5 -
woo-poly-integration/trunk/__init__.php
r2475760 r2475778 11 11 * GitHub Plugin URI: hyyan/woo-poly-integration 12 12 * License: MIT License 13 * Version: 1. 4.513 * Version: 1.5.0 14 14 * Requires At Least: 5.4 15 15 * Tested Up To: 5.6.1 -
woo-poly-integration/trunk/readme.txt
r2475760 r2475778 3 3 Tags: cms, woocommerce, multilingual, polylang, bilingual, international, language, localization, multilanguage, multilingual, translate, translation 4 4 Requires at least: 5.4 5 Stable tag: 1. 4.55 Stable tag: 1.5.0 6 6 Tested Up To: 5.6.1 7 7 WC requires at least: 3.0.0 … … 136 136 137 137 == Changelog == 138 139 == 1.5.0 == 140 141 * correction to fix #527 142 * fixes #536 avoid over-setting product type on edit 143 * re- fixes #534 new variation not visible until save 144 * re- fixes #527 variation form default values 145 * fixes #535 variation stock issues 138 146 139 147 == 1.4.5 == -
woo-poly-integration/trunk/src/Hyyan/WPI/Product/Meta.php
r2475760 r2475778 809 809 * list 810 810 */ 811 if ($ID && ($type = get_post_meta($ID, '_translation_porduct_type'))) { 812 add_action('admin_print_scripts', function () use ($type) { 813 $jsID = 'product-type-sync'; 814 $code = sprintf( 815 '// <![CDATA[ %1$s' 816 . ' addLoadEvent(function () { ' 817 . 'document.getElementById("product-type").value="%2$s";' 818 . '})' 819 . '// ]]>', PHP_EOL, $type[0] 820 ); 821 822 Utilities::jsScriptWrapper($jsID, $code, false); 823 }, 11); 811 if ($ID && (isset($_GET['from_post'])) && ($type = get_post_meta($ID, '_translation_porduct_type') ) ) { 812 //don't switch type if setting is corrupt 813 if ($type && is_array($type) && $type[0]!='' && $type[0]!='simple'){ 814 add_action('admin_print_scripts', function () use ($type) { 815 $jsID = 'product-type-sync'; 816 $code = sprintf( 817 '// <![CDATA[ %1$s' 818 . ' addLoadEvent(function () { ' 819 . 'document.getElementById("product-type").value="%2$s";' 820 . '})' 821 . '// ]]>', PHP_EOL, $type[0] 822 ); 823 824 Utilities::jsScriptWrapper($jsID, $code, false); 825 }, 11); 826 } 824 827 } 825 828 } -
woo-poly-integration/trunk/src/Hyyan/WPI/Product/Stock.php
r2475760 r2475778 100 100 $translation = wc_get_product( $product_translation ); 101 101 if ( $translation ) { 102 //here the product stock is updated without saving then wc_update_product_stock_status will update and save status102 //here the product stock is updated without saving then wc_update_product_stock_status will update and save status 103 103 wc_update_product_stock( $translation, $targetValue, 'set', true ); 104 104 wc_update_product_stock_status ($product_translation, $target_status); 105 if ($translation->get_parent_id()) { 106 $prodparent = wc_get_product($translation->get_parent_id()); 107 $parentstatus = $prodparent->get_stock_status(); 108 wc_update_product_stock_status ($translation->get_parent_id(), $target_status); 109 } 105 110 } 106 111 } -
woo-poly-integration/trunk/src/Hyyan/WPI/Product/Variable.php
r2475760 r2475778 39 39 add_filter(HooksInterface::FIELDS_LOCKER_SELECTORS_FILTER, array($this, 'extendFieldsLockerSelectors')); 40 40 41 add_filter( 'woocommerce_variable_children_args', array( $this, 'allow_variable_children' ), 10, 3 ); 42 41 43 // Variable Products limitations warnings and safe-guards 42 44 if (is_admin()) { … … 46 48 } 47 49 50 /** 51 * Stop Polylang preventing WooCommerce from finding child variations 52 * by hooking woocommerce_variable_children_args and 53 * adding any langugage parameter to variable children 54 * needed since Polylang 2.8 55 * 56 * @param array $args array of WP_Query args 57 * @param \WC_Product $product Product 58 * @param bool $visible whether querying for visible children or not 59 * 60 * @return $args 61 */ 62 public function allow_variable_children($args, $product, $visible){ 63 $args['lang'] = ''; 64 return $args; 65 } 66 48 67 /** 49 68 * Translate Variation for given variable product. … … 129 148 unset($langs[$key]); 130 149 } 150 remove_action('save_post', array($this, __FUNCTION__), 10); 151 add_filter( 'woocommerce_hide_invisible_variations', function() { 152 return false; 153 } ); 131 154 foreach ($langs as $lang) { 132 remove_action('save_post', array($this, __FUNCTION__), 10);133 add_filter( 'woocommerce_hide_invisible_variations', function() {134 return false;135 } );136 155 $variation = new Variation( 137 156 $from, … … 139 158 ); 140 159 $variation->duplicate(); 141 add_action('save_post', array($this, __FUNCTION__), 10, 3);142 }160 } 161 add_action('save_post', array($this, __FUNCTION__), 10, 3); 143 162 144 163 /* … … 227 246 $product = wc_get_product($post_id); 228 247 229 if ($product && 'simple' === $product->get_type() && Utilities::maybeVariableProduct($product)) { 230 // Maybe is Variable Product - new translations of Variable Products are first created as simple 248 //JM2021: new translations of Variable Products are first created as simple 249 //but now at this point are already Variable but not linked translations 250 if ($product && isset($_GET['from_post']) && Utilities::maybeVariableProduct($product)) { 231 251 232 252 // Only need to sync for the new translation from source product … … 242 262 243 263 // For each product translation, get the translated (default) terms/attributes 244 $attributes_translation = Utilities::getDefaultAttributesTranslation($p roduct->get_id());264 $attributes_translation = Utilities::getDefaultAttributesTranslation($post_id); 245 265 $langs = pll_languages_list(); 246 266 247 267 foreach ($langs as $lang) { 248 $translation_id = pll_get_post($p roduct->get_id(), $lang);249 250 if ( $translation_id && $translation_id != $p roduct->get_id()) {268 $translation_id = pll_get_post($post_id, $lang); 269 270 if ( $translation_id && $translation_id != $post_id) { 251 271 update_post_meta($translation_id, '_default_attributes', $attributes_translation[$lang]); 252 272 } -
woo-poly-integration/trunk/src/Hyyan/WPI/Product/Variation.php
r2475760 r2475778 51 51 { 52 52 //the variations of the product in the from product language 53 $fromVariation = $this->from->get_available_variations(); 53 //JM2021: needs to sync all children not only available variations 54 //$fromVariation = $this->from->get_available_variations(); 55 $fromVariation = $this->from->get_children(); 54 56 if (empty($fromVariation)) { 55 57 return false; … … 59 61 * In such a case just add the duplicate meta 60 62 */ 61 foreach ($fromVariation as $variation) { 63 foreach ($fromVariation as $variation_id) { 64 $variation = $this->from->get_available_variation( $variation_id ); 62 65 if (! metadata_exists('post', $variation['variation_id'], self::DUPLICATE_KEY)) { 63 66 update_post_meta( … … 69 72 /* This could be a very long operation */ 70 73 set_time_limit(0); 71 foreach ($fromVariation as $variation) { 74 foreach ($fromVariation as $variation_id) { 75 $variation = $this->from->get_available_variation( $variation_id ); 72 76 /* 73 77 * First we check if the "to" product contains the duplicate meta … … 76 80 $posts = get_posts(array( 77 81 'meta_key' => self::DUPLICATE_KEY, 78 'meta_value' => $variation ['variation_id'],82 'meta_value' => $variation_id, 79 83 'post_type' => 'product_variation', 80 84 'post_status' => 'any', … … 87 91 // update 88 92 $this->update( 89 wc_get_product($variation ['variation_id']), $posts[0], $variation93 wc_get_product($variation_id), $posts[0], $variation 90 94 ); 91 95 break; 92 96 case 0: 93 97 // insert 94 $this->insert(wc_get_product($variation ['variation_id']), $variation);98 $this->insert(wc_get_product($variation_id), $variation); 95 99 break; 96 100 default: … … 98 102 //- update first variation eg original 99 103 $this->update( 100 wc_get_product($variation ['variation_id']), $posts[0], $variation104 wc_get_product($variation_id), $posts[0], $variation 101 105 ); 102 106 //- delete duplicate variations … … 114 118 } 115 119 } 120 $target_status=$this->from->get_stock_status(); 121 wc_update_product_stock_status ($this->to->get_id(), $target_status); 122 utilities::flushCacheUpdateLookupTable($this->to->get_id()); 116 123 /* Restor original timeout */ 117 124 set_time_limit(ini_get('max_execution_time')); … … 190 197 } 191 198 if ($targetLang){ 192 pll_set_post_language( $ID, pll_get_post_language( $targetLang ));199 pll_set_post_language( $ID, $targetLang ); 193 200 } 194 201 update_post_meta( -
woo-poly-integration/trunk/src/Hyyan/WPI/Utilities.php
r2475760 r2475778 248 248 public static function getDefaultAttributesTranslation($product_id, $lang = '') 249 249 { 250 $product = wc_get_product($product_id); 250 //all variation details including default attributes must be copied from base language 251 $base_product_id = pll_get_post($product_id, pll_default_language()); 252 $product = wc_get_product($base_product_id); 251 253 $translated_attributes = array(); 252 254 … … 334 336 $add_new_product = $current_screen && $current_screen->post_type === 'product' && $current_screen->action === 'add'; 335 337 $is_translation = isset($_GET['from_post']) && isset($_GET['new_lang']); 336 //new product does not in fact have variations at this point so $has_variations test always fails 337 /* 338 //new product did not appear have variations due to Polylang 2.8 aggressive filtering see #535 338 339 $has_variations = get_children(array( 339 340 'post_type' => 'product_variation', 340 'post_parent' => $product->get_id() 341 'post_parent' => $product->get_id(), 342 'lang' => '' 341 343 )); 342 344 343 345 if ($add_new_product && $is_translation && $has_variations) { 344 */345 if ($add_new_product && $is_translation ) {346 346 return true; 347 347 }
Note: See TracChangeset
for help on using the changeset viewer.