Plugin Directory

Changeset 3370412


Ignore:
Timestamp:
09/30/2025 12:34:52 PM (6 months ago)
Author:
arture
Message:

Version 4.2.0

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

Legend:

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

    r3350913 r3370412  
    6767            $processed_products = '';
    6868            $results = $web_api->storecontrl_get_sku_stock_changes();
    69 
    7069            if (isset($results) && is_array($results) && !empty($results)) {
    7170
     
    479478                $Product->set_gallery_image_ids($gallery_image_ids);
    480479                ftp_close($this::$storecontrl_ftp_connection);
     480
     481                do_action('storecontrl_after_gallery_save', $post_id, $gallery_image_ids);
    481482            }
    482483        }
     
    17681769    {
    17691770        global $wpdb;
    1770 
    17711771        $logging = new StoreContrl_WP_Connection_Logging();
    17721772
    1773         //removed limit 1 to form an array and loop through the array
    17741773        $existing_product_variation = $wpdb->get_results($wpdb->prepare("
    1775             SELECT *
    1776             FROM $wpdb->postmeta
    1777             WHERE meta_key = 'storecontrl_size_id' AND meta_value = '%s'
    1778             ORDER BY meta_id DESC
    1779          ", $product_variation['sku_id']), 'ARRAY_A');
     1774        SELECT *
     1775        FROM $wpdb->postmeta
     1776        WHERE meta_key = 'storecontrl_size_id' AND meta_value = %s
     1777        ORDER BY meta_id DESC
     1778    ", $product_variation['sku_id']), ARRAY_A);
    17801779
    17811780        foreach ($existing_product_variation as $variation) {
    17821781
    1783             // Check if variation exist
    1784             if (isset($variation['post_id']) && !empty($variation['post_id'])) {
    1785 
    1786                 $variation_post_id = $variation['post_id'];
    1787                 $product_id = wp_get_post_parent_id($variation_post_id);
    1788 
    1789                 $Variation = new WC_Product_Variation( $variation_post_id );
    1790 
    1791                 if( isset($product_id) && is_int($product_id) ){
    1792                     $Variation->set_parent_id($product_id);
    1793                 }
    1794                 else{
    1795                     $logging->log_file_write('ERROR | Unkown parent product for varation: ' . $variation_post_id );
    1796                     $wpdb->query($wpdb->prepare("DELETE * FROM $wpdb->postmeta WHERE meta_id = '%s'", $variation['meta_id']), 'ARRAY_A');
    1797                     return;
    1798                 }
    1799 
    1800                 if(abs($product_variation['stock_total']) != $product_variation['stock_total']){
    1801                     $product_variation['stock_total'] = 0;
    1802                 }
    1803                 $Variation->set_stock_quantity($product_variation['stock_total']);
    1804                 $Variation->set_manage_stock('yes');
    1805 
    1806 
    1807                 $logging->log_file_write('StoreContrl | Update stock of variation: ' . $variation_post_id . ' / ' . $product_variation['sku_id']. ' with new stock total: ' .$product_variation['stock_total']);
    1808 
    1809                 // Remove sale dates from variation if zero stock otherwise it gets backorder status by WC
    1810                 if( $product_variation['stock_total'] == 0 ){
     1782            if (!empty($variation['post_id'])) {
     1783                $variation_post_id = (int) $variation['post_id'];
     1784                $product_id = (int) wp_get_post_parent_id($variation_post_id);
     1785
     1786                if ($product_id <= 0) {
     1787                    $logging->log_file_write('ERROR | Unknown parent product for variation: ' . $variation_post_id );
     1788                    // let op: correcte DELETE syntaxis + prepared helper:
     1789                    $wpdb->delete($wpdb->postmeta, ['meta_id' => (int)$variation['meta_id']], ['%d']);
     1790                    continue;
     1791                }
     1792
     1793                $stock = (int) max(0, (int)$product_variation['stock_total']);
     1794
     1795                // Dit wijzigt alléén voorraad; geen attributen of andere meta.
     1796                wc_update_product_stock($variation_post_id, $stock, 'set');
     1797                wc_update_product_stock_status($variation_post_id, $stock > 0 ? 'instock' : 'outofstock');
     1798
     1799                $logging->log_file_write(
     1800                    sprintf('StoreContrl | Update stock of variation: %d / %s to: %d',
     1801                        $variation_post_id,
     1802                        $product_variation['sku_id'],
     1803                        $stock
     1804                    )
     1805                );
     1806
     1807                // Optioneel: backorders en sale-datums alleen via meta bij 0 voorraad
     1808                if ($stock === 0) {
    18111809                    $_backorders = get_post_meta($variation_post_id, '_backorders', true);
    1812                     if ($_backorders != 'notify' && $_backorders != 'yes' ) {
    1813                         $Variation->set_date_on_sale_from();
    1814                         $Variation->set_date_on_sale_to();
    1815                         $Variation->set_backorders('no');
    1816                     }
    1817                 }
    1818 
    1819                 $Variation->save();
    1820 
    1821                 $this->functions->custom_update_post_meta($variation_post_id, 'latest_update', date('Y-m-d H:i'));
    1822             }
    1823             else{
    1824                 $logging->log_file_write('StoreContrl | Unable to find variation: ' . $product_variation['sku_id']. ' to update a new stock total: ' .$product_variation['stock_total']);
     1810                    if ($_backorders !== 'notify' && $_backorders !== 'yes') {
     1811                        delete_post_meta($variation_post_id, '_sale_price_dates_from');
     1812                        delete_post_meta($variation_post_id, '_sale_price_dates_to');
     1813                        update_post_meta($variation_post_id, '_backorders', 'no');
     1814                    }
     1815                }
     1816
     1817                $this->functions->custom_update_post_meta($variation_post_id, 'latest_update', current_time('Y-m-d H:i'));
     1818            } else {
     1819                $logging->log_file_write('StoreContrl | Unable to find variation: ' . $product_variation['sku_id'] . ' to update a new stock total: ' . $product_variation['stock_total']);
    18251820            }
    18261821        }
  • storecontrl-wp-connection/trunk/includes/cronjob/class-storecontrl-cronjob-functions.php

    r3363222 r3370412  
    899899            $changes = $web_api->curl_request("/Data/GetChanges", "GET", $args);
    900900
    901             echo '<pre>';
    902             print_r($changes);
    903             echo '</pre>';
    904 
    905901            if( isset($changes) && !empty($changes) ) {
    906902
     
    15391535        }
    15401536
    1541         // Reset sale products because they can be planned
    1542         // Only ones after midnight
    1543         if( date('H') == '01' || date('H') == '12' ){
    1544             $this->logging->log_file_write( 'Cronjob | Update sale products' );
     1537        // Draai alleen om 01:00 en 12:00 én als er geen lock staat
     1538        $hour = (int) current_time('H');
     1539        if (in_array($hour, [1, 12], true) && ! get_transient('update_sale_products_lock')) {
     1540
     1541            // TTL tot nét voorbij het volgende uur (voorkomt dubbele runs in hetzelfde uur)
     1542            $minutes   = (int) current_time('i');
     1543            $ttl       = ((60 - $minutes) + 5) * MINUTE_IN_SECONDS;
     1544            set_transient('update_sale_products_lock', 1, $ttl);
     1545
     1546            $this->logging->log_file_write('Cronjob | Update sale products');
    15451547            $this->update_sale_products();
    15461548        }
  • storecontrl-wp-connection/trunk/readme.txt

    r3363222 r3370412  
    55Requires at least: 6.6.0
    66Tested up to: 6.8.2
    7 Stable tag: 4.1.9
     7Stable tag: 4.2.0
    88Requires PHP: 8.0
    99License: GPLv2 or later
     
    9393== Changelog ==
    9494
     95= 4.2.0 =
     96* Nieuwe add_action na het verwerken van de afbeelingen: storecontrl_after_gallery_save
     97* Aangepaste stock update actie
     98
    9599= 4.1.9 =
    96100* Wijziging in de verwerking van de afbeeldingen
  • storecontrl-wp-connection/trunk/storecontrl-wp-connection.php

    r3363222 r3370412  
    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.1.9
     6Version:     4.2.0
    77Requires Plugins: woocommerce
    88Author:      Arture
Note: See TracChangeset for help on using the changeset viewer.