Plugin Directory

Changeset 2913178


Ignore:
Timestamp:
05/16/2023 06:19:51 PM (3 years ago)
Author:
skynetsolutions
Message:

1.1.20 - added support for new Beta version of API.

Location:
midwest-logistics/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • midwest-logistics/trunk/classes/class-ml-settings.php

    r2529939 r2913178  
    3232                'Midwest_Logistics_plugin_Page'
    3333            );
     34           
     35            add_settings_field(
     36                'Midwest_Logistics_api_version',
     37                __( 'API Version:', 'Midwest_Logistics' ),
     38                array($this,'Midwest_Logistics_api_version_render'),
     39                'Midwest_Logistics_plugin_Page',
     40                'Midwest_Logistics_Midwest_Logistics_plugin_Page_section'
     41            );
    3442            add_settings_field(
    3543                'Midwest_Logistics_text_field_0',
     
    125133            ?>
    126134            <input type='text' name='Midwest_Logistics_settings[Midwest_Logistics_API_Key_field_0]' value='<?php echo $value ?>'>
     135            <?php
     136        }
     137        public function Midwest_Logistics_api_version_render() {
     138            $options = get_option( 'Midwest_Logistics_settings' );
     139            ?>
     140            <select name='Midwest_Logistics_settings[Midwest_Logistics_api_version]'>
     141                <option value='1' <?php selected( $options['Midwest_Logistics_api_version'], 1 ); ?>>API Version 1.0.0 (Current)</option>
     142                <option value='2' <?php selected( $options['Midwest_Logistics_api_version'], 2 ); ?>>API Version 2.0.0 (Beta)</option>
     143            </select>
    127144            <?php
    128145        }
  • midwest-logistics/trunk/classes/class-ml-stock.php

    r2481617 r2913178  
    4949
    5050        $skusResults = $this->get_SKUs();
     51
    5152        $skus = false;
    5253        $skusArray = array();
     54        $skusJSONArray = array();
    5355        if(count($skusResults) == 0) {
    5456            //we must have updated them all so reset the field
     
    5860
    5961        if(count($skusResults) > 0) {
    60             foreach ($skusResults as $singleSKU) {
     62            foreach ($skusResults as $singleSKU) {               
    6163                $skus .= $singleSKU["midwestSKU"] . ",";
    62                
     64                $skusJSONArray[] = $singleSKU["midwestSKU"];
    6365                $skusArray[$singleSKU["midwestSKU"]] = array("id"=>$singleSKU["post_id"]);
    6466               
     
    8385                "request" => "productcheckbylist"
    8486            ];   
    85        
    86             $postString = json_encode ($jsonArray);
    8787
    88             $args = array(
    89                 'body' => $postString,
    90                 'timeout' => '60',
    91                 'redirection' => '5',
    92                 'httpversion' => '1.0',
    93                 'blocking' => true,
    94                 'headers' => array(),
    95                 'cookies' => array()
    96             );
    9788
    98             $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    99             if(is_wp_error($wp_remote_post_response)) {
    100                 $httpcode = "500";
    101                 $code = $wp_remote_post_response->get_error_code();
    102                 $response = $wp_remote_post_response->get_error_messages($code);
    103                 if(is_array($response)) {
    104                     $response = $response[0];
    105                 }
     89            $API = new ML_API();
     90            $APIVersion = $API->get_api_version();
     91            //switch the SKUs for a array
     92            if($APIVersion == "2") {
     93                $jsonArray["sku"] = $skusJSONArray;
     94            }
     95           
    10696
    107             } else {
    108                 $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    109                 $response = $wp_remote_post_response["body"];
    110             }
     97            $httpcode = "500";
     98            $postString = json_encode ($jsonArray);   
     99           
     100            $response = $API->send($postString);
     101            if($response != null) {
     102                $httpcode = $response["code"];
     103                $response = $response["response"];
     104            }           
    111105
    112106            if($httpcode == "200") {
     
    167161$ML_Stock = new ML_Stock();
    168162
     163//add_action( 'init', 'test_run_start' );
     164function test_run_start() {
     165    $ML_Stock = new ML_Stock();
     166    $ML_Stock->get_inventory();
     167   
     168}
  • midwest-logistics/trunk/classes/class-wc-ml-shipping-options.php

    r2481617 r2913178  
    5050            ];
    5151           
    52             $midwest_logistics_api_key = $settingOptions["Midwest_Logistics_API_Key_field_0"];
    53             $midwest_logistics_customer_key = $settingOptions["Midwest_Logistics_customer_id_text_field_1"];
    5452            $postString = json_encode ($jsonArray);
    55             $args = array(
    56                 'body' => $postString,
    57                 'timeout' => '60',
    58                 'redirection' => '5',
    59                 'httpversion' => '1.0',
    60                 'blocking' => true,
    61                 'headers' => array(),
    62                 'cookies' => array()
    63             );
    64 
    65 
    66 
    67             $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    68             if(is_wp_error($wp_remote_post_response)) {
    69                 $httpcode = "500";
    70                 $code = $wp_remote_post_response->get_error_code();
    71                 $response = $wp_remote_post_response->get_error_messages($code);
    72                 if(is_array($response)) {
    73                     $response = $response[0];
    74                 }
    75 
    76             } else {
    77                 $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    78                 $response = $wp_remote_post_response["body"];
     53           
     54            $httpcode = "500";
     55            $API = new ML_API();
     56            $response = $API->send($postString);
     57            if($response != null) {
     58                $httpcode = $response["code"];
     59                $response = $response["response"];
    7960            }
    80 
     61           
    8162            $responseText = "";
    8263           
  • midwest-logistics/trunk/inc/orderFunctions.php

    r2529939 r2913178  
    226226                ]
    227227            ];
     228
     229            $httpcode = "500";
     230            $postString = json_encode ($jsonArray); 
    228231           
    229             $postString = json_encode ($jsonArray);
    230             $args = array(
    231                 'body' => $postString,
    232                 'timeout' => '60',
    233                 'redirection' => '5',
    234                 'httpversion' => '1.0',
    235                 'blocking' => true,
    236                 'headers' => array(),
    237                 'cookies' => array()
    238             );
    239             $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    240             if(is_wp_error($wp_remote_post_response)) {
    241                 $httpcode = "500";
    242                 $code = $wp_remote_post_response->get_error_code();
    243                 $response = $wp_remote_post_response->get_error_messages($code);
    244                 if(is_array($response)) {
    245                     $response = $response[0];
    246                 }
    247 
    248             } else {
    249                 $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    250                 $response = $wp_remote_post_response["body"];
    251             }
    252             //$ch = curl_init( MIDWESTLOGISTICS_API_URL );
    253             //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    254             //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);                                                                 
    255             //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
    256             //$response =  curl_exec( $ch );
    257             //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);     
     232
     233
     234            $API = new ML_API();
     235            $response = $API->send($postString);
     236            if($response != null) {
     237                $httpcode = $response["code"];
     238                $response = $response["response"];
     239            }
     240
    258241            $responseText = "";
    259242            if($httpcode == "200") {
  • midwest-logistics/trunk/inc/productFunctions.php

    r2481617 r2913178  
    146146        "request" => "productcheck"
    147147    ];   
    148     $postString = json_encode ($jsonArray);
    149 
    150     $args = array(
    151         'method'      => 'POST',
    152         'body' => $postString,
    153         'timeout' => '60',
    154         'redirection' => '5',
    155         'httpversion' => '1.0',
    156         'blocking' => true,
    157         'headers' => array(),
    158         'sslverify' => true
    159     );
    160 
    161     $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    162     if(is_wp_error($wp_remote_post_response)) {
    163         $httpcode = "500";
    164         $code = $wp_remote_post_response->get_error_code();
    165         $response = $wp_remote_post_response->get_error_messages($code);
    166         if(is_array($response)) {
    167             $response = $response[0];
    168         }
    169        
    170     } else {
    171         $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    172         $response = $wp_remote_post_response["body"];
    173     }
    174    
    175    
    176     //$ch = curl_init( MIDWESTLOGISTICS_API_URL );
    177     //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    178     //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);                                                                 
    179     //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
    180 
    181     //$response =  curl_exec( $ch );
    182     //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     148
     149    $httpcode = "500";
     150    $postString = json_encode ($jsonArray);   
     151    $API = new ML_API();
     152    $response = $API->send($postString);
     153    if($response != null) {
     154        $httpcode = $response["code"];
     155        $response = $response["response"];
     156    }
     157
    183158    $responseText = "";
    184159
    185    
     160
    186161    if($httpcode == "200") {
    187162        if(json_decode($response) !== null) {
    188163            $jsonResponse = json_decode($response);
    189             $curl_result = $jsonResponse -> {"result"};           
     164
     165            $curl_result = $jsonResponse -> {"result"};         
     166
    190167            if($curl_result === "200") {
    191168                $responseText = $jsonResponse -> {"message"};
     
    194171                $responseText = $jsonResponse -> {"message"};
    195172                $responseArray =  array("result" => false, "message" => $jsonResponse -> {"message"});
     173               
    196174            }
    197175        } else {
     
    202180    }
    203181
    204     if($httpcode == "500") {
     182    if($httpcode == "500") {               
    205183        new WP_Error(  MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." );
    206184        $responseText = MIDWESTLOGISTICS_NAME . " API is down.";
     
    210188    //add the log
    211189    midwest_logistics_add_communication_log($postString,$response,get_the_ID(),"product",get_the_title(),$responseText);
    212     //var_dump($responseArray);
    213190    return $responseArray;
    214191}
     
    232209    if( !empty( $midwest_logistics_product_sku_text_field_value ) ) {
    233210        if($midwest_logistics_product_sku_text_field_value !== "") {
     211
    234212            $responseArray = midwest_logisitcs_verify_sku_number($midwest_logistics_product_sku_text_field_value);
    235213            if(is_array($responseArray)) {
    236214
    237215                if($responseArray["result"] === false) {
     216
    238217                    if($responseArray["message"] == "The API key is invalid") {
    239218                        ?>
  • midwest-logistics/trunk/inc/trackingFunctions.php

    r2529939 r2913178  
    7575            }
    7676        }
    77        
     77
    7878        if(count($orderArray) > 0) {
    7979            get_midwest_logistics_tracking_information($orderArray);
     
    9393        $midwest_logistics_customer_key = $settingOptions["Midwest_Logistics_customer_id_text_field_1"];
    9494    }
    95     $postString = '{"apiKey":"' . $apiKey . '","customerId": "' . $midwest_logistics_customer_key . '","request":"orderStatus","orders":[';
     95   
     96    $orders = [];
    9697    foreach ($orderArray as $orderArraySingle) {
    97         $orderString .= "{ \"orderId\": \"\",\"CRMID\" :  \"" . $orderArraySingle["CRMID"] . "\" },";
    98     }
    99     if($orderString !== "") {
    100         $orderString = substr($orderString,0,strlen($orderString)-1);
    101         $postString .= $orderString ."]}";
    102     }
    103     $args = array(
    104         'body' => $postString,
    105         'timeout' => '60',
    106         'redirection' => '5',
    107         'httpversion' => '1.0',
    108         'blocking' => true,
    109         'headers' => array(),
    110         'cookies' => array()
    111     );
    112 
    113     $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    114     if(is_wp_error($wp_remote_post_response)) {
    115         $httpcode = "500";
    116         $code = $wp_remote_post_response->get_error_code();
    117         $response = $wp_remote_post_response->get_error_messages($code);
    118         if(is_array($response)) {
    119             $response = $response[0];
    120         }
    121     } else {
    122         $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    123         $response = $wp_remote_post_response["body"];
    124     }
    125    
    126    
    127 
    128     //$ch = curl_init( MIDWESTLOGISTICS_API_URL );
    129     //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    130     //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);                                                                 
    131     //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
    132     //$response =  curl_exec( $ch );
    133     //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     98        $orders[] = array(
     99            "orderId" => "",
     100            "CRMID" => $orderArraySingle["CRMID"]           
     101        );
     102    }
     103    $jsonArray = [
     104        "apiKey" => $apiKey,
     105        "customerId" => $midwest_logistics_customer_key,
     106        "request" => "orderStatus",
     107        "orders" => $orders
     108    ];   
     109    print_r($jsonArray);
     110    $httpcode = "500";
     111    $postString = json_encode ($jsonArray);   
     112    $API = new ML_API();
     113    $response = $API->send($postString);
     114    if($response != null) {
     115        $httpcode = $response["code"];
     116        $response = $response["response"];
     117    }
    134118
    135119    $responseText = "";
  • midwest-logistics/trunk/midwest-wholesale.php

    r2893907 r2913178  
    44    * Plugin URI:  https://plugins.skynet-solutions.net/
    55    * Description: Midwest Wholesale Plugin allows you to automatically add Woocommerce orders into the Midwest Logistics order system.
    6     * Version:     1.1.19
     6    * Version:     1.1.20
    77    * WC requires at least: 3.0.0
    8     * WC tested up to: 7.5.1
     8    * WC tested up to: 6.1.1
    99    * Author:      Skynet Solutions Inc.
    1010    * Author URI:  http://www.skynet-solutions.net/
     
    8181
    8282    }
     83   
     84    //This is being faded out but left for right now. Setting is now in class-ML-API
    8385    if ( !defined( 'MIDWESTLOGISTICS_API_URL' ) ) {
    8486        //define( 'MIDWESTLOGISTICS_API_URL', 'http://midwestlogistics.windev.skynet-solutions.net/api/json/' );
     
    114116       
    115117        if($apiKey <> "") {
     118            require_once( MIDWESTLOGISTICS_PATH . 'classes/class-ml-api.php' );
    116119            require_once( MIDWESTLOGISTICS_PATH . 'classes/class-wc-ml-shipping-options.php' );
    117120            require_once( MIDWESTLOGISTICS_PATH . 'classes/class-ml-settings-orders.php' );
  • midwest-logistics/trunk/readme.txt

    r2893907 r2913178  
    33Tags: Midwest Logistics, Distribution, Shipping
    44Requires at least: 4.0
    5 Tested up to: 6.2.0
     5Tested up to: 5.9.0
    66Requires PHP: 5.4
    7 Stable tag: 1.1.19
     7Stable tag: 1.1.20
    88License: GPLv3
    99
Note: See TracChangeset for help on using the changeset viewer.