Plugin Directory

Changeset 2437678


Ignore:
Timestamp:
12/11/2020 08:28:15 PM (5 years ago)
Author:
skynetsolutions
Message:

1.1.15 - Updated stock settings to load WooCommerce product and update stock using built in WooComerce Product Class instead of manually updating wp_post_meta.

Location:
midwest-logistics/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • midwest-logistics/trunk/inc/setupFunctions.php

    r2313232 r2437678  
    44
    55
     6
    67/* Does User Belong Here */
    78
     
    910
    1011
     12
    1113if ( ! defined( 'MIDWESTLOGISTICS_VERSION' ) ) {
    1214
     
    1416
    1517
     18
    1619    header( 'Status: 403 Forbidden' );
    1720
     
    1922
    2023
     24
    2125    header( 'HTTP/1.1 403 Forbidden' );
    2226
     
    2428
    2529
     30
    2631    exit();
    2732
     
    2934
    3035
     36
    3137}
    3238
     
    3945
    4046
     47
     48
    4149function midwest_logistics_initialize() {
    4250
     
    5462
    5563
     64
     65
     66
    5667    //Do we need to update the db table?
    5768
     
    5970
    6071
     72
    6173    if( empty(get_option( 'midwest_logistics_db_version' )) || get_option( 'midwest_logistics_db_version' ) !== '1.1' ){
    6274
     
    6476
    6577
     78
    6679        //Run any updates for table or option settings here. It will be ran when the plugin updates.
    6780
     
    7992
    8093
     94
     95
     96
    8197    } 
    8298
     
    84100
    85101
     102
    86103    if (!in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 
    87104
     
    89106
    90107
     108
    91109        add_action( 'admin_notices', 'midwest_logistics_no_woo' );
    92110
     
    94112
    95113
     114
    96115        $MIDWESTLOGISTICS_activated = false;
    97116
     
    99118
    100119
     120
    101121    }
    102122
     
    104124
    105125
     126
    106127}
    107128
     
    114135
    115136
     137
     138
    116139function midwest_logistics_activate() {
    117140
     
    119142
    120143
     144
    121145    if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    122146
     
    124148
    125149
     150
    126151        midwest_logistics_create_table();
    127152
     
    129154
    130155
     156
    131157        midwest_logistics_create_order_table();
    132158
     
    139165
    140166
     167
     168
    141169        //set up the scheduler stock update
    142170
     
    144172
    145173
     174
    146175        if ( ! wp_next_scheduled( 'midwest_logistics_inventory_stock_update' ) ) {
    147176
     
    149178
    150179
     180
    151181            wp_schedule_event(time(), 'hourly', 'midwest_logistics_inventory_stock_update');
    152182
     
    154184
    155185
     186
    156187        }
    157188
     
    164195
    165196
     197
     198
    166199        //set up the scheduler for the tracking information
    167200
     
    169202
    170203
     204
    171205        if ( ! wp_next_scheduled( 'midwest_logistics_update_tracking_information' ) ) {
    172206
     
    174208
    175209
     210
    176211            wp_schedule_event(time(), 'hourly', 'midwest_logistics_update_tracking_information');
    177212
     
    179214
    180215
     216
    181217        }
    182218
     
    189225
    190226
     227
     228
    191229        midwest_logistics_revert_update_partial_orders();
    192230
     
    199237
    200238
     239
     240
    201241        update_option( 'midwest_logistics_db_version', '1.1' );
    202242
     
    204244
    205245
     246
    206247        $MIDWESTLOGISTICS_activated = true;
    207248
     
    209250
    210251
     252
    211253    }     
    212254
     
    214256
    215257
     258
    216259}
    217260
     
    224267
    225268
     269
     270
    226271function midwest_logistics_deactivate() {
    227272
     
    229274
    230275
     276
    231277    wp_clear_scheduled_hook('midwest_logistics_inventory_stock_update');
    232278
     
    234280
    235281
     282
    236283    wp_clear_scheduled_hook('midwest_logistics_update_tracking_information');
    237284
     
    239286
    240287
     288
    241289    midwest_logistics_update_partial_orders();
    242290
     
    244292
    245293
     294
    246295}
    247296
     
    254303
    255304
     305
     306
    256307function midwest_logistics_unistall() {
    257308
     
    259310
    260311
     312
    261313    midwest_logistics_delete_table();
    262314
     
    264316
    265317
     318
    266319    delete_option("midwest_logistics_settings");
    267320
     
    269322
    270323
     324
    271325    delete_option("midwest_logistics_db_version");
    272326
     
    274328
    275329
     330
    276331    //wp_clear_scheduled_hook('midwest_logistics_inventory_stock_update');
    277332
     
    279334
    280335
     336
    281337    //wp_clear_scheduled_hook('midwest_logistics_update_tracking_information');
    282338
     
    284340
    285341
     342
    286343}
    287344
     
    304361
    305362
     363
     364
     365
     366
    306367/*
    307368
     
    309370
    310371
     372
    311373* Registers the scripts needed for the Midwest Woocommerce.
    312374
     
    314376
    315377
     378
    316379*/
    317380
     
    319382
    320383
     384
    321385add_action( 'admin_enqueue_scripts', 'midwest_logistics_admin_script' );
    322386
     
    324388
    325389
     390
    326391function midwest_logistics_admin_script($hook) {
    327392
     
    329394
    330395
     396
    331397    wp_enqueue_script( 'midwest_logistics_admin_script', plugin_dir_url( __FILE__ )   . '../scripts/admin.js', false, '1.0.0' );
    332398
     
    334400
    335401
     402
    336403}
    337404
     
    344411
    345412
     413
     414
    346415function midwest_logistics_warn_phpversion() {
    347416
     
    349418
    350419
     420
    351421    ?>
    352422
     
    354424
    355425
     426
    356427    <div class="notice-error notice is-dismissible">
    357428
     
    359430
    360431
     432
    361433        <p><strong><?php _e( "PHP version 5.3.0 is required to run this plugin.",MIDWESTLOGISTICS_NAME); ?></strong></p>
    362434
     
    364436
    365437
     438
    366439    </div>
    367440
     
    369442
    370443
     444
    371445    <?php
    372446
     
    374448
    375449
     450
    376451}
    377452
     
    384459
    385460
     461
     462
    386463function midwest_logistics_no_woo() {
    387464
     
    389466
    390467
     468
    391469    if (! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    392470
     
    394472
    395473
     474
    396475        ?>
    397476
     
    399478
    400479
     480
    401481        <div class="notice-error notice is-dismissible">
    402482
     
    404484
    405485
     486
    406487            <p><strong><?php _e( "Woocommerce is required to run the " . MIDWESTLOGISTICS_NAME ." plugin. Please install or activate Woocommerce.",MIDWESTLOGISTICS_NAME); ?></strong></p>
    407488
     
    409490
    410491
     492
    411493        </div>
    412494
     
    414496
    415497
     498
    416499        <?php
    417500
     
    419502
    420503
     504
    421505    }
    422506
     
    424508
    425509
     510
    426511       
    427512
     
    429514
    430515
     516
    431517}
    432518
     
    439525
    440526
     527
     528
    441529function  midwest_logistics_no_api() {
    442530
     
    444532
    445533
     534
    446535    $settingsOptions = get_option( 'Midwest_Logistics_settings' );
    447536
     
    454543
    455544
     545
     546
    456547    $apiKey = "";
    457548
     
    459550
    460551
     552
    461553    $customerId = "";
    462554
     
    464556
    465557
     558
    466559    $settingOptions = get_option('Midwest_Logistics_settings','');
    467560
     
    469562
    470563
     564
    471565    if($settingOptions !== "") {
    472566
     
    474568
    475569
     570
    476571        $apiKey = $settingOptions["Midwest_Logistics_API_Key_field_0"];
    477572
     
    479574
    480575
     576
    481577        $customerId = $settingOptions["Midwest_Logistics_customer_id_text_field_1"];
    482578
     
    484580
    485581
     582
    486583    }
    487584
     
    489586
    490587
     588
    491589    if ($apiKey === "" || $customerId === "") {
    492590
     
    494592
    495593
     594
    496595        ?>
    497596
     
    499598
    500599
     600
    501601        <div class="notice-error notice is-dismissible">
    502602
     
    504604
    505605
     606
    506607            <p><strong><?php _e( "An API key and customer id is required before " . MIDWESTLOGISTICS_NAME . " plugin can be used.",MIDWESTLOGISTICS_NAME); ?></strong></p>
    507608
     
    509610
    510611
     612
    511613        </div>
    512614
     
    514616
    515617
     618
    516619        <?php
    517620
     
    519622
    520623
     624
    521625    }       
    522626
     
    524628
    525629
     630
    526631}
    527632
     
    534639
    535640
     641
     642
    536643//this must be set for the wp scheduler to work.
    537644
     
    539646
    540647
     648
    541649add_action( 'midwest_logistics_inventory_stock_update', 'midwest_logistics_inventory_stock_update' );
    542650
     
    544652
    545653
     654
    546655function midwest_logistics_inventory_stock_update() {
    547656
     
    554663
    555664
     665
     666
    556667    $settingsOptions = get_option( 'Midwest_Logistics_settings' );
    557668
     
    559670
    560671
     672
    561673    if($settingsOptions['Midwest_Logistics_select_field_1'] == "2" || $settingsOptions['Midwest_Logistics_select_field_1'] == "") {
    562674
     
    564676
    565677
     678
    566679        //if the dropdown is set to no don't worry about it.
    567680
     
    569682
    570683
     684
    571685        return;
    572686
     
    574688
    575689
     690
    576691    }
    577692
     
    584699
    585700
     701
     702
    586703    $apiKey = "";
    587704
     
    589706
    590707
     708
    591709    $settingOptions = get_option('Midwest_Logistics_settings','');
    592710
     
    594712
    595713
     714
    596715    if($settingOptions !== "") {
    597716
     
    599718
    600719
     720
    601721        $apiKey = $settingOptions["Midwest_Logistics_API_Key_field_0"];
    602722
     
    604724
    605725
     726
    606727    }
    607728
     
    614735
    615736
     737
     738
    616739       
    617740
     
    619742
    620743
     744
    621745    //simple Products
    622746
     
    624748
    625749
     750
    626751    $args = array(
    627752
     
    629754
    630755
     756
    631757        'posts_per_page'   => 10000,
    632758
     
    634760
    635761
     762
    636763        'offset'           => 0,
    637764
     
    639766
    640767
     768
    641769        'category'         => '',
    642770
     
    644772
    645773
     774
    646775        'category_name'    => '',
    647776
     
    649778
    650779
     780
    651781        'orderby'          => 'date',
    652782
     
    654784
    655785
     786
    656787        'order'            => 'DESC',
    657788
     
    659790
    660791
     792
    661793        'include'          => '',
    662794
     
    664796
    665797
     798
    666799        'exclude'          => '',
    667800
     
    669802
    670803
     804
    671805        'meta_key'         => '_midwest_logistics_product_select',
    672806
     
    674808
    675809
     810
    676811        'meta_value'       => 'Y',
    677812
     
    679814
    680815
     816
    681817        'post_type'        => 'product',
    682818
     
    684820
    685821
     822
    686823        'post_mime_type'   => '',
    687824
     
    689826
    690827
     828
    691829        'post_parent'      => '',
    692830
     
    694832
    695833
     834
    696835        'author'       => '',
    697836
     
    699838
    700839
     840
    701841        'author_name'      => '',
    702842
     
    704844
    705845
     846
    706847        'post_status'      => 'publish',
    707848
     
    709850
    710851
     852
    711853        'suppress_filters' => true
    712854
     
    714856
    715857
     858
    716859    );
    717860
     
    719862
    720863
     864
    721865    $posts_array = get_posts( $args );     
    722866
     
    724868
    725869
     870
    726871    foreach ( $posts_array as $post) : setup_postdata( $posts_array );
    727872
     
    729874
    730875
     876
    731877        //simple product
    732878
     
    734880
    735881
     882
    736883        if(get_post_meta($post->ID, '_manage_stock', true ) === "yes") {
    737884
     
    739886
    740887
     888
    741889            $SKUNumber = get_post_meta($post->ID, '_midwest_logistics_product_sku_text_field', true );
    742890
     
    744892
    745893
     894
    746895            if($SKUNumber !== "") {
    747896
     
    749898
    750899
     900
    751901                $jsonArray = [
    752902
     
    754904
    755905
     906
    756907                    "apiKey" => $apiKey,
    757908
     
    759910
    760911
     912
    761913                    "sku" => $SKUNumber,
    762914
     
    764916
    765917
     918
    766919                    "request" => "productcheck"
    767920
     
    769922
    770923
     924
    771925                ];   
    772926
     
    779933
    780934
     935
     936
    781937                $postString = json_encode ($jsonArray);
    782938
     
    789945
    790946
     947
     948
    791949                $args = array(
    792950
     
    794952
    795953
     954
    796955                    'body' => $postString,
    797956
     
    799958
    800959
     960
    801961                    'timeout' => '60',
    802962
     
    804964
    805965
     966
    806967                    'redirection' => '5',
    807968
     
    809970
    810971
     972
    811973                    'httpversion' => '1.0',
    812974
     
    814976
    815977
     978
    816979                    'blocking' => true,
    817980
     
    819982
    820983
     984
    821985                    'headers' => array(),
    822986
     
    824988
    825989
     990
    826991                    'cookies' => array()
    827992
     
    829994
    830995
     996
    831997                );
    832998
     
    8341000
    8351001
     1002
    8361003   
    8371004
     
    8391006
    8401007
     1008
    8411009                $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    8421010
     
    8441012
    8451013
     1014
    8461015                if(is_wp_error($wp_remote_post_response)) {
    8471016
     
    8491018
    8501019
     1020
    8511021                    $httpcode = "500";
    8521022
     
    8541024
    8551025
     1026
    8561027                    $code = $wp_remote_post_response->get_error_code();
    8571028
     
    8591030
    8601031
     1032
    8611033                    $response = $wp_remote_post_response->get_error_messages($code);
    8621034
     
    8641036
    8651037
     1038
    8661039                    if(is_array($response)) {
    8671040
     
    8691042
    8701043
     1044
    8711045                        $response = $response[0];
    8721046
     
    8741048
    8751049
     1050
    8761051                    }
    8771052
     
    8791054
    8801055
     1056
    8811057       
    8821058
     
    8841060
    8851061
     1062
    8861063                } else {
    8871064
     
    8891066
    8901067
     1068
    8911069                    $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    8921070
     
    8941072
    8951073
     1074
    8961075                    $response = $wp_remote_post_response["body"];
    8971076
     
    8991078
    9001079
     1080
    9011081                }
    9021082
     
    9041084
    9051085
     1086
    9061087               
    9071088
     
    9141095
    9151096
     1097
     1098
    9161099                //$ch = curl_init( MIDWESTLOGISTICS_API_URL );
    9171100
     
    9191102
    9201103
     1104
    9211105                //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    9221106
     
    9241108
    9251109
     1110
    9261111                //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);                                                                 
    9271112
     
    9291114
    9301115
     1116
    9311117                //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
    9321118
     
    9391125
    9401126
     1127
     1128
    9411129                //$response =  curl_exec( $ch );
    9421130
     
    9441132
    9451133
     1134
    9461135                //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    9471136
     
    9491138
    9501139
     1140
    9511141                if($httpcode == "200") {
    9521142
     
    9541144
    9551145
     1146
    9561147                    $responseArray = midwest_logistics_inventory_json_parse($response);
    9571148
     
    9591150
    9601151
     1152
    9611153                    if(is_array($responseArray)) {
    9621154
     
    9641156
    9651157
     1158
    9661159                        if($responseArray["result"] = "200") {
    9671160
     
    9691162
    9701163
     1164
    9711165                            $stockAmount = $responseArray["stockAmount"];
    9721166
     
    9741168
    9751169
     1170
    9761171                            $inStock = $responseArray["instock"];
    9771172
     
    9791174
    9801175
     1176
    9811177                            $responseText = $inStock;
    9821178
     
    9841180
    9851181
    986                             if($inStock = "Y") {
    987 
    988 
    989 
    990 
    991                                 if(is_numeric($stockAmount) ) {
    992 
    993 
    994 
    995 
    996                                     //update_post_meta( $post->ID, '_stock_status', esc_attr( "instock") );
    997 
    998 
    999 
    1000 
    1001                                     update_post_meta( $post->ID, '_stock', esc_attr( $stockAmount) );
    1002 
    1003 
    1004 
    1005 
    1006                                 }
    1007 
    1008 
    1009 
    1010 
    1011                             } else {
    1012 
    1013 
    1014 
    1015 
    1016                                 //update_post_meta( $post->ID, '_stock_status', esc_attr( "outofstock") );
    1017 
    1018 
    1019 
    1020 
    1021                                 update_post_meta( $post->ID, '_stock', esc_attr( $stockAmount) );
    1022 
    1023 
    1024 
    1025 
     1182                            if(is_numeric($stockAmount) ) {
     1183                                $product = new WC_Product( $post->ID );
     1184                                $product->set_stock_quantity($stockAmount);
     1185                                $product->save();
    10261186                            }
     1187                           
     1188
     1189                        }
     1190
     1191
     1192
     1193
     1194
     1195                    }
     1196
     1197
     1198
     1199
     1200
     1201                }
     1202
     1203
     1204
     1205
     1206
     1207
     1208
     1209
     1210
     1211
     1212
     1213                if($httpcode == "500") {
     1214
     1215
     1216
     1217
     1218
     1219                    new WP_Error(  MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." );
     1220
     1221
     1222
     1223
     1224
     1225                    $responseArray =  array("result" => false, "message" => MIDWESTLOGISTICS_NAME . " API is down.");
     1226
     1227
     1228
     1229
     1230
     1231                }
     1232
     1233
     1234
     1235
     1236
     1237
     1238
     1239
     1240
     1241
     1242
     1243                //add the log
     1244
     1245
     1246
     1247
     1248
     1249                midwest_logistics_add_communication_log($postString,$response,$post->ID,"product",get_the_title(),$responseText);             
     1250
     1251
     1252
     1253
     1254
     1255            }
     1256
     1257
     1258
     1259
     1260
     1261        }       
     1262
     1263
     1264
     1265
     1266
     1267    endforeach;
     1268
     1269
     1270
     1271
     1272
     1273
     1274
     1275
     1276
     1277
     1278
     1279    //variable products
     1280
     1281
     1282
     1283
     1284
     1285    $args = array(
     1286
     1287
     1288
     1289
     1290
     1291        'posts_per_page'   => 10000,
     1292
     1293
     1294
     1295
     1296
     1297        'offset'           => 0,
     1298
     1299
     1300
     1301
     1302
     1303        'category'         => '',
     1304
     1305
     1306
     1307
     1308
     1309        'category_name'    => '',
     1310
     1311
     1312
     1313
     1314
     1315        'orderby'          => 'date',
     1316
     1317
     1318
     1319
     1320
     1321        'order'            => 'DESC',
     1322
     1323
     1324
     1325
     1326
     1327        'include'          => '',
     1328
     1329
     1330
     1331
     1332
     1333        'exclude'          => '',
     1334
     1335
     1336
     1337
     1338
     1339        'meta_key'         => '_midwest_logistics_product_select',
     1340
     1341
     1342
     1343
     1344
     1345        'meta_value'       => 'Y',
     1346
     1347
     1348
     1349
     1350
     1351        'post_type'        => 'product_variation',
     1352
     1353
     1354
     1355
     1356
     1357        'post_mime_type'   => '',
     1358
     1359
     1360
     1361
     1362
     1363        'post_parent'      => '',
     1364
     1365
     1366
     1367
     1368
     1369        'author'       => '',
     1370
     1371
     1372
     1373
     1374
     1375        'author_name'      => '',
     1376
     1377
     1378
     1379
     1380
     1381        'post_status'      => 'publish',
     1382
     1383
     1384
     1385
     1386
     1387        'suppress_filters' => true
     1388
     1389
     1390
     1391
     1392
     1393    );
     1394
     1395
     1396
     1397
     1398
     1399   
     1400
     1401
     1402
     1403
     1404
     1405    $posts_array = get_posts( $args );     
     1406
     1407
     1408
     1409
     1410
     1411
     1412
     1413
     1414
     1415
     1416
     1417    foreach ( $posts_array as $post) : setup_postdata( $posts_array );
     1418
     1419
     1420
     1421
     1422
     1423        if(get_post_meta($post->ID, '_manage_stock', true ) === "yes") {
     1424
     1425
     1426
     1427
     1428
     1429            $SKUNumber = get_post_meta($post->ID, '_midwest_logistics_product_sku_text_field', true );
     1430
     1431
     1432
     1433
     1434
     1435            if($SKUNumber !== "") {
     1436
     1437
     1438
     1439
     1440
     1441                $jsonArray = [
     1442
     1443
     1444
     1445
     1446
     1447                    "apiKey" => $apiKey,
     1448
     1449
     1450
     1451
     1452
     1453                    "sku" => $SKUNumber,
     1454
     1455
     1456
     1457
     1458
     1459                    "request" => "productcheck"
     1460
     1461
     1462
     1463
     1464
     1465                ];   
     1466
     1467
     1468
     1469
     1470
     1471
     1472
     1473
     1474
     1475
     1476
     1477                $postString = json_encode ($jsonArray);
     1478
     1479
     1480
     1481
     1482
     1483
     1484
     1485
     1486
     1487
     1488
     1489                $args = array(
     1490
     1491
     1492
     1493
     1494
     1495                    'body' => $postString,
     1496
     1497
     1498
     1499
     1500
     1501                    'timeout' => '60',
     1502
     1503
     1504
     1505
     1506
     1507                    'redirection' => '5',
     1508
     1509
     1510
     1511
     1512
     1513                    'httpversion' => '1.0',
     1514
     1515
     1516
     1517
     1518
     1519                    'blocking' => true,
     1520
     1521
     1522
     1523
     1524
     1525                    'headers' => array(),
     1526
     1527
     1528
     1529
     1530
     1531                    'cookies' => array()
     1532
     1533
     1534
     1535
     1536
     1537                );
     1538
     1539
     1540
     1541
     1542
     1543   
     1544
     1545
     1546
     1547
     1548
     1549                $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
     1550
     1551
     1552
     1553
     1554
     1555                if(is_wp_error($wp_remote_post_response)) {
     1556
     1557
     1558
     1559
     1560
     1561                    $httpcode = "500";
     1562
     1563
     1564
     1565
     1566
     1567                    $code = $wp_remote_post_response->get_error_code();
     1568
     1569
     1570
     1571
     1572
     1573                    $response = $wp_remote_post_response->get_error_messages($code);
     1574
     1575
     1576
     1577
     1578
     1579                    if(is_array($response)) {
     1580
     1581
     1582
     1583
     1584
     1585                        $response = $response[0];
     1586
     1587
     1588
     1589
     1590
     1591                    }
     1592
     1593
     1594
     1595
     1596
     1597       
     1598
     1599
     1600
     1601
     1602
     1603                } else {
     1604
     1605
     1606
     1607
     1608
     1609                    $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
     1610
     1611
     1612
     1613
     1614
     1615                    $response = $wp_remote_post_response["body"];
     1616
     1617
     1618
     1619
     1620
     1621                }
     1622
     1623
     1624
     1625
     1626
     1627               
     1628
     1629
     1630
     1631
     1632
     1633
     1634
     1635
     1636
     1637
     1638
     1639                //$ch = curl_init( MIDWESTLOGISTICS_API_URL );
     1640
     1641
     1642
     1643
     1644
     1645                //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
     1646
     1647
     1648
     1649
     1650
     1651                //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);                                                                 
     1652
     1653
     1654
     1655
     1656
     1657                //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
     1658
     1659
     1660
     1661
     1662
     1663
     1664
     1665
     1666
     1667
     1668
     1669                //$response =  curl_exec( $ch );
     1670
     1671
     1672
     1673
     1674
     1675                //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     1676
     1677
     1678
     1679
     1680
     1681                if($httpcode == "200") {
     1682
     1683
     1684
     1685
     1686
     1687                    $responseArray = midwest_logistics_inventory_json_parse($response);
     1688
     1689
     1690
     1691
     1692
     1693                    if(is_array($responseArray)) {
     1694
     1695
     1696
     1697
     1698
     1699                        if($responseArray["result"] = "200") {
     1700
     1701
     1702
     1703
     1704
     1705                            $stockAmount = $responseArray["stockAmount"];
     1706
     1707
     1708
     1709
     1710
     1711                            $inStock = $responseArray["instock"];
     1712
     1713
     1714
     1715
     1716
     1717                            $responseText = $inStock;
     1718
     1719
     1720
     1721                            if(is_numeric($stockAmount) ) {
     1722                                $product =  wc_get_product($post->ID);
     1723                                $product->set_stock_quantity($stockAmount);
     1724                                $product->save();
     1725                            }
     1726
    10271727
    10281728
     
    10341734
    10351735
     1736
    10361737                        }
    10371738
     
    10391740
    10401741
     1742
    10411743                    }
    10421744
     
    10441746
    10451747
     1748
    10461749                }
    10471750
     
    10541757
    10551758
     1759
     1760
    10561761                if($httpcode == "500") {
    10571762
     
    10591764
    10601765
     1766
    10611767                    new WP_Error(  MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." );
    10621768
     
    10641770
    10651771
     1772
    10661773                    $responseArray =  array("result" => false, "message" => MIDWESTLOGISTICS_NAME . " API is down.");
    10671774
     
    10691776
    10701777
     1778
    10711779                }
    10721780
     
    10791787
    10801788
     1789
     1790
    10811791                //add the log
    10821792
     
    10841794
    10851795
     1796
    10861797                midwest_logistics_add_communication_log($postString,$response,$post->ID,"product",get_the_title(),$responseText);             
    10871798
     
    10891800
    10901801
     1802
    10911803            }
    10921804
     
    10941806
    10951807
     1808
    10961809        }       
    10971810
     
    10991812
    11001813
    1101     endforeach;
    1102 
    1103 
    1104 
    1105 
    1106 
    1107 
    1108 
    1109 
    1110 
    1111     //variable products
    1112 
    1113 
    1114 
    1115 
    1116     $args = array(
    1117 
    1118 
    1119 
    1120 
    1121         'posts_per_page'   => 10000,
    1122 
    1123 
    1124 
    1125 
    1126         'offset'           => 0,
    1127 
    1128 
    1129 
    1130 
    1131         'category'         => '',
    1132 
    1133 
    1134 
    1135 
    1136         'category_name'    => '',
    1137 
    1138 
    1139 
    1140 
    1141         'orderby'          => 'date',
    1142 
    1143 
    1144 
    1145 
    1146         'order'            => 'DESC',
    1147 
    1148 
    1149 
    1150 
    1151         'include'          => '',
    1152 
    1153 
    1154 
    1155 
    1156         'exclude'          => '',
    1157 
    1158 
    1159 
    1160 
    1161         'meta_key'         => '_midwest_logistics_product_select',
    1162 
    1163 
    1164 
    1165 
    1166         'meta_value'       => 'Y',
    1167 
    1168 
    1169 
    1170 
    1171         'post_type'        => 'product_variation',
    1172 
    1173 
    1174 
    1175 
    1176         'post_mime_type'   => '',
    1177 
    1178 
    1179 
    1180 
    1181         'post_parent'      => '',
    1182 
    1183 
    1184 
    1185 
    1186         'author'       => '',
    1187 
    1188 
    1189 
    1190 
    1191         'author_name'      => '',
    1192 
    1193 
    1194 
    1195 
    1196         'post_status'      => 'publish',
    1197 
    1198 
    1199 
    1200 
    1201         'suppress_filters' => true
    1202 
    1203 
    1204 
    1205 
    1206     );
    1207 
    1208 
    1209 
    1210 
    1211    
    1212 
    1213 
    1214 
    1215 
    1216     $posts_array = get_posts( $args );     
    1217 
    1218 
    1219 
    1220 
    1221 
    1222 
    1223 
    1224 
    1225 
    1226     foreach ( $posts_array as $post) : setup_postdata( $posts_array );
    1227 
    1228 
    1229 
    1230 
    1231         if(get_post_meta($post->ID, '_manage_stock', true ) === "yes") {
    1232 
    1233 
    1234 
    1235 
    1236             $SKUNumber = get_post_meta($post->ID, '_midwest_logistics_product_sku_text_field', true );
    1237 
    1238 
    1239 
    1240 
    1241             if($SKUNumber !== "") {
    1242 
    1243 
    1244 
    1245 
    1246                 $jsonArray = [
    1247 
    1248 
    1249 
    1250 
    1251                     "apiKey" => $apiKey,
    1252 
    1253 
    1254 
    1255 
    1256                     "sku" => $SKUNumber,
    1257 
    1258 
    1259 
    1260 
    1261                     "request" => "productcheck"
    1262 
    1263 
    1264 
    1265 
    1266                 ];   
    1267 
    1268 
    1269 
    1270 
    1271 
    1272 
    1273 
    1274 
    1275 
    1276                 $postString = json_encode ($jsonArray);
    1277 
    1278 
    1279 
    1280 
    1281 
    1282 
    1283 
    1284 
    1285 
    1286                 $args = array(
    1287 
    1288 
    1289 
    1290 
    1291                     'body' => $postString,
    1292 
    1293 
    1294 
    1295 
    1296                     'timeout' => '60',
    1297 
    1298 
    1299 
    1300 
    1301                     'redirection' => '5',
    1302 
    1303 
    1304 
    1305 
    1306                     'httpversion' => '1.0',
    1307 
    1308 
    1309 
    1310 
    1311                     'blocking' => true,
    1312 
    1313 
    1314 
    1315 
    1316                     'headers' => array(),
    1317 
    1318 
    1319 
    1320 
    1321                     'cookies' => array()
    1322 
    1323 
    1324 
    1325 
    1326                 );
    1327 
    1328 
    1329 
    1330 
    1331    
    1332 
    1333 
    1334 
    1335 
    1336                 $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args);
    1337 
    1338 
    1339 
    1340 
    1341                 if(is_wp_error($wp_remote_post_response)) {
    1342 
    1343 
    1344 
    1345 
    1346                     $httpcode = "500";
    1347 
    1348 
    1349 
    1350 
    1351                     $code = $wp_remote_post_response->get_error_code();
    1352 
    1353 
    1354 
    1355 
    1356                     $response = $wp_remote_post_response->get_error_messages($code);
    1357 
    1358 
    1359 
    1360 
    1361                     if(is_array($response)) {
    1362 
    1363 
    1364 
    1365 
    1366                         $response = $response[0];
    1367 
    1368 
    1369 
    1370 
    1371                     }
     1814
     1815    endforeach;
     1816
     1817
     1818
     1819
     1820
     1821}
     1822
     1823
     1824
     1825
     1826
     1827//add_action( 'wp_loaded', 'midwest_logistics_inventory_stock_update' );
     1828
     1829
     1830
     1831
     1832
     1833
     1834
     1835
     1836
     1837
     1838
     1839
     1840
     1841
     1842function midwest_logistics_inventory_json_parse($json) {
     1843
     1844
     1845
     1846
     1847
     1848    if(json_decode($json) !== null) {
     1849
     1850
     1851
     1852
     1853
     1854        $jsonResponse = json_decode($json);
     1855
     1856
     1857
     1858
     1859
     1860        $curl_result = $jsonResponse -> {"result"};           
     1861
     1862
     1863
     1864
     1865
     1866        if($curl_result === "200") {
     1867
     1868
     1869
     1870
     1871
     1872            $responseArray = array("result" => true, "message" => $jsonResponse -> {"message"}, "stockAmount" => $jsonResponse -> {"stock"}, "instock" => $jsonResponse -> {"instock"});
     1873
     1874
     1875
     1876
     1877
     1878        } else {
     1879
     1880
     1881
     1882
     1883
     1884            $responseArray =  array("result" => false, "message" => $jsonResponse -> {"message"}, "stockAmount" => "0", "instock" => "N");
     1885
     1886
     1887
     1888
     1889
     1890        }
     1891
     1892
     1893
     1894
     1895
     1896    } else {
     1897
     1898
     1899
     1900
     1901
     1902        new WP_Error(  MIDWESTLOGISTICS_NAME . ' API',"Invalid Call" );
     1903
     1904
     1905
     1906
     1907
     1908        $responseArray =   array("result" => false, "message" => "Invalid Call", "stockAmount" => "0", "instock" => "N");
     1909
     1910
     1911
     1912
     1913
     1914    }
     1915
     1916
     1917
     1918
     1919
     1920
     1921
     1922
     1923
     1924
     1925
     1926    return $responseArray;
     1927
     1928
     1929
     1930
     1931
     1932
     1933
     1934
     1935
     1936
     1937
     1938}
     1939
     1940
     1941
     1942
     1943
     1944
     1945
     1946
     1947
     1948
     1949
     1950
     1951
     1952
     1953
     1954
     1955
     1956function midwest_logistics_create_table() {
     1957
     1958
     1959
     1960
     1961
     1962    global $wpdb;
     1963
     1964
     1965
     1966
     1967
     1968    $table_name = $wpdb->prefix . MIDWESTLOGISTICS_TABLE_NAME;
     1969
     1970
     1971
     1972
     1973
     1974    $charset_collate = $wpdb->get_charset_collate();
     1975
     1976
     1977
     1978
     1979
     1980
     1981
     1982
     1983
     1984
     1985
     1986    $sql = "CREATE TABLE $table_name (
     1987
     1988
     1989
     1990
     1991
     1992        id bigint(9) NOT NULL AUTO_INCREMENT,
     1993
     1994
     1995
     1996
     1997
     1998        dateadded datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
     1999
     2000
     2001
     2002
     2003
     2004        JSONsent text NOT NULL,
     2005
     2006
     2007
     2008
     2009
     2010        JSONresponse text NOT NULL,
     2011
     2012
     2013
     2014
     2015
     2016        post_id bigint NOT NULL,
     2017
     2018
     2019
     2020
     2021
     2022        post_meta_key varchar(255),
     2023
     2024
     2025
     2026
     2027
     2028        post_meta_value longtext,
     2029
     2030
     2031
     2032
     2033
     2034        response varchar(255),
     2035
     2036
     2037
     2038
     2039
     2040        PRIMARY KEY  (id)
     2041
     2042
     2043
     2044
     2045
     2046    ) $charset_collate;";
     2047
    13722048
    13732049
     
    13792055
    13802056
    1381                 } else {
    1382 
    1383 
    1384 
    1385 
    1386                     $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response );
    1387 
    1388 
    1389 
    1390 
    1391                     $response = $wp_remote_post_response["body"];
    1392 
    1393 
    1394 
    1395 
    1396                 }
    1397 
    1398 
    1399 
    1400 
    1401                
    1402 
    1403 
    1404 
    1405 
    1406 
    1407 
    1408 
    1409 
    1410 
    1411                 //$ch = curl_init( MIDWESTLOGISTICS_API_URL );
    1412 
    1413 
    1414 
    1415 
    1416                 //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    1417 
    1418 
    1419 
    1420 
    1421                 //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);                                                                 
    1422 
    1423 
    1424 
    1425 
    1426                 //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
    1427 
    1428 
    1429 
    1430 
    1431 
    1432 
    1433 
    1434 
    1435 
    1436                 //$response =  curl_exec( $ch );
    1437 
    1438 
    1439 
    1440 
    1441                 //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    1442 
    1443 
    1444 
    1445 
    1446                 if($httpcode == "200") {
    1447 
    1448 
    1449 
    1450 
    1451                     $responseArray = midwest_logistics_inventory_json_parse($response);
    1452 
    1453 
    1454 
    1455 
    1456                     if(is_array($responseArray)) {
    1457 
    1458 
    1459 
    1460 
    1461                         if($responseArray["result"] = "200") {
    1462 
    1463 
    1464 
    1465 
    1466                             $stockAmount = $responseArray["stockAmount"];
    1467 
    1468 
    1469 
    1470 
    1471                             $inStock = $responseArray["instock"];
    1472 
    1473 
    1474 
    1475 
    1476                             $responseText = $inStock;
    1477 
    1478 
    1479 
    1480 
    1481                             if($inStock = "Y") {
    1482 
    1483 
    1484 
    1485 
    1486                                 if(is_numeric($stockAmount) ) {
    1487 
    1488 
    1489 
    1490 
    1491                                     //update_post_meta( $post->ID, '_stock_status', esc_attr( "instock") );
    1492 
    1493 
    1494 
    1495 
    1496                                     update_post_meta( $post->ID, '_stock', esc_attr( $stockAmount) );
    1497 
    1498 
    1499 
    1500 
    1501                                 }
    1502 
    1503 
    1504 
    1505 
    1506                             } else {
    1507 
    1508 
    1509 
    1510 
    1511                                 //update_post_meta( $post->ID, '_stock_status', esc_attr( "outofstock") );
    1512 
    1513 
    1514 
    1515 
    1516                                 update_post_meta( $post->ID, '_stock', esc_attr( $stockAmount) );
    1517 
    1518 
    1519 
    1520 
    1521                             }
    1522 
    1523 
    1524 
    1525 
    1526                            
    1527 
    1528 
    1529 
    1530 
    1531                         }
    1532 
    1533 
    1534 
    1535 
    1536                     }
    1537 
    1538 
    1539 
    1540 
    1541                 }
    1542 
    1543 
    1544 
    1545 
    1546 
    1547 
    1548 
    1549 
    1550 
    1551                 if($httpcode == "500") {
    1552 
    1553 
    1554 
    1555 
    1556                     new WP_Error(  MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." );
    1557 
    1558 
    1559 
    1560 
    1561                     $responseArray =  array("result" => false, "message" => MIDWESTLOGISTICS_NAME . " API is down.");
    1562 
    1563 
    1564 
    1565 
    1566                 }
    1567 
    1568 
    1569 
    1570 
    1571 
    1572 
    1573 
    1574 
    1575 
    1576                 //add the log
    1577 
    1578 
    1579 
    1580 
    1581                 midwest_logistics_add_communication_log($postString,$response,$post->ID,"product",get_the_title(),$responseText);             
    1582 
    1583 
    1584 
    1585 
    1586             }
    1587 
    1588 
    1589 
    1590 
    1591         }       
    1592 
    1593 
    1594 
    1595 
    1596     endforeach;
     2057
     2058    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     2059
     2060
     2061
     2062
     2063
     2064    dbDelta( $sql );
     2065
    15972066
    15982067
     
    16052074
    16062075
    1607 
    1608 
    1609 
    1610 
    1611 
    1612 
    1613 
    1614 
    1615 
    1616 function midwest_logistics_inventory_json_parse($json) {
    1617 
    1618 
    1619 
    1620 
    1621     if(json_decode($json) !== null) {
    1622 
    1623 
    1624 
    1625 
    1626         $jsonResponse = json_decode($json);
    1627 
    1628 
    1629 
    1630 
    1631         $curl_result = $jsonResponse -> {"result"};           
    1632 
    1633 
    1634 
    1635 
    1636         if($curl_result === "200") {
    1637 
    1638 
    1639 
    1640 
    1641             $responseArray = array("result" => true, "message" => $jsonResponse -> {"message"}, "stockAmount" => $jsonResponse -> {"stock"}, "instock" => $jsonResponse -> {"instock"});
    1642 
    1643 
    1644 
    1645 
    1646         } else {
    1647 
    1648 
    1649 
    1650 
    1651             $responseArray =  array("result" => false, "message" => $jsonResponse -> {"message"}, "stockAmount" => "0", "instock" => "N");
    1652 
    1653 
    1654 
    1655 
    1656         }
    1657 
    1658 
    1659 
    1660 
    1661     } else {
    1662 
    1663 
    1664 
    1665 
    1666         new WP_Error(  MIDWESTLOGISTICS_NAME . ' API',"Invalid Call" );
    1667 
    1668 
    1669 
    1670 
    1671         $responseArray =   array("result" => false, "message" => "Invalid Call", "stockAmount" => "0", "instock" => "N");
    1672 
    1673 
    1674 
    1675 
    1676     }
    1677 
    1678 
    1679 
    1680 
    1681 
    1682 
    1683 
    1684 
    1685 
    1686     return $responseArray;
    1687 
    1688 
    1689 
    1690 
     2076function midwest_logistics_create_order_table() {
     2077
     2078
     2079
     2080
     2081
     2082    global $wpdb;
     2083
     2084
     2085
     2086
     2087
     2088    $table_name = $wpdb->prefix . "midwest_logistics_orders";
     2089
     2090
     2091
     2092
     2093
     2094    $charset_collate = $wpdb->get_charset_collate();
     2095
     2096
     2097
     2098
     2099
     2100
     2101
     2102
     2103
     2104
     2105
     2106    $sql = "CREATE TABLE $table_name (
     2107
     2108
     2109
     2110
     2111
     2112        id bigint(9) NOT NULL AUTO_INCREMENT,
     2113
     2114
     2115
     2116
     2117
     2118        post_id bigint,
     2119
     2120
     2121
     2122
     2123
     2124        initial_status varchar(255),
     2125
     2126
     2127
     2128
     2129
     2130        changed_to_status varchar(255),
     2131
     2132
     2133
     2134
     2135
     2136        PRIMARY KEY  (id)
     2137
     2138
     2139
     2140
     2141
     2142    ) $charset_collate;";
     2143
     2144
     2145
     2146
     2147
     2148       
     2149
     2150
     2151
     2152
     2153
     2154    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     2155
     2156
     2157
     2158
     2159
     2160    dbDelta( $sql );
    16912161
    16922162
     
    17062176
    17072177
    1708 
    1709 
    1710 
    1711 function midwest_logistics_create_table() {
     2178function midwest_logistics_delete_table() {
     2179
    17122180
    17132181
     
    17192187
    17202188
    1721     $table_name = $wpdb->prefix . MIDWESTLOGISTICS_TABLE_NAME;
    1722 
    1723 
    1724 
    1725 
    1726     $charset_collate = $wpdb->get_charset_collate();
    1727 
    1728 
    1729 
    1730 
    1731 
    1732 
    1733 
    1734 
    1735 
    1736     $sql = "CREATE TABLE $table_name (
    1737 
    1738 
    1739 
    1740 
    1741         id bigint(9) NOT NULL AUTO_INCREMENT,
    1742 
    1743 
    1744 
    1745 
    1746         dateadded datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    1747 
    1748 
    1749 
    1750 
    1751         JSONsent text NOT NULL,
    1752 
    1753 
    1754 
    1755 
    1756         JSONresponse text NOT NULL,
    1757 
    1758 
    1759 
    1760 
    1761         post_id bigint NOT NULL,
    1762 
    1763 
    1764 
    1765 
    1766         post_meta_key varchar(255),
    1767 
    1768 
    1769 
    1770 
    1771         post_meta_value longtext,
    1772 
    1773 
    1774 
    1775 
    1776         response varchar(255),
    1777 
    1778 
    1779 
    1780 
    1781         PRIMARY KEY  (id)
    1782 
    1783 
    1784 
    1785 
    1786     ) $charset_collate;";
    1787 
    1788 
    1789 
    1790 
    1791        
    1792 
    1793 
    1794 
    1795 
    1796     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    1797 
    1798 
    1799 
    1800 
    1801     dbDelta( $sql );
     2189
     2190    $table_name = $wpdb->prefix . MIDWESTLOGISTICS_TABLE_NAME;
     2191
     2192
     2193
     2194
     2195
     2196    $sql = "DROP TABLE IF EXISTS $table_name";
     2197
     2198
     2199
     2200
     2201
     2202    $wpdb->query($sql);
     2203
     2204
     2205
     2206
     2207
     2208
     2209
     2210
     2211
     2212
     2213
     2214    $table_name = $wpdb->prefix . "midwest_logistics_orders";
     2215
     2216
     2217
     2218
     2219
     2220    $sql = "DROP TABLE IF EXISTS $table_name";
     2221
     2222
     2223
     2224
     2225
     2226    $wpdb->query($sql);
     2227
    18022228
    18032229
     
    18092235
    18102236
    1811 function midwest_logistics_create_order_table() {
     2237
     2238
     2239
     2240
     2241
     2242
     2243
     2244function midwest_logistics_update_partial_orders() {
     2245
    18122246
    18132247
     
    18192253
    18202254
    1821     $table_name = $wpdb->prefix . "midwest_logistics_orders";
    1822 
    1823 
    1824 
    1825 
    1826     $charset_collate = $wpdb->get_charset_collate();
    1827 
    1828 
    1829 
    1830 
    1831 
    1832 
    1833 
    1834 
    1835 
    1836     $sql = "CREATE TABLE $table_name (
    1837 
    1838 
    1839 
    1840 
    1841         id bigint(9) NOT NULL AUTO_INCREMENT,
    1842 
    1843 
    1844 
    1845 
    1846         post_id bigint,
    1847 
    1848 
    1849 
    1850 
    1851         initial_status varchar(255),
    1852 
    1853 
    1854 
    1855 
    1856         changed_to_status varchar(255),
    1857 
    1858 
    1859 
    1860 
    1861         PRIMARY KEY  (id)
    1862 
    1863 
    1864 
    1865 
    1866     ) $charset_collate;";
    1867 
    1868 
    1869 
    1870 
    1871        
    1872 
    1873 
    1874 
    1875 
    1876     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    1877 
    1878 
    1879 
    1880 
    1881     dbDelta( $sql );
     2255
     2256    $table_name = $wpdb->prefix . "posts";
     2257
     2258
     2259
     2260
     2261
     2262    $order_table_name = $wpdb->prefix . "midwest_logistics_orders";
     2263
     2264
     2265
     2266
     2267
     2268    $orderArray = [];
     2269
     2270
     2271
     2272
     2273
     2274    $sql = "INSERT INTO $order_table_name
     2275
     2276
     2277
     2278
     2279            (post_id,initial_status,changed_to_status)
     2280
     2281
     2282
     2283
     2284            SELECT wP.ID,post_status,'wc-processing'
     2285
     2286
     2287
     2288
     2289            FROM $table_name wP
     2290
     2291
     2292
     2293
     2294            WHERE post_status = 'wc-partial-shipped'
     2295
     2296
     2297
     2298
     2299            AND post_type='shop_order'; ";
     2300
     2301
     2302
     2303
     2304
     2305
     2306
     2307
     2308
     2309
     2310
     2311    $wpdb->query($sql);
     2312
     2313
     2314
     2315
     2316
     2317
     2318
     2319
     2320
     2321
     2322
     2323    $sql = "UPDATE wp_posts SET post_status = 'wc-processing'
     2324
     2325
     2326
     2327
     2328            WHERE ID IN (
     2329
     2330
     2331
     2332
     2333                SELECT post_id
     2334
     2335
     2336
     2337
     2338                FROM wp_midwest_logistics_orders   
     2339
     2340
     2341
     2342
     2343            )
     2344
     2345
     2346
     2347
     2348            AND post_status = 'wc-partial-shipped'
     2349
     2350
     2351
     2352
     2353            AND post_type='shop_order'; ";
     2354
     2355
     2356
     2357
     2358
     2359    $wpdb->query($sql);
     2360
    18822361
    18832362
     
    18942373
    18952374
    1896 function midwest_logistics_delete_table() {
     2375
     2376
     2377function midwest_logistics_revert_update_partial_orders() {
     2378
    18972379
    18982380
     
    19042386
    19052387
    1906     $table_name = $wpdb->prefix . MIDWESTLOGISTICS_TABLE_NAME;
    1907 
    1908 
    1909 
    1910 
    1911     $sql = "DROP TABLE IF EXISTS $table_name";
     2388
     2389    $table_name = $wpdb->prefix . "posts";
     2390
     2391
     2392
     2393
     2394
     2395    $order_table_name = $wpdb->prefix . "midwest_logistics_orders";
     2396
     2397
     2398
     2399
     2400
     2401    $orderArray = [];
     2402
     2403
     2404
     2405
     2406
     2407    $sql = "UPDATE $table_name SET post_status = 'wc-partial-shipped'
     2408
     2409
     2410
     2411
     2412            WHERE ID IN (
     2413
     2414
     2415
     2416
     2417                SELECT post_id
     2418
     2419
     2420
     2421
     2422                FROM $order_table_name   
     2423
     2424
     2425
     2426
     2427            )
     2428
     2429
     2430
     2431
     2432            AND post_status = 'wc-processing'
     2433
     2434
     2435
     2436
     2437            AND post_type='shop_order';";
     2438
     2439
     2440
     2441
     2442
     2443
     2444
    19122445
    19132446
     
    19242457
    19252458
    1926     $table_name = $wpdb->prefix . "midwest_logistics_orders";
    1927 
    1928 
    1929 
    1930 
    1931     $sql = "DROP TABLE IF EXISTS $table_name";
     2459
     2460
     2461    $sql = "DELETE FROM $order_table_name;";
     2462
    19322463
    19332464
     
    19392470
    19402471
     2472
    19412473}
    19422474
     
    19492481
    19502482
    1951 function midwest_logistics_update_partial_orders() {
    1952 
    1953 
    1954 
    1955 
    1956     global $wpdb;
    1957 
    1958 
    1959 
    1960 
    1961     $table_name = $wpdb->prefix . "posts";
    1962 
    1963 
    1964 
    1965 
    1966     $order_table_name = $wpdb->prefix . "midwest_logistics_orders";
    1967 
    1968 
    1969 
    1970 
    1971     $orderArray = [];
    1972 
    1973 
    1974 
    1975 
    1976     $sql = "INSERT INTO $order_table_name
    1977 
    1978 
    1979 
    1980             (post_id,initial_status,changed_to_status)
    1981 
    1982 
    1983 
    1984             SELECT wP.ID,post_status,'wc-processing'
    1985 
    1986 
    1987 
    1988             FROM $table_name wP
    1989 
    1990 
    1991 
    1992             WHERE post_status = 'wc-partial-shipped'
    1993 
    1994 
    1995 
    1996             AND post_type='shop_order'; ";
    1997 
    1998 
    1999 
    2000 
    2001 
    2002 
    2003 
    2004 
    2005 
    2006     $wpdb->query($sql);
    2007 
    2008 
    2009 
    2010 
    2011 
    2012 
    2013 
    2014 
    2015 
    2016     $sql = "UPDATE wp_posts SET post_status = 'wc-processing'
    2017 
    2018 
    2019 
    2020             WHERE ID IN (
    2021 
    2022 
    2023 
    2024                 SELECT post_id
    2025 
    2026 
    2027 
    2028                 FROM wp_midwest_logistics_orders   
    2029 
    2030 
    2031 
    2032             )
    2033 
    2034 
    2035 
    2036             AND post_status = 'wc-partial-shipped'
    2037 
    2038 
    2039 
    2040             AND post_type='shop_order'; ";
    2041 
    2042 
    2043 
    2044 
    2045     $wpdb->query($sql);
    2046 
    2047 
    2048 
    2049 
    2050 }
    2051 
    2052 
    2053 
    2054 
    2055 
    2056 
    2057 
    2058 
    2059 
    2060 function midwest_logistics_revert_update_partial_orders() {
    2061 
    2062 
    2063 
    2064 
    2065     global $wpdb;
    2066 
    2067 
    2068 
    2069 
    2070     $table_name = $wpdb->prefix . "posts";
    2071 
    2072 
    2073 
    2074 
    2075     $order_table_name = $wpdb->prefix . "midwest_logistics_orders";
    2076 
    2077 
    2078 
    2079 
    2080     $orderArray = [];
    2081 
    2082 
    2083 
    2084 
    2085     $sql = "UPDATE $table_name SET post_status = 'wc-partial-shipped'
    2086 
    2087 
    2088 
    2089             WHERE ID IN (
    2090 
    2091 
    2092 
    2093                 SELECT post_id
    2094 
    2095 
    2096 
    2097                 FROM $order_table_name   
    2098 
    2099 
    2100 
    2101             )
    2102 
    2103 
    2104 
    2105             AND post_status = 'wc-processing'
    2106 
    2107 
    2108 
    2109             AND post_type='shop_order';";
    2110 
    2111 
    2112 
    2113 
    2114 
    2115 
    2116 
    2117 
    2118 
    2119     $wpdb->query($sql);
    2120 
    2121 
    2122 
    2123 
    2124 
    2125 
    2126 
    2127 
    2128 
    2129     $sql = "DELETE FROM $order_table_name;";
    2130 
    2131 
    2132 
    2133 
    2134     $wpdb->query($sql);
    2135 
    2136 
    2137 
    2138 
    2139 }
    2140 
    2141 
    2142 
    2143 
    2144 
    2145 
    21462483
    21472484
     
    21572494
    21582495
     2496
    21592497//function debug_me() {
    21602498
     
    21622500
    21632501
     2502
    21642503//    var_dump(wp_next_scheduled( 'midwest_logistics_inventory_stock_update' ));
    21652504
     
    21672506
    21682507
     2508
    21692509//}
    21702510
     
    21722512
    21732513
     2514
    21742515//add_action( 'wp_loaded', 'midwest_logistics_inventory_stock_update' );
    21752516
     
    21822523
    21832524
     2525
     2526
  • midwest-logistics/trunk/midwest-wholesale.php

    r2383128 r2437678  
    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.14
     6    * Version:     1.1.15
    77    * WC requires at least: 3.0.0
    8     * WC tested up to: 4.5.1 
     8    * WC tested up to: 4.8.0 
    99    * Author:      Skynet Solutions Inc.
    1010    * Author URI:  http://www.skynet-solutions.net/
  • midwest-logistics/trunk/readme.txt

    r2383128 r2437678  
    33Tags: Midwest Logistics, Distribution, Shipping
    44Requires at least: 4.0
    5 Tested up to: 5.3.2
     5Tested up to: 5.6.0
    66Requires PHP: 5.4
    7 Stable tag: 1.1.14
     7Stable tag: 1.1.15
    88License: GPLv3
    99
Note: See TracChangeset for help on using the changeset viewer.