Plugin Directory

Changeset 2475778


Ignore:
Timestamp:
02/16/2021 05:09:13 PM (5 years ago)
Author:
hyyan
Message:

v1.5.0

Location:
woo-poly-integration
Files:
92 added
8 edited

Legend:

Unmodified
Added
Removed
  • woo-poly-integration/trunk/CHANGELOG.md

    r2475760 r2475778  
    11# Changelog
    22
     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
    310
    411### 1.4.5
  • woo-poly-integration/trunk/__init__.php

    r2475760 r2475778  
    1111 * GitHub Plugin URI: hyyan/woo-poly-integration
    1212 * License: MIT License
    13  * Version: 1.4.5
     13 * Version: 1.5.0
    1414 * Requires At Least: 5.4
    1515 * Tested Up To: 5.6.1
  • woo-poly-integration/trunk/readme.txt

    r2475760 r2475778  
    33Tags: cms, woocommerce, multilingual, polylang, bilingual, international, language, localization, multilanguage, multilingual, translate, translation
    44Requires at least: 5.4
    5 Stable tag: 1.4.5
     5Stable tag: 1.5.0
    66Tested Up To: 5.6.1
    77WC requires at least: 3.0.0
     
    136136
    137137== 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
    138146
    139147== 1.4.5 ==
  • woo-poly-integration/trunk/src/Hyyan/WPI/Product/Meta.php

    r2475760 r2475778  
    809809         * list
    810810         */
    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            }
    824827        }
    825828    }
  • woo-poly-integration/trunk/src/Hyyan/WPI/Product/Stock.php

    r2475760 r2475778  
    100100                        $translation = wc_get_product( $product_translation );
    101101                        if ( $translation ) {
    102             //here the product stock is updated without saving then wc_update_product_stock_status will update and save status
     102              //here the product stock is updated without saving then wc_update_product_stock_status will update and save status
    103103                            wc_update_product_stock( $translation, $targetValue, 'set', true );
    104104              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              }                                           
    105110                        }
    106111                    }
  • woo-poly-integration/trunk/src/Hyyan/WPI/Product/Variable.php

    r2475760 r2475778  
    3939        add_filter(HooksInterface::FIELDS_LOCKER_SELECTORS_FILTER, array($this, 'extendFieldsLockerSelectors'));
    4040
     41        add_filter( 'woocommerce_variable_children_args', array( $this, 'allow_variable_children' ), 10, 3 );
     42
    4143        // Variable Products limitations warnings and safe-guards
    4244        if (is_admin()) {
     
    4648    }
    4749
     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       
    4867    /**
    4968     * Translate Variation for given variable product.
     
    129148            unset($langs[$key]);
    130149        }
     150        remove_action('save_post', array($this, __FUNCTION__), 10);
     151        add_filter( 'woocommerce_hide_invisible_variations', function() {
     152          return false;
     153        } );
    131154        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             } );
    136155            $variation = new Variation(
    137156                    $from,
     
    139158            );
    140159            $variation->duplicate();
    141             add_action('save_post', array($this, __FUNCTION__), 10, 3);
    142         }
     160        }
     161        add_action('save_post', array($this, __FUNCTION__), 10, 3);
    143162
    144163        /*
     
    227246        $product = wc_get_product($post_id);
    228247
    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)) {
    231251
    232252            // Only need to sync for the new translation from source product
     
    242262
    243263            // For each product translation, get the translated (default) terms/attributes
    244             $attributes_translation = Utilities::getDefaultAttributesTranslation($product->get_id());
     264            $attributes_translation = Utilities::getDefaultAttributesTranslation($post_id);
    245265            $langs                  = pll_languages_list();
    246266
    247267            foreach ($langs as $lang) {
    248                 $translation_id = pll_get_post($product->get_id(), $lang);
    249 
    250                 if ( $translation_id && $translation_id != $product->get_id()) {
     268                $translation_id = pll_get_post($post_id, $lang);
     269
     270                if ( $translation_id && $translation_id != $post_id) {
    251271                    update_post_meta($translation_id, '_default_attributes', $attributes_translation[$lang]);
    252272                }
  • woo-poly-integration/trunk/src/Hyyan/WPI/Product/Variation.php

    r2475760 r2475778  
    5151    {
    5252        //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();
    5456        if (empty($fromVariation)) {
    5557            return false;
     
    5961             * In such a case just add the duplicate meta
    6062             */
    61             foreach ($fromVariation as $variation) {
     63            foreach ($fromVariation as $variation_id) {
     64                $variation = $this->from->get_available_variation( $variation_id );
    6265                if (! metadata_exists('post', $variation['variation_id'], self::DUPLICATE_KEY)) {
    6366                    update_post_meta(
     
    6972            /* This could be a very long operation */
    7073            set_time_limit(0);
    71             foreach ($fromVariation as $variation) {
     74            foreach ($fromVariation as $variation_id) {
     75                $variation = $this->from->get_available_variation( $variation_id );
    7276                /*
    7377                 * First we check if the "to" product contains the duplicate meta
     
    7680                $posts = get_posts(array(
    7781                    'meta_key' => self::DUPLICATE_KEY,
    78                     'meta_value' => $variation['variation_id'],
     82                    'meta_value' => $variation_id,
    7983                    'post_type' => 'product_variation',
    8084                    'post_status'    => 'any',
     
    8791                        // update
    8892                        $this->update(
    89                             wc_get_product($variation['variation_id']), $posts[0], $variation
     93                            wc_get_product($variation_id), $posts[0], $variation
    9094                        );
    9195                        break;
    9296                    case 0:
    9397                        // insert
    94                         $this->insert(wc_get_product($variation['variation_id']), $variation);
     98                        $this->insert(wc_get_product($variation_id), $variation);
    9599                        break;
    96100                    default:
     
    98102                        //-  update first variation eg original
    99103                        $this->update(
    100                             wc_get_product($variation['variation_id']), $posts[0], $variation
     104                            wc_get_product($variation_id), $posts[0], $variation
    101105                        );
    102106                        //- delete duplicate variations
     
    114118                }
    115119            }
     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());
    116123            /* Restor original timeout */
    117124            set_time_limit(ini_get('max_execution_time'));
     
    190197            }
    191198            if ($targetLang){
    192                 pll_set_post_language( $ID, pll_get_post_language( $targetLang ) );
     199                pll_set_post_language( $ID, $targetLang );
    193200            }
    194201            update_post_meta(
  • woo-poly-integration/trunk/src/Hyyan/WPI/Utilities.php

    r2475760 r2475778  
    248248    public static function getDefaultAttributesTranslation($product_id, $lang = '')
    249249    {
    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);
    251253        $translated_attributes = array();
    252254
     
    334336            $add_new_product = $current_screen && $current_screen->post_type === 'product' && $current_screen->action === 'add';
    335337            $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
    338339            $has_variations  = get_children(array(
    339340                'post_type'   => 'product_variation',
    340                 'post_parent' => $product->get_id()
     341                'post_parent' => $product->get_id(),
     342                'lang' => ''
    341343            ));
    342344
    343345            if ($add_new_product && $is_translation && $has_variations) {
    344             */
    345             if ($add_new_product && $is_translation ) {
    346346                return true;
    347347            }
Note: See TracChangeset for help on using the changeset viewer.