Changeset 3434321
- Timestamp:
- 01/07/2026 12:11:42 PM (3 months ago)
- Location:
- storecontrl-wp-connection/trunk
- Files:
-
- 6 edited
-
includes/api/class-storecontrl-web-api-functions.php (modified) (5 diffs)
-
includes/api/class-storecontrl-web-api.php (modified) (2 diffs)
-
includes/cronjob/class-storecontrl-cronjob-functions.php (modified) (3 diffs)
-
includes/woocommerce/class-storecontrl-woocommerce-functions.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
storecontrl-wp-connection.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
storecontrl-wp-connection/trunk/includes/api/class-storecontrl-web-api-functions.php
r3407611 r3434321 315 315 316 316 $post_id = wp_insert_post($args); 317 $cronjob_functions = new StoreContrl_Cronjob_Functions();318 $cronjob_functions->storecontrl_synchronize_product( $product['product_id'] );319 317 } 320 318 … … 421 419 422 420 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 } 423 427 424 428 // Bij een full sync controleren of het aantal variaties overeenkomt met aantal in Woocommerce; nee = opschonen … … 1370 1374 public function insert_product_variations( $product_id, $product ) 1371 1375 { 1376 global $wpdb; 1377 1372 1378 $logging = new StoreContrl_WP_Connection_Logging(); 1373 1379 … … 1478 1484 1479 1485 // 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 } 1482 1514 } 1483 1515 … … 1849 1881 return $slug; 1850 1882 } 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 1851 1924 } -
storecontrl-wp-connection/trunk/includes/api/class-storecontrl-web-api.php
r3350913 r3434321 215 215 216 216 public function storecontrl_get_sku_stock_changes() { 217 218 // Get data from resulting URL219 217 $request_url = '/Sku/GetSkuStockChanges'; 220 218 $args = array( … … 226 224 return $results; 227 225 } 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 } 228 237 229 238 public function storecontrl_remove_sku_stock_changes( $processed_products = '') { -
storecontrl-wp-connection/trunk/includes/cronjob/class-storecontrl-cronjob-functions.php
r3407611 r3434321 226 226 $web_api = new StoreContrl_Web_Api(); 227 227 $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'); 229 229 230 230 $output[$product['product_id']] = $product; … … 546 546 } 547 547 548 // Add product full import to queue549 $this->storecontrl_synchronize_product($product_variations['product_id']);550 551 548 $all_variations[$key]->processed = 'true'; 552 549 file_put_contents( $directory . '/' . $file, json_encode($all_variations) ); … … 573 570 continue; 574 571 } 575 576 // Add product full import to queue577 $this->storecontrl_synchronize_product($product_variations['product_id']);578 572 579 573 $all_variations[$key]->processed = 'true'; -
storecontrl-wp-connection/trunk/includes/woocommerce/class-storecontrl-woocommerce-functions.php
r3407611 r3434321 9 9 add_filter('handle_bulk_actions-edit-product', array($this, 'handle_sc_bulk_action'), 10, 3); 10 10 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>'; 11 57 } 12 58 … … 31 77 foreach( $post_ids as $post_id ) { 32 78 $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'); 34 80 35 81 $output[$product['product_id']] = $product; … … 890 936 } 891 937 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 ){ 893 941 //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') { 895 943 echo __("Succesvol teruggekoppeld"); 896 944 } -
storecontrl-wp-connection/trunk/readme.txt
r3407611 r3434321 5 5 Requires at least: 6.6.0 6 6 Tested up to: 6.8.3 7 Stable tag: 4.2. 27 Stable tag: 4.2.3 8 8 Requires PHP: 8.0 9 9 License: GPLv2 or later … … 93 93 == Changelog == 94 94 95 = 4.2.3 = 96 * Optimalisatie in product update flow 97 95 98 = 4.2.2 = 96 99 * Wijziging van logica bij sku_changed en sku_added naar full product import -
storecontrl-wp-connection/trunk/storecontrl-wp-connection.php
r3407611 r3434321 4 4 Plugin URI: http://www.arture.nl/storecontrl 5 5 Description: 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. 26 Version: 4.2.3 7 7 Requires Plugins: woocommerce 8 8 Author: Arture
Note: See TracChangeset
for help on using the changeset viewer.