Plugin Directory

Changeset 3435393


Ignore:
Timestamp:
01/08/2026 05:59:33 PM (3 months ago)
Author:
arture
Message:

Version 4.2.4

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

Legend:

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

    r3434321 r3435393  
    1313
    1414    private $functions;
     15    private $cronjob_functions;
     16    private $logging;
     17
    1518    private $storecontrl_api_ftp_user;
    1619    private $storecontrl_api_ftp_password;
     
    2225    {
    2326        $this->functions = new StoreContrl_WP_Connection_Functions();
     27        $this->cronjob_functions = new StoreContrl_Cronjob_Functions();
     28        $this->logging = new StoreContrl_WP_Connection_Logging();
    2429        $this->use_instock_variations = get_option('storecontrl_use_instock_variations');
    2530        $this->storecontrl_api_ftp_user = get_option('storecontrl_api_ftp_user');
     
    3742            // Refresh if not exist
    3843            if( !isset($storecontrl_masterdata['VariationInfo']) || empty($storecontrl_masterdata['VariationInfo']) ){
    39                 $cronjob_functions = new StoreContrl_Cronjob_Functions();
    40                 $cronjob_functions->storecontrl_set_masterdata();
     44                $this->cronjob_functions->storecontrl_set_masterdata();
    4145
    4246                $storecontrl_masterdata = file_get_contents($directory . '/MasterData.json');
     
    5357    {
    5458        $web_api = new StoreContrl_Web_Api();
    55         $logging = new StoreContrl_WP_Connection_Logging();
     59        $logging = $this->logging;
    5660
    5761        // Upload directory
     
    104108    public function set_product_masterdata($product)
    105109    {
    106         $logging = new StoreContrl_WP_Connection_Logging();
     110        $logging = $this->logging;
    107111
    108112        $output = $product;
     
    177181    public function set_product_variations_data($variations)
    178182    {
    179         $logging = new StoreContrl_WP_Connection_Logging();
     183        $logging = $this->logging;
    180184
    181185        $mapped_variations = $this->storecontrl_masterdata['VariationInfo'];
     
    230234    public function storecontrl_update_wc_product($product, $full_sync = false)
    231235    {
     236        // DEBUG
     237        $start = microtime(true);
     238        $logging = $this->logging;
    232239
    233240        // Get all masterdata by product id's
     
    400407            $storecontrl_keep_product_images = get_option('storecontrl_keep_product_images');
    401408            if (!isset($storecontrl_keep_product_images) || !$storecontrl_keep_product_images || !has_post_thumbnail($post_id)) {
    402                 $cronjob_functions = new StoreContrl_Cronjob_Functions();
    403                 $this::$storecontrl_ftp_connection = $cronjob_functions->GetFTPConnection(true);
     409                $this::$storecontrl_ftp_connection = $this->cronjob_functions->GetFTPConnection(true);
    404410                $gallery_image_ids = $this->save_product_images($post_id, $product);
    405411                $Product->set_gallery_image_ids($gallery_image_ids);
     
    422428            // Product full update if new variations are more than existing
    423429            if( count($product['variations']) > count($all_product_variations) ){
    424                 $cronjob_functions = new StoreContrl_Cronjob_Functions();
    425                 $cronjob_functions->storecontrl_synchronize_product($product['product_id']);
     430                $this->cronjob_functions->storecontrl_synchronize_product($product['product_id']);
    426431            }
    427432
     
    444449                if( isset($new_product_size_list) && !empty($new_product_size_list) ) {
    445450                    if (!in_array($storecontrl_size_id, $new_product_size_list)) {
    446                         $logging = new StoreContrl_WP_Connection_Logging();
    447451                        $logging->log_file_write('DEBUG | Variation ' . $variation_post_id . ' deleted from product: ' . $post_id . ' beacuse variation don\'t exist in StoreContrl.');
    448452                        wp_delete_post($variation_post_id, true);
     
    745749            if (!isset($storecontrl_keep_product_status) || !$storecontrl_keep_product_status) {
    746750                $post_status = $no_image_post_status;
    747 
    748                 // LOG
    749                 $logging = new StoreContrl_WP_Connection_Logging();
    750751                $logging->log_file_write('Status | Post (' . $post_id . ') has no image. Updating post-status to: ' . $no_image_post_status);
    751752            }
     
    10401041                        $sub_category_id_1 = $sub_category_1->get_error_data("term_exists");
    10411042                    } else {
    1042                         $logging = new StoreContrl_WP_Connection_Logging();
    1043                         $logging->log_file_write('WP error | Error creating new subterm');
     1043                        $this->logging->log_file_write('WP error | Error creating new subterm');
    10441044                    }
    10451045                } else {
     
    11431143                            if (is_wp_error($main_category)) {
    11441144                                $error_string = $main_category->get_error_message();
    1145                                 $logging = new StoreContrl_WP_Connection_Logging();
    1146                                 $logging->log_file_write('WP error | ' . $error_string);
     1145                                $this->logging->log_file_write('WP error | ' . $error_string);
    11471146                            } else {
    11481147                                $main_category_id = $main_category['term_id'];
     
    11751174                            if (is_wp_error($sub_category_1)) {
    11761175                                $error_string = $sub_category_1->get_error_message();
    1177                                 $logging = new StoreContrl_WP_Connection_Logging();
    1178                                 $logging->log_file_write('WP error | ' . $error_string);
     1176                                $this->logging->log_file_write('WP error | ' . $error_string);
    11791177                            } else {
    11801178                                $sub_category_id_1 = $sub_category_1['term_id'];
     
    12051203                            if (is_wp_error($sub_category_2)) {
    12061204                                $error_string = $sub_category_2->get_error_message();
    1207                                 $logging = new StoreContrl_WP_Connection_Logging();
    1208                                 $logging->log_file_write('WP error | ' . $error_string);
     1205                                $this->logging->log_file_write('WP error | ' . $error_string);
    12091206                            } else {
    12101207                                $sub_category_id_2 = $sub_category_2['term_id'];
     
    13441341            if (isset($attribute_id->errors)) {
    13451342                foreach ($attribute_id->errors as $error) {
    1346                     $logging = new StoreContrl_WP_Connection_Logging();
    1347                     $logging->log_file_write('ERROR | ' . $error[0]);
     1343                    $this->logging->log_file_write('ERROR | ' . $error[0]);
    13481344                }
    13491345            }
     
    13741370    public function insert_product_variations( $product_id, $product )
    13751371    {
    1376         global $wpdb;
    1377 
    1378         $logging = new StoreContrl_WP_Connection_Logging();
     1372        $logging = $this->logging;
    13791373
    13801374        $variations = $product['variations'];
     
    14831477            }
    14841478
    1485             // Set barcode to the new GTIN field
    1486             if( !empty($variation['barcode']) && $this->is_valid_gtin($variation['barcode']) ) {
    1487 
    1488                 $ean = $variation['barcode'];
     1479            /// Set barcode to the new GTIN field
     1480            if ( ! empty($variation['barcode']) && $this->is_valid_gtin($variation['barcode']) ) {
     1481
     1482                global $wpdb;
     1483
     1484                $ean      = $variation['barcode'];
    14891485                $meta_key = '_global_unique_id';
    1490 
    1491                 // check of er al een ander product/variatie is met dezelfde EAN
    1492                 $existing_id = (int)$wpdb->get_var(
     1486                $current_id = (int) $variation_post_id; // dit is jouw eigen variatie ID
     1487
     1488                // check of er al een ander product/variatie is met dezelfde EAN (behalve deze zelf)
     1489                $existing_id = (int) $wpdb->get_var(
    14931490                    $wpdb->prepare(
    14941491                        "
     
    14991496                        WHERE pm.meta_key   = %s
    15001497                          AND pm.meta_value = %s
     1498                          AND pm.post_id   != %d
    15011499                          AND p.post_type IN ('product','product_variation')
     1500                          AND p.post_status NOT IN ('trash','auto-draft')
    15021501                        LIMIT 1
    15031502                        ",
    15041503                        $meta_key,
    1505                         $ean
     1504                        $ean,
     1505                        $current_id
    15061506                    )
    15071507                );
    15081508
    1509                 if ($existing_id > 0) {
    1510                     $logging->log_file_write('NOTICE | Duplicate _global_unique_id: ' . $ean . ' (exist already on post ' . $existing_id . ')');
     1509                if ( $existing_id > 0 ) {
     1510                    $logging->log_file_write(
     1511                        'NOTICE | Duplicate _global_unique_id: ' . $ean . ' (exists already on post ' . $existing_id . ')'
     1512                    );
    15111513                } else {
    15121514                    $Variation->update_meta_data('_global_unique_id', $ean);
     
    16681670        $attachment_ids = [];
    16691671        $functions = new StoreContrl_WP_Connection_Functions();
    1670         $logging = new StoreContrl_WP_Connection_Logging();
     1672        $logging = $this->logging;
    16711673
    16721674        $storecontrl_hide_featured_image_from_gallery = get_option('storecontrl_hide_featured_image_from_gallery');
     
    16871689
    16881690            // Verwijder niet-bestaande afbeeldingen
    1689             if ($attach_id && !$functions->is_url_exist(wp_get_attachment_url($attach_id))) {
    1690                 wp_delete_attachment($attach_id);
    1691                 $attach_id = null;
     1691            if ($attach_id) {
     1692                $file = get_attached_file($attach_id);
     1693                if (!$file || !file_exists($file)) {
     1694                    wp_delete_attachment($attach_id, true);
     1695                    $attach_id = null;
     1696                }
    16921697            }
    16931698
     
    17331738                }
    17341739                if ($is_featured) {
    1735                     set_post_thumbnail($post_id, $attach_id);
     1740                    $current_thumb = (int) get_post_meta($post_id, '_thumbnail_id', true);
     1741                    if ($current_thumb !== $attach_id) {
     1742                        set_post_thumbnail($post_id, $attach_id);
     1743                    }
    17361744                } else {
    17371745                    $attachment_ids[] = $attach_id;
     
    17471755        global $wpdb;
    17481756
    1749         $logging = new StoreContrl_WP_Connection_Logging();
     1757        $logging = $this->logging;
    17501758
    17511759        $existing_product_variation = $wpdb->get_results(
  • storecontrl-wp-connection/trunk/includes/cronjob/class-storecontrl-cronjob-functions.php

    r3434321 r3435393  
    240240            unset($output[$product['product_id']]['sku_list']);
    241241
    242             file_put_contents($new_upload_dir . '/products_batch_' . $sc_product_id . '.json', json_encode($output));
     242            file_put_contents($new_upload_dir . '/'.time().'_products_batch_' . $sc_product_id . '.json', json_encode($output));
    243243        }
    244244    }
     
    339339                    $products_array = json_encode($products_array);
    340340
    341                     $success = file_put_contents($new_upload_dir . '/products_batch_' . $batch . '.json', $products_array);
     341                    $success = file_put_contents($new_upload_dir . '/'.time().'_products_batch_' . $batch . '.json', $products_array);
    342342                    if( $success === FALSE ){
    343343                        $this->logging->log_file_write( 'ERROR | Product batch ' .$batch. ' not created!' );
  • storecontrl-wp-connection/trunk/includes/woocommerce/class-storecontrl-woocommerce-functions.php

    r3434321 r3435393  
    9292            }
    9393
    94             file_put_contents($new_upload_dir . '/products_batch_bulk.json', json_encode($output));
     94            file_put_contents($new_upload_dir . '/'.time().'_products_batch_bulk.json', json_encode($output));
    9595
    9696            $redirect_url = add_query_arg('storecontrl-import-started', count($post_ids), $redirect_url);
     
    636636                    $order->update_meta_data('order_returned_successfully_to_storecontrl', '1');
    637637                } elseif ($results == 'OrderId already exists') {
    638                     //update_post_meta($order_id, 'order_returned_successfully_to_storecontrl', '1');
    639638                    $order->update_meta_data('order_returned_successfully_to_storecontrl', '1');
    640639                    $message = 'OrderId already exists: ' . $order_data['id'];
  • storecontrl-wp-connection/trunk/readme.txt

    r3434321 r3435393  
    55Requires at least: 6.6.0
    66Tested up to: 6.8.3
    7 Stable tag: 4.2.3
     7Stable tag: 4.2.4
    88Requires PHP: 8.0
    99License: GPLv2 or later
  • storecontrl-wp-connection/trunk/storecontrl-wp-connection.php

    r3434321 r3435393  
    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.3
     6Version:     4.2.4
    77Requires Plugins: woocommerce
    88Author:      Arture
Note: See TracChangeset for help on using the changeset viewer.