Plugin Directory

Changeset 2956645


Ignore:
Timestamp:
08/22/2023 09:21:42 AM (3 years ago)
Author:
extendago
Message:

Version 1.4.2

Location:
extendago-wp-connection/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extendago-wp-connection/trunk/extendago-wp-connection.php

    r2945883 r2956645  
    44Plugin URI:  http://www.arture.nl/extendago
    55Description: 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.1
     6Version:     1.4.2
    77Author:      Arture B.V.
    88Author URI:  https://arture.nl/
  • extendago-wp-connection/trunk/includes/admin/class-extendago-wp-connection-admin.php

    r2932171 r2956645  
    22class ExtendaGo_WP_Connection_Admin {
    33
     4    private $active_connection = false;
     5    private $web_api;
     6
    47    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();
    524
    625        $plugin_basename = EXTENDAGO_WP_CONNECTION_PLUGIN_BASENAME;
     
    5675        $extendago_api_arture_key = get_option('extendago_api_arture_key');
    5776        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');
    6084        }
    6185
     
    98122        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');
    99123
     124        register_setting('extendago_api_options', 'extendago_api_arture_key');
    100125        register_setting('extendago_api_options', 'extendago_api_username');
    101126        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');
    103129
    104130        if ( class_exists( 'WooCommerce' ) ) {
     
    143169    =================================================
    144170    */
     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    }
    145176    public function display_extendago_api_username_element(){
    146177        ?>
     
    153184        <?php
    154185    }
    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'/>
    158194        <?php
    159195    }
     
    398434
    399435        if ( class_exists( 'WooCommerce' ) ) {
    400             $extendago_api_username     = get_option( 'extendago_api_username' );
    401             $extendago_api_password     = get_option( 'extendago_api_password' );
    402436
    403437            // 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');
    411440                if ( ! isset( $shop_groups ) || empty( $shop_groups ) ) {
    412441                    echo '<div class="alert alert-warning" role="alert">' . __('Extendago shop groups unavailable or not set.', 'extendago-wp-connection-plugin') . '</div>';
     
    618647
    619648        if ( class_exists( 'WooCommerce' ) ) {
    620             $extendago_api_username     = get_option( 'extendago_api_username' );
    621             $extendago_api_password     = get_option( 'extendago_api_password' );
    622649
    623650            // 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();
    631653
    632654                if ( ! isset( $extendago_shops ) || empty( $extendago_shops ) ) {
     
    664686
    665687        if ( class_exists( 'WooCommerce' ) ) {
    666             $extendago_api_username     = get_option( 'extendago_api_username' );
    667             $extendago_api_password     = get_option( 'extendago_api_password' );
    668688
    669689            // 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();
    677693
    678694                if ( ! isset( $extendago_stock_locations ) || empty( $extendago_stock_locations ) ) {
     
    706722
    707723        if ( class_exists( 'WooCommerce' ) ) {
    708             $extendago_api_username     = get_option( 'extendago_api_username' );
    709             $extendago_api_password     = get_option( 'extendago_api_password' );
    710724
    711725            // 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
    716728                $Extendago = new Extendago_Web_Api();
    717729                $VatRates = $Extendago->CurlRequest("/vat_rates", "GET");
     
    794806
    795807        if ( class_exists( 'WooCommerce' ) ) {
    796             $extendago_api_username     = get_option( 'extendago_api_username' );
    797             $extendago_api_password     = get_option( 'extendago_api_password' );
    798808
    799809            // 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
    804812                ?>
    805813                <label class="checkbox-inline">
     
    824832
    825833        if ( class_exists( 'WooCommerce' ) ) {
    826             $extendago_api_username     = get_option( 'extendago_api_username' );
    827             $extendago_api_password     = get_option( 'extendago_api_password' );
    828 
    829834
    830835            // 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
    835838                global $woocommerce;
    836839
     
    927930
    928931        if($positive_result) {
    929             $web_api = new ExtendaGo_Web_Api();
    930             $results = $web_api->listShops();
     932            $results = $this->web_api->listShops();
    931933
    932934            if( isset($results) && !empty($results) ){
  • extendago-wp-connection/trunk/includes/admin/js/extendago-api-admin.js

    r2930779 r2956645  
    6767
    6868        $('.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 enbale 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!')) {
    7070
    7171            $(this).find('.loading').show();
  • extendago-wp-connection/trunk/includes/admin/partials/extendago_wp_connection_settings_page.php

    r2932171 r2956645  
    5353    <?php
    5454    $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    ):
    5665        $install_completed = false; ?>
    5766        <div class="container">
  • extendago-wp-connection/trunk/includes/api/class-extendago-web-api.php

    r2945883 r2956645  
    55    private $extendago_api_password;
    66    private $extendago_api_url;
     7    private $extendago_client_id;
     8    private $extendago_client_secret;
    79
    810    public function __construct() {
    911        $this->extendago_api_username = get_option('extendago_api_username');
    1012        $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');
    1115        $this->extendago_api_url = 'https://pos-etail.wallmob.com';
    1216    }
    1317
    1418    public function CurlRequest($request, $method = "GET", $params = array(), $AsJSON = false, $AsMultipart = false) {
     19
     20        $access_token = $this->getAccesToken();
     21
    1522        $ch = curl_init();
    1623        if ($method == "POST" || $method == "PUT" || $method == "PATCH" ) {
     
    3037        }
    3138
     39        echo '<pre>';
     40        print_r($url);
     41        echo '</pre>';
     42
    3243        curl_setopt($ch, CURLOPT_URL, $url);
    3344
    3445        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
    3859        if ($AsMultipart) $Headers[] = 'Content-Type: multipart/form-data';
    3960        curl_setopt($ch, CURLOPT_HTTPHEADER, $Headers);
    4061        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     62        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    4163        $result = curl_exec($ch);
    4264        $http_code = curl_getinfo($ch,  CURLINFO_HTTP_CODE);
     
    6991    }
    7092
    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,
    7599        );
    76100
    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;
    119123    }
    120124
  • extendago-wp-connection/trunk/includes/cronjob/class-extendago-cronjob-functions.php

    r2945883 r2956645  
    599599                    // Move file to temp folder
    600600                    $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;
    602602                    $new_file_path = $directory . '/temp/' . $temp_file_name;
    603603
     
    682682                $data_array = file_get_contents( $directory . '/' . $file );
    683683                $results        = json_decode( $data_array );
    684 
    685                 $file_finished = true;
    686684
    687685                // Check if existing batches
     
    10541052                    }
    10551053
    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);
    10641055                }
    10651056                else{
     
    11111102        $params = array(
    11121103            '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'))
    11141105        );
    11151106        $changes = $web_api->listChanges($params);
    1116 
    1117         echo '<pre>';
    1118         print_r($changes);
    1119         echo '</pre>';
    11201107
    11211108        // Upload directory
     
    11241111        $new_upload_dir = $upload_dir . '/extendago/imports';
    11251112
    1126         if( isset($changes) && $changes['changes_found'] > 0 ) {
     1113        if( isset($changes['changes_found']) && $changes['changes_found'] > 0 ) {
    11271114
    11281115            $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  
    259259                        $variation_price = $variation_meta['_regular_price'][0];
    260260                        $variation_regular_price = $variation_meta['_regular_price'][0];
    261                         $variation_sale_price = $variation_meta['_sale_price'][0];
     261                        $variation_sale_price = '';
    262262
    263263                        // Check for prices exclude vat
     
    270270                            }
    271271
    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 );
    274274                            }
    275275                        }
     
    851851        require_once(__DIR__ . "/../api/class-extendago-web-api.php");
    852852        $Extendago = new Extendago_Web_Api();
    853         $Voucher = $Extendago->Request('/vouchers/'.$_POST['voucher'], 'GET');
     853        $Voucher = $Extendago->CurlRequest('/vouchers/'.$_POST['voucher'], 'GET');
    854854
    855855        if (isset($Voucher['id'])) {
     
    868868            require_once(__DIR__ . "/../api/class-extendago-web-api.php");
    869869            $Extendago = new Extendago_Web_Api();
    870             $Voucher = $Extendago->Request('/vouchers/'.$_GET['voucher'], 'GET');
     870            $Voucher = $Extendago->CurlRequest('/vouchers/'.$_GET['voucher'], 'GET');
    871871
    872872            if (isset($Voucher['id'])) {
  • extendago-wp-connection/trunk/readme.txt

    r2945883 r2956645  
    44Tags: extendago, extenda, woocommerce, arture, POS,
    55Requires at least: 6.0
    6 Tested up to: 6.2.2
    7 Stable tag: 1.4.1
     6Tested up to: 6.3.0
     7Stable tag: 1.4.2
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    3030
    3131== Changelog ==
     32
     33= 1.4.2 =
     34* New token based API method
     35* Bugfix for changed api call for changes
     36* Code performance
    3237
    3338= 1.4.1 =
Note: See TracChangeset for help on using the changeset viewer.