Plugin Directory

Changeset 3434321


Ignore:
Timestamp:
01/07/2026 12:11:42 PM (3 months ago)
Author:
arture
Message:

Version 4.2.3

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

Legend:

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

    r3407611 r3434321  
    315315
    316316            $post_id = wp_insert_post($args);
    317             $cronjob_functions = new StoreContrl_Cronjob_Functions();
    318             $cronjob_functions->storecontrl_synchronize_product( $product['product_id'] );
    319317        }
    320318
     
    421419
    422420        if (isset($all_product_variations) && !empty($all_product_variations) && isset($product['variations'])) {
     421
     422            // Product full update if new variations are more than existing
     423            if( count($product['variations']) > count($all_product_variations) ){
     424                $cronjob_functions = new StoreContrl_Cronjob_Functions();
     425                $cronjob_functions->storecontrl_synchronize_product($product['product_id']);
     426            }
    423427
    424428            // Bij een full sync controleren of het aantal variaties overeenkomt met aantal in Woocommerce; nee = opschonen
     
    13701374    public function insert_product_variations( $product_id, $product )
    13711375    {
     1376        global $wpdb;
     1377
    13721378        $logging = new StoreContrl_WP_Connection_Logging();
    13731379
     
    14781484
    14791485            // Set barcode to the new GTIN field
    1480             if( !empty($variation['barcode']) ){
    1481                 $Variation->update_meta_data( '_global_unique_id', $variation['barcode'] );
     1486            if( !empty($variation['barcode']) && $this->is_valid_gtin($variation['barcode']) ) {
     1487
     1488                $ean = $variation['barcode'];
     1489                $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(
     1493                    $wpdb->prepare(
     1494                        "
     1495                        SELECT pm.post_id
     1496                        FROM {$wpdb->postmeta} pm
     1497                        INNER JOIN {$wpdb->posts} p
     1498                            ON p.ID = pm.post_id
     1499                        WHERE pm.meta_key   = %s
     1500                          AND pm.meta_value = %s
     1501                          AND p.post_type IN ('product','product_variation')
     1502                        LIMIT 1
     1503                        ",
     1504                        $meta_key,
     1505                        $ean
     1506                    )
     1507                );
     1508
     1509                if ($existing_id > 0) {
     1510                    $logging->log_file_write('NOTICE | Duplicate _global_unique_id: ' . $ean . ' (exist already on post ' . $existing_id . ')');
     1511                } else {
     1512                    $Variation->update_meta_data('_global_unique_id', $ean);
     1513                }
    14821514            }
    14831515
     
    18491881        return $slug;
    18501882    }
     1883
     1884    public function normalize_gtin(string $s): string {
     1885        return preg_replace('/\D+/', '', $s); // keep digits only
     1886    }
     1887
     1888    public function is_valid_gtin(string $code): bool {
     1889        $code = $this->normalize_gtin($code);
     1890        $len  = strlen($code);
     1891
     1892        // GTIN lengths: EAN-8, UPC-A (12), EAN-13, GTIN-14
     1893        if (!in_array($len, [8, 12, 13, 14], true)) {
     1894            return false;
     1895        }
     1896
     1897        // Check digit (last digit)
     1898        $check = (int)$code[$len - 1];
     1899
     1900        // Calculate expected check digit (GS1)
     1901        $sum = 0;
     1902        // Walk from right to left excluding check digit
     1903        for ($i = $len - 2, $pos = 1; $i >= 0; $i--, $pos++) {
     1904            $digit = (int)$code[$i];
     1905            // positions from the right: odd*3, even*1
     1906            $sum += ($pos % 2 === 1) ? $digit * 3 : $digit;
     1907        }
     1908        $expected = (10 - ($sum % 10)) % 10;
     1909
     1910        return $check === $expected;
     1911    }
     1912
     1913    public function gtin_type(string $code): ?string {
     1914        $code = $this->normalize_gtin($code);
     1915        return match (strlen($code)) {
     1916            8  => 'EAN-8',
     1917            12 => 'UPC-A',
     1918            13 => 'EAN-13',
     1919            14 => 'GTIN-14',
     1920            default => null,
     1921        };
     1922    }
     1923
    18511924}
  • storecontrl-wp-connection/trunk/includes/api/class-storecontrl-web-api.php

    r3350913 r3434321  
    215215
    216216    public function storecontrl_get_sku_stock_changes() {
    217 
    218         // Get data from resulting URL
    219217        $request_url = '/Sku/GetSkuStockChanges';
    220218        $args = array(
     
    226224        return  $results;
    227225    }
     226
     227    public function GetCustomerDiscount( $email ) {
     228        $request_url = '/Customer/GetCustomerDiscount/'.$email;
     229        $args = array(
     230            'content_type' => 'application/json',
     231            'has_sessionId' => false
     232        );
     233        $results = $this->curl_request( $request_url, 'GET', $args );
     234
     235        return  $results;
     236    }
    228237
    229238    public function storecontrl_remove_sku_stock_changes( $processed_products = '') {
  • storecontrl-wp-connection/trunk/includes/cronjob/class-storecontrl-cronjob-functions.php

    r3407611 r3434321  
    226226            $web_api = new StoreContrl_Web_Api();
    227227            $output = array();
    228             $product = $web_api->curl_request("/Product/GetProductInfo/" . $sc_product_id, 'GET');
     228            $product = $web_api->curl_request("/Product/GetProductInfo/" . $sc_product_id . "?sendEan=true", 'GET');
    229229
    230230            $output[$product['product_id']] = $product;
     
    546546                                }
    547547
    548                                 // Add product full import to queue
    549                                 $this->storecontrl_synchronize_product($product_variations['product_id']);
    550 
    551548                                $all_variations[$key]->processed = 'true';
    552549                                file_put_contents( $directory . '/' . $file, json_encode($all_variations) );
     
    573570                                    continue;
    574571                                }
    575 
    576                                 // Add product full import to queue
    577                                 $this->storecontrl_synchronize_product($product_variations['product_id']);
    578572
    579573                                $all_variations[$key]->processed = 'true';
  • storecontrl-wp-connection/trunk/includes/woocommerce/class-storecontrl-woocommerce-functions.php

    r3407611 r3434321  
    99        add_filter('handle_bulk_actions-edit-product', array($this, 'handle_sc_bulk_action'), 10, 3);
    1010        add_action('admin_notices', array($this, 'show_bulk_succes_message'));
     11
     12        add_action('init', function () {
     13            add_rewrite_endpoint('spaarpunten', EP_ROOT | EP_PAGES);
     14        });
     15
     16        add_filter('woocommerce_get_query_vars', function ($vars) {
     17            $vars['spaarpunten'] = 'spaarpunten';
     18            return $vars;
     19        });
     20
     21        add_filter('woocommerce_account_menu_items', array($this, 'sc_woocommerce_account_menu_items'), 10, 1);
     22        add_action('woocommerce_account_spaarpunten_endpoint', array($this, 'woocommerce_account_spaarpunten_endpoint'));
     23    }
     24
     25    public function sc_woocommerce_account_menu_items($items) {
     26        // Plaats bijvoorbeeld vóór "Uitloggen"
     27        $logout = $items['customer-logout'] ?? null;
     28        if ($logout !== null) unset($items['customer-logout']);
     29
     30        $items['spaarpunten'] = 'Spaarpunten';
     31
     32        if ($logout !== null) $items['customer-logout'] = $logout;
     33        return $items;
     34    }
     35
     36    public function woocommerce_account_spaarpunten_endpoint() {
     37        $user = wp_get_current_user();
     38        $email = $user->user_email ?? '';
     39
     40        echo '<h2>Spaarpunten</h2>';
     41
     42        if (empty($email)) {
     43            echo '<p>Geen e-mailadres gevonden.</p>';
     44            return;
     45        }
     46
     47        $web_api = new StoreContrl_Web_Api();
     48        $GetCustomerDiscount = $web_api->GetCustomerDiscount($email);
     49
     50        echo '<pre>';
     51        print_r($GetCustomerDiscount);
     52        echo '</pre>';
     53        exit;
     54
     55        echo '<p>Totaal spaarpunten voor <strong>' . esc_html($email) . '</strong>:</p>';
     56        echo '<p style="font-size:24px; font-weight:700;">' . esc_html('TODO') . '</p>';
    1157    }
    1258
     
    3177            foreach( $post_ids as $post_id ) {
    3278                $sc_product_id = get_post_meta( $post_id, 'sc_product_id', true );
    33                 $product = $web_api->curl_request("/Product/GetProductInfo/" . $sc_product_id, 'GET');
     79                $product = $web_api->curl_request("/Product/GetProductInfo/" . $sc_product_id . "?sendEan=true", 'GET');
    3480
    3581                $output[$product['product_id']] = $product;
     
    890936            }
    891937
    892             if (strlen(get_post_meta($order_id, 'order_returned_successfully_to_storecontrl', true)) > 0) {
     938            $order_returned_successfully_to_storecontrl_hpos = $order->get_meta('order_returned_successfully_to_storecontrl');
     939            $order_returned_successfully_to_storecontrl = get_post_meta($order_id, 'order_returned_successfully_to_storecontrl', true);
     940            if( strlen($order_returned_successfully_to_storecontrl_hpos) > 0 || strlen($order_returned_successfully_to_storecontrl) > 0 ){
    893941                //ORDER HAS BEEN SENT TO STORECONTRL
    894                 if (get_post_meta($order_id, 'order_returned_successfully_to_storecontrl', true) == '1') {
     942                if ($order_returned_successfully_to_storecontrl_hpos == '1' || $order_returned_successfully_to_storecontrl == '1') {
    895943                    echo __("Succesvol teruggekoppeld");
    896944                }
  • storecontrl-wp-connection/trunk/readme.txt

    r3407611 r3434321  
    55Requires at least: 6.6.0
    66Tested up to: 6.8.3
    7 Stable tag: 4.2.2
     7Stable tag: 4.2.3
    88Requires PHP: 8.0
    99License: GPLv2 or later
     
    9393== Changelog ==
    9494
     95= 4.2.3 =
     96* Optimalisatie in product update flow
     97
    9598= 4.2.2 =
    9699* Wijziging van logica bij sku_changed en sku_added naar full product import
  • storecontrl-wp-connection/trunk/storecontrl-wp-connection.php

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