Changeset 2956645
- Timestamp:
- 08/22/2023 09:21:42 AM (3 years ago)
- Location:
- extendago-wp-connection/trunk
- Files:
-
- 8 edited
-
extendago-wp-connection.php (modified) (1 diff)
-
includes/admin/class-extendago-wp-connection-admin.php (modified) (12 diffs)
-
includes/admin/js/extendago-api-admin.js (modified) (1 diff)
-
includes/admin/partials/extendago_wp_connection_settings_page.php (modified) (1 diff)
-
includes/api/class-extendago-web-api.php (modified) (3 diffs)
-
includes/cronjob/class-extendago-cronjob-functions.php (modified) (5 diffs)
-
includes/woocommerce/class-extendago-woocommerce-functions.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
extendago-wp-connection/trunk/extendago-wp-connection.php
r2945883 r2956645 4 4 Plugin URI: http://www.arture.nl/extendago 5 5 Description: The Wordpress plugin for connecting Woocommerce with Extenda GO / Wallmob. You can manage your products inside Extenda GO or make your webshop as leading foor product manangement. You Stock changes will be two-way binding. 6 Version: 1.4. 16 Version: 1.4.2 7 7 Author: Arture B.V. 8 8 Author URI: https://arture.nl/ -
extendago-wp-connection/trunk/includes/admin/class-extendago-wp-connection-admin.php
r2932171 r2956645 2 2 class ExtendaGo_WP_Connection_Admin { 3 3 4 private $active_connection = false; 5 private $web_api; 6 4 7 public function __construct() { 8 9 $extendago_api_username = get_option( 'extendago_api_username' ); 10 $extendago_api_password = get_option( 'extendago_api_password' ); 11 $extendago_client_id = get_option( 'extendago_client_id' ); 12 $extendago_client_secret = get_option( 'extendago_client_secret' ); 13 14 // Check if connection available 15 if ( 16 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 17 || 18 isset( $extendago_client_id ) && ! empty( $extendago_client_id ) && isset( $extendago_client_secret ) && ! empty( $extendago_client_secret ) 19 ) { 20 $this->active_connection = true; 21 } 22 23 $this->web_api = new ExtendaGo_Web_Api(); 5 24 6 25 $plugin_basename = EXTENDAGO_WP_CONNECTION_PLUGIN_BASENAME; … … 56 75 $extendago_api_arture_key = get_option('extendago_api_arture_key'); 57 76 if( isset($extendago_api_arture_key) && !empty($extendago_api_arture_key) ) { 58 add_settings_field('extendago_api_username', esc_html(__('Extendago username', 'extendago-wp-connection-plugin')), array($this, 'display_extendago_api_username_element'), 'extendago_api_options', 'default_section'); 59 add_settings_field('extendago_api_password', esc_html(__('Extendago password', 'extendago-wp-connection-plugin')), array($this, 'display_extendago_api_password_element'), 'extendago_api_options', 'default_section'); 77 $extendago_client_id = get_option('extendago_client_id'); 78 if( !isset($extendago_client_id) || empty($extendago_client_id) ) { 79 add_settings_field('extendago_api_username', esc_html(__('Extendago username', 'extendago-wp-connection-plugin')), array($this, 'display_extendago_api_username_element'), 'extendago_api_options', 'default_section'); 80 add_settings_field('extendago_api_password', esc_html(__('Extendago password', 'extendago-wp-connection-plugin')), array($this, 'display_extendago_api_password_element'), 'extendago_api_options', 'default_section'); 81 } 82 add_settings_field('extendago_client_id', esc_html(__('Extendago Client ID', 'extendago-wp-connection-plugin')), array($this, 'display_extendago_client_id_element'), 'extendago_api_options', 'default_section'); 83 add_settings_field('extendago_client_secret', esc_html(__('Extendago Client Secret', 'extendago-wp-connection-plugin')), array($this, 'display_extendago_client_secret_element'), 'extendago_api_options', 'default_section'); 60 84 } 61 85 … … 98 122 add_settings_field('extendago_debug_logs', esc_html(__('Logs', 'extendago-wp-connection-plugin')), array( $this, 'display_extendago_debug_logs_element' ), 'extendago_debug_options', 'debug_section'); 99 123 124 register_setting('extendago_api_options', 'extendago_api_arture_key'); 100 125 register_setting('extendago_api_options', 'extendago_api_username'); 101 126 register_setting('extendago_api_options', 'extendago_api_password'); 102 register_setting('extendago_api_options', 'extendago_api_arture_key'); 127 register_setting('extendago_api_options', 'extendago_client_id'); 128 register_setting('extendago_api_options', 'extendago_client_secret'); 103 129 104 130 if ( class_exists( 'WooCommerce' ) ) { … … 143 169 ================================================= 144 170 */ 171 public function display_extendago_api_arture_key_element(){ 172 ?> 173 <input type='text' name='extendago_api_arture_key' id='extendago_api_arture_key' placeholder="<?php echo esc_html(__('Enter your license key', 'extendago-wp-connection-plugin')); ?>" value='<?php echo esc_html(get_option('extendago_api_arture_key')); ?>' style='min-width: 500px'/> 174 <?php 175 } 145 176 public function display_extendago_api_username_element(){ 146 177 ?> … … 153 184 <?php 154 185 } 155 public function display_extendago_api_arture_key_element(){ 156 ?> 157 <input type='text' name='extendago_api_arture_key' id='extendago_api_arture_key' placeholder="<?php echo esc_html(__('Enter your license key', 'extendago-wp-connection-plugin')); ?>" value='<?php echo esc_html(get_option('extendago_api_arture_key')); ?>' style='min-width: 500px'/> 186 public function display_extendago_client_id_element(){ 187 ?> 188 <input type='text' name='extendago_client_id' id='extendago_client_id' placeholder="<?php echo esc_html(__('API Client ID', 'extendago-wp-connection-plugin')); ?>" value='<?php echo esc_html(get_option('extendago_client_id')); ?>' style='min-width: 500px'/> 189 <?php 190 } 191 public function display_extendago_client_secret_element(){ 192 ?> 193 <input type='text' name='extendago_client_secret' id='extendago_client_secret' placeholder="<?php echo esc_html(__('API Client Secret', 'extendago-wp-connection-plugin')); ?>" value='<?php echo esc_html(get_option('extendago_client_secret')); ?>' style='min-width: 500px'/> 158 194 <?php 159 195 } … … 398 434 399 435 if ( class_exists( 'WooCommerce' ) ) { 400 $extendago_api_username = get_option( 'extendago_api_username' );401 $extendago_api_password = get_option( 'extendago_api_password' );402 436 403 437 // Check if connection available 404 if ( 405 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && 406 isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 407 ) { 408 409 $web_api = new ExtendaGo_Web_Api(); 410 $shop_groups = $web_api->CurlRequest('/shop_groups', 'GET'); 438 if ( $this->active_connection ) { 439 $shop_groups = $this->web_api->CurlRequest('/shop_groups', 'GET'); 411 440 if ( ! isset( $shop_groups ) || empty( $shop_groups ) ) { 412 441 echo '<div class="alert alert-warning" role="alert">' . __('Extendago shop groups unavailable or not set.', 'extendago-wp-connection-plugin') . '</div>'; … … 618 647 619 648 if ( class_exists( 'WooCommerce' ) ) { 620 $extendago_api_username = get_option( 'extendago_api_username' );621 $extendago_api_password = get_option( 'extendago_api_password' );622 649 623 650 // Check if connection available 624 if ( 625 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && 626 isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 627 ) { 628 629 $web_api = new ExtendaGo_Web_Api(); 630 $extendago_shops = $web_api->listShops(); 651 if ( $this->active_connection ) { 652 $extendago_shops = $this->web_api->listShops(); 631 653 632 654 if ( ! isset( $extendago_shops ) || empty( $extendago_shops ) ) { … … 664 686 665 687 if ( class_exists( 'WooCommerce' ) ) { 666 $extendago_api_username = get_option( 'extendago_api_username' );667 $extendago_api_password = get_option( 'extendago_api_password' );668 688 669 689 // Check if connection available 670 if ( 671 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && 672 isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 673 ) { 674 675 $web_api = new ExtendaGo_Web_Api(); 676 $extendago_stock_locations = $web_api->listStockLocations(); 690 if ( $this->active_connection ) { 691 692 $extendago_stock_locations = $this->web_api->listStockLocations(); 677 693 678 694 if ( ! isset( $extendago_stock_locations ) || empty( $extendago_stock_locations ) ) { … … 706 722 707 723 if ( class_exists( 'WooCommerce' ) ) { 708 $extendago_api_username = get_option( 'extendago_api_username' );709 $extendago_api_password = get_option( 'extendago_api_password' );710 724 711 725 // Check if connection available 712 if ( 713 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && 714 isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 715 ) { 726 if ( $this->active_connection ) { 727 716 728 $Extendago = new Extendago_Web_Api(); 717 729 $VatRates = $Extendago->CurlRequest("/vat_rates", "GET"); … … 794 806 795 807 if ( class_exists( 'WooCommerce' ) ) { 796 $extendago_api_username = get_option( 'extendago_api_username' );797 $extendago_api_password = get_option( 'extendago_api_password' );798 808 799 809 // Check if connection available 800 if ( 801 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && 802 isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 803 ) { 810 if ( $this->active_connection ) { 811 804 812 ?> 805 813 <label class="checkbox-inline"> … … 824 832 825 833 if ( class_exists( 'WooCommerce' ) ) { 826 $extendago_api_username = get_option( 'extendago_api_username' );827 $extendago_api_password = get_option( 'extendago_api_password' );828 829 834 830 835 // Check if connection available 831 if ( 832 isset( $extendago_api_username ) && ! empty( $extendago_api_username ) && 833 isset( $extendago_api_password ) && ! empty( $extendago_api_password ) 834 ) { 836 if ( $this->active_connection ) { 837 835 838 global $woocommerce; 836 839 … … 927 930 928 931 if($positive_result) { 929 $web_api = new ExtendaGo_Web_Api(); 930 $results = $web_api->listShops(); 932 $results = $this->web_api->listShops(); 931 933 932 934 if( isset($results) && !empty($results) ){ -
extendago-wp-connection/trunk/includes/admin/js/extendago-api-admin.js
r2930779 r2956645 67 67 68 68 $('.notice').remove(); 69 if (confirm('Please confirm to import/update all products available in Extendago into Woocommerce. If you want to import only products related to a specific shop en bale this setting on the Import/Export settings tab!')) {69 if (confirm('Please confirm to import/update all products available in Extendago into Woocommerce. If you want to import only products related to a specific shop enable this setting on the Import/Export settings tab!')) { 70 70 71 71 $(this).find('.loading').show(); -
extendago-wp-connection/trunk/includes/admin/partials/extendago_wp_connection_settings_page.php
r2932171 r2956645 53 53 <?php 54 54 $extendago_api_username = get_option('extendago_api_username'); 55 if( isset($extendago_api_arture_key) && !empty($extendago_api_arture_key) && ( !isset($extendago_api_username) || empty($extendago_api_username) ) ): 55 $extendago_client_id = get_option('extendago_client_id'); 56 if( 57 isset($extendago_api_arture_key) && !empty($extendago_api_arture_key) 58 && 59 ( 60 ( !isset($extendago_api_username) || empty($extendago_api_username) ) 61 && 62 ( !isset($extendago_client_id) || empty($extendago_client_id) ) 63 ) 64 ): 56 65 $install_completed = false; ?> 57 66 <div class="container"> -
extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php
r2945883 r2956645 5 5 private $extendago_api_password; 6 6 private $extendago_api_url; 7 private $extendago_client_id; 8 private $extendago_client_secret; 7 9 8 10 public function __construct() { 9 11 $this->extendago_api_username = get_option('extendago_api_username'); 10 12 $this->extendago_api_password = get_option('extendago_api_password'); 13 $this->extendago_client_id = get_option('extendago_client_id'); 14 $this->extendago_client_secret = get_option('extendago_client_secret'); 11 15 $this->extendago_api_url = 'https://pos-etail.wallmob.com'; 12 16 } 13 17 14 18 public function CurlRequest($request, $method = "GET", $params = array(), $AsJSON = false, $AsMultipart = false) { 19 20 $access_token = $this->getAccesToken(); 21 15 22 $ch = curl_init(); 16 23 if ($method == "POST" || $method == "PUT" || $method == "PATCH" ) { … … 30 37 } 31 38 39 echo '<pre>'; 40 print_r($url); 41 echo '</pre>'; 42 32 43 curl_setopt($ch, CURLOPT_URL, $url); 33 44 34 45 if ( $method != 'POST' ) curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); 35 $Headers = array( 36 'Authorization: Basic '.base64_encode($this->extendago_api_username.":".$this->extendago_api_password), 37 ); 46 47 // CHECK FOR NEW AUTH METHOD 48 if( isset($access_token) && !empty($access_token) ){ 49 $Headers = array( 50 'Authorization: Bearer ' . $access_token, 51 ); 52 } 53 else { 54 $Headers = array( 55 'Authorization: Basic ' . base64_encode($this->extendago_api_username . ":" . $this->extendago_api_password), 56 ); 57 } 58 38 59 if ($AsMultipart) $Headers[] = 'Content-Type: multipart/form-data'; 39 60 curl_setopt($ch, CURLOPT_HTTPHEADER, $Headers); 40 61 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 62 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 41 63 $result = curl_exec($ch); 42 64 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); … … 69 91 } 70 92 71 public function Request($request, $method = "GET", $params = array(), $AsJSON = false, $AsMultipart = false) { 72 73 $args['headers'] = array( 74 'Authorization' => 'Basic '.base64_encode($this->extendago_api_username.":".$this->extendago_api_password), 93 public function getAccesToken() { 94 95 $params = array( 96 'grant_type' => 'client_credentials', 97 'client_id' => $this->extendago_client_id, 98 'client_secret' => $this->extendago_client_secret, 75 99 ); 76 100 77 if ($AsMultipart){ 78 $args['headers'][] = 'Content-Type: multipart/form-data'; 79 } 80 81 if ($method == "POST") { 82 if ($params != NULL) { 83 if ($AsJSON){ 84 $args['body'] = json_encode($params); 85 } 86 elseif ($AsMultipart){ 87 $args['body'] = $params; 88 } 89 else{ 90 $args['body'] = http_build_query($params); 91 } 92 } 93 94 $result = wp_remote_post($this->extendago_api_url . $request, $args); 95 } 96 elseif ($method == "DELETE") { 97 $args['method'] = 'DELETE'; 98 $result = wp_remote_post($this->extendago_api_url . $request, $args); 99 } 100 elseif ($params != NULL) { 101 $result = wp_remote_get( $this->extendago_api_url . $request."?".http_build_query($params) . $request, $args ); 102 } 103 else { 104 $result = wp_remote_get($this->extendago_api_url . $request, $args); 105 } 106 107 if ( !is_wp_error( $result ) || wp_remote_retrieve_response_code( $result ) == 200 ) { 108 $result = json_decode($result['body'], true); 109 if (json_last_error() == JSON_ERROR_NONE) { 110 return $result; 111 } 112 } 113 else{ 114 $logging = new ExtendaGo_WP_Connection_Logging(); 115 $logging->log_file_write( $result->get_error_message() ); 116 } 117 118 return NULL; 101 $url = $this->extendago_api_url . '/auth/token'; 102 103 $ch = curl_init(); 104 curl_setopt($ch, CURLOPT_URL, $url); 105 curl_setopt($ch, CURLOPT_POST, 1); 106 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); 107 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 108 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 109 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 110 $result = curl_exec($ch); 111 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 112 curl_close ($ch); 113 114 if ($http_code == 200 || $http_code == 400) { 115 $result = json_decode($result, true); 116 117 update_option('extendago_access_token', $result['access_token']); 118 119 return $result['access_token']; 120 } 121 122 return; 119 123 } 120 124 -
extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php
r2945883 r2956645 599 599 // Move file to temp folder 600 600 $current_file_path = $directory . '/' . $file; 601 $temp_file_name = date('Y-m-d_H :i') . '_' . $file;601 $temp_file_name = date('Y-m-d_H.i') . '_' . $file; 602 602 $new_file_path = $directory . '/temp/' . $temp_file_name; 603 603 … … 682 682 $data_array = file_get_contents( $directory . '/' . $file ); 683 683 $results = json_decode( $data_array ); 684 685 $file_finished = true;686 684 687 685 // Check if existing batches … … 1054 1052 } 1055 1053 1056 // Only move if finished 1057 if( $file_finished ) { 1058 unlink($directory . '/' . $file); 1059 $this->logging->log_file_write('EXPORT | Batch finished: ' . $file); 1060 } 1061 else{ 1062 $this->logging->log_file_write('EXPORT | Batch retry because not all data has been processed: ' . $file); 1063 } 1054 $this->logging->log_file_write('EXPORT | Batch finished: ' . $file); 1064 1055 } 1065 1056 else{ … … 1111 1102 $params = array( 1112 1103 'from' => time() - 60*12, // Afgelopen 12 minuten 1113 'include' => array('products', 'promotion_campaigns', 'product_categories')1104 'include' => json_encode(array('products', 'promotion_campaigns', 'product_categories')) 1114 1105 ); 1115 1106 $changes = $web_api->listChanges($params); 1116 1117 echo '<pre>';1118 print_r($changes);1119 echo '</pre>';1120 1107 1121 1108 // Upload directory … … 1124 1111 $new_upload_dir = $upload_dir . '/extendago/imports'; 1125 1112 1126 if( isset($changes ) && $changes['changes_found'] > 0 ) {1113 if( isset($changes['changes_found']) && $changes['changes_found'] > 0 ) { 1127 1114 1128 1115 $this->logging->log_file_write('Changes | Extendago product changes amount: ' . $changes['changes_found']); -
extendago-wp-connection/trunk/includes/woocommerce/class-extendago-woocommerce-functions.php
r2945883 r2956645 259 259 $variation_price = $variation_meta['_regular_price'][0]; 260 260 $variation_regular_price = $variation_meta['_regular_price'][0]; 261 $variation_sale_price = $variation_meta['_sale_price'][0];261 $variation_sale_price = ''; 262 262 263 263 // Check for prices exclude vat … … 270 270 } 271 271 272 if( isset($variation_ sale_price) && !empty($variation_sale_price) ){273 $variation_sale_price = ( $variation_ sale_price/ 100 ) * ( $default_tax + 100 );272 if( isset($variation_meta['_sale_price'][0]) && !empty($variation_meta['_sale_price'][0]) ){ 273 $variation_sale_price = ( $variation_meta['_sale_price'][0] / 100 ) * ( $default_tax + 100 ); 274 274 } 275 275 } … … 851 851 require_once(__DIR__ . "/../api/class-extendago-web-api.php"); 852 852 $Extendago = new Extendago_Web_Api(); 853 $Voucher = $Extendago-> Request('/vouchers/'.$_POST['voucher'], 'GET');853 $Voucher = $Extendago->CurlRequest('/vouchers/'.$_POST['voucher'], 'GET'); 854 854 855 855 if (isset($Voucher['id'])) { … … 868 868 require_once(__DIR__ . "/../api/class-extendago-web-api.php"); 869 869 $Extendago = new Extendago_Web_Api(); 870 $Voucher = $Extendago-> Request('/vouchers/'.$_GET['voucher'], 'GET');870 $Voucher = $Extendago->CurlRequest('/vouchers/'.$_GET['voucher'], 'GET'); 871 871 872 872 if (isset($Voucher['id'])) { -
extendago-wp-connection/trunk/readme.txt
r2945883 r2956645 4 4 Tags: extendago, extenda, woocommerce, arture, POS, 5 5 Requires at least: 6.0 6 Tested up to: 6. 2.27 Stable tag: 1.4. 16 Tested up to: 6.3.0 7 Stable tag: 1.4.2 8 8 Requires PHP: 7.4 9 9 License: GPLv2 or later … … 30 30 31 31 == Changelog == 32 33 = 1.4.2 = 34 * New token based API method 35 * Bugfix for changed api call for changes 36 * Code performance 32 37 33 38 = 1.4.1 =
Note: See TracChangeset
for help on using the changeset viewer.