Plugin Directory

Changeset 3435950


Ignore:
Timestamp:
01/09/2026 01:50:10 PM (3 months ago)
Author:
arture
Message:

Version 4.2.5

Location:
storecontrl-wp-connection/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • storecontrl-wp-connection/trunk/includes/api/class-storecontrl-web-api-functions.php

    r3435393 r3435950  
    230230
    231231        return $output;
     232    }
     233
     234    public function storecontrl_update_wc_product_variation($product_variations, $change_api_name = '')
     235    {
     236        // Find product by SKU
     237        $product_id = $this->functions->custom_get_product_id_by_sku($product_variations['product_id']);
     238
     239        // Check if product exist
     240        if ($product_id != 0) {
     241
     242            // init CRUD
     243            $Product = new WC_Product_Variable( $product_id );
     244
     245            // SET ALL MASTERDATA
     246            $output = $this->set_product_variations_data($product_variations['sku_list']);
     247            $product_variations['variations'] = $output['variations'];
     248            $product_variations['product_atributes'] = $output['product_atributes'];
     249            unset($product_variations['sku_list']);
     250
     251            $product_attributes = $Product->get_attributes();
     252            if (isset($product_attributes) && !empty($product_attributes)) {
     253
     254                $product_atributes = array();
     255                foreach( $product_variations['product_atributes'] as $product_atribute ){
     256                    $product_atributes[] = 'pa_' . $this->generate_clean_slug($product_atribute);
     257                }
     258
     259                foreach ($product_attributes as $attribute_name => $attribute_data) {
     260                    $attribute_data = $attribute_data->get_data();
     261                    if( $attribute_data['is_variation'] && !in_array($attribute_name, $product_atributes) ){
     262                        unset($product_attributes[$attribute_name]);
     263                    }
     264                }
     265            }
     266
     267            $existing_variation_attributes = $Product->get_variation_attributes();
     268            if (isset($existing_variation_attributes) && !empty($existing_variation_attributes)) {
     269
     270                $new_clean_product_atributes = array();
     271                foreach ($product_variations['product_atributes'] as $variation_attribute_name) {
     272                    $new_clean_product_atributes[] = 'pa_' . $this->generate_clean_slug($variation_attribute_name);
     273                }
     274
     275                $all_product_attributes = get_post_meta($product_id, '_product_attributes', true);
     276                foreach ($existing_variation_attributes as $variation_attribute_name => $variation_attribute_id) {
     277                    if (!in_array($variation_attribute_name, $new_clean_product_atributes)) {
     278                        unset($all_product_attributes[$variation_attribute_name]);
     279                        $this->functions->custom_update_post_meta($product_id, '_product_attributes', $all_product_attributes);
     280                    }
     281                }
     282            }
     283
     284            // Add all attributes to the global size term for filtering ( As in the basic plugin )
     285            $product_variations_attributes = $this->insert_product_attributes('size', $product_variations['variations']);
     286            if( isset($product_variations_attributes) && is_array($product_variations_attributes) ){
     287                $product_attributes = array_merge($product_attributes, $this->insert_product_attributes('size', $product_variations['variations']));
     288                $product_attributes = array_merge($product_attributes, $this->insert_product_attributes($product_variations['product_atributes'], $product_variations['variations']));
     289                $this->insert_product_variations($product_id, $product_variations);
     290            }
     291
     292            $Product->set_attributes($product_attributes);
     293            $Product->save();
     294
     295            do_action('after_sc_variations_process', $product_id, $product_variations);
     296
     297            return 'true';
     298        } else {
     299            return 'false';
     300        }
    232301    }
    233302
  • storecontrl-wp-connection/trunk/includes/cronjob/class-storecontrl-cronjob-functions.php

    r3435393 r3435950  
    531531                            break;
    532532
    533                         // SKu Added batch processing
     533                        // SKU Added batch processing
    534534                        case (strpos($file, 'sku_added') !== false):
    535535
     
    539539                            // Iterate products batch
    540540                            foreach ( $results as $key => $product_variations) {
     541
    541542                                $product_variations = (array)$product_variations;
    542543
     
    546547                                }
    547548
    548                                 $all_variations[$key]->processed = 'true';
    549                                 file_put_contents( $directory . '/' . $file, json_encode($all_variations) );
    550 
    551                                 // Update time after every succefull processed product
    552                                 $processing_batch_time = time();
    553                                 update_option( 'processing_batch_time', $processing_batch_time );
     549                                $response = $api_functions->storecontrl_update_wc_product_variation( $product_variations, 'GetSkuAdded');
     550
     551                                // Check if product is processed or 10 times try to process
     552                                if( $response == 'true' || isset($product_variations['retry']) && $product_variations['retry'] == 12 ) {
     553                                    $all_variations[$key]->processed = 'true';
     554                                    file_put_contents( $directory . '/' . $file, json_encode($all_variations) );
     555
     556                                    // Update time after every succefull processed product
     557                                    $processing_batch_time = time();
     558                                    update_option( 'processing_batch_time', $processing_batch_time );
     559                                }
     560                                else{
     561                                    $retry = 0;
     562                                    if( isset($product_variations['retry']) ) {
     563                                        $retry = $product_variations['retry'];
     564                                    }
     565                                    $retry++;
     566                                    $all_variations[$key]->retry = $retry;
     567                                    file_put_contents( $directory . '/' . $file, json_encode($all_variations) );
     568
     569                                    $file_finished = false;
     570                                }
    554571
    555572                            }
    556573                            break;
    557574
    558                         // SKu Changed batch processing
     575                        // SKU Changed batch processing
    559576                        case (strpos($file, 'sku_changed') !== false):
     577
    560578                            $all_variations = $results;
    561579                            $results = (array) $results;
     
    571589                                }
    572590
    573                                 $all_variations[$key]->processed = 'true';
    574                                 file_put_contents( $directory . '/' . $file, json_encode($all_variations) );
    575 
    576                                 // Update time after every succefull processed product
    577                                 $processing_batch_time = time();
    578                                 update_option( 'processing_batch_time', $processing_batch_time );
     591                                $response = $api_functions->storecontrl_update_wc_product_variation($product_variations, 'GetSkuChanged');
     592
     593                                // Check if product is processed
     594                                if( $response == 'true' ) {
     595                                    $all_variations[$key]->processed = 'true';
     596                                    file_put_contents( $directory . '/' . $file, json_encode($all_variations) );
     597
     598                                    // Update time after every succefull processed product
     599                                    $processing_batch_time = time();
     600                                    update_option( 'processing_batch_time', $processing_batch_time );
     601                                }
     602                                else{
     603                                    $this->logging->log_file_write( 'Cronjob | SKU changed | Product ID not found: ' . $product_variations['product_id'] );
     604                                }
    579605                            }
    580606                            break;
  • storecontrl-wp-connection/trunk/readme.txt

    r3435393 r3435950  
    55Requires at least: 6.6.0
    66Tested up to: 6.8.3
    7 Stable tag: 4.2.4
     7Stable tag: 4.2.5
    88Requires PHP: 8.0
    99License: GPLv2 or later
     
    9393== Changelog ==
    9494
     95= 4.2.5 =
     96* Bugfix with new added products and variations processing
     97
    9598= 4.2.3 =
    9699* Optimalisatie in product update flow
  • storecontrl-wp-connection/trunk/storecontrl-wp-connection.php

    r3435714 r3435950  
    44Plugin URI:  http://www.arture.nl/storecontrl
    55Description: The Wordpress plugin for connecting Woocommerce with StoreContrl Cloud. With the synchronizing cronjobs your products will be automatically processed, images added, and the categories set. Every 5 minutes all stock changes are processed. We provide a up-to-date plugin, easy setup and always the best support.
    6 Version:     4.2.4
     6Version:     4.2.5
    77Requires Plugins: woocommerce
    88Author:      Arture
Note: See TracChangeset for help on using the changeset viewer.