Changeset 2437678
- Timestamp:
- 12/11/2020 08:28:15 PM (5 years ago)
- Location:
- midwest-logistics/trunk
- Files:
-
- 3 edited
-
inc/setupFunctions.php (modified) (198 diffs)
-
midwest-wholesale.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
midwest-logistics/trunk/inc/setupFunctions.php
r2313232 r2437678 4 4 5 5 6 6 7 /* Does User Belong Here */ 7 8 … … 9 10 10 11 12 11 13 if ( ! defined( 'MIDWESTLOGISTICS_VERSION' ) ) { 12 14 … … 14 16 15 17 18 16 19 header( 'Status: 403 Forbidden' ); 17 20 … … 19 22 20 23 24 21 25 header( 'HTTP/1.1 403 Forbidden' ); 22 26 … … 24 28 25 29 30 26 31 exit(); 27 32 … … 29 34 30 35 36 31 37 } 32 38 … … 39 45 40 46 47 48 41 49 function midwest_logistics_initialize() { 42 50 … … 54 62 55 63 64 65 66 56 67 //Do we need to update the db table? 57 68 … … 59 70 60 71 72 61 73 if( empty(get_option( 'midwest_logistics_db_version' )) || get_option( 'midwest_logistics_db_version' ) !== '1.1' ){ 62 74 … … 64 76 65 77 78 66 79 //Run any updates for table or option settings here. It will be ran when the plugin updates. 67 80 … … 79 92 80 93 94 95 96 81 97 } 82 98 … … 84 100 85 101 102 86 103 if (!in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 87 104 … … 89 106 90 107 108 91 109 add_action( 'admin_notices', 'midwest_logistics_no_woo' ); 92 110 … … 94 112 95 113 114 96 115 $MIDWESTLOGISTICS_activated = false; 97 116 … … 99 118 100 119 120 101 121 } 102 122 … … 104 124 105 125 126 106 127 } 107 128 … … 114 135 115 136 137 138 116 139 function midwest_logistics_activate() { 117 140 … … 119 142 120 143 144 121 145 if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 122 146 … … 124 148 125 149 150 126 151 midwest_logistics_create_table(); 127 152 … … 129 154 130 155 156 131 157 midwest_logistics_create_order_table(); 132 158 … … 139 165 140 166 167 168 141 169 //set up the scheduler stock update 142 170 … … 144 172 145 173 174 146 175 if ( ! wp_next_scheduled( 'midwest_logistics_inventory_stock_update' ) ) { 147 176 … … 149 178 150 179 180 151 181 wp_schedule_event(time(), 'hourly', 'midwest_logistics_inventory_stock_update'); 152 182 … … 154 184 155 185 186 156 187 } 157 188 … … 164 195 165 196 197 198 166 199 //set up the scheduler for the tracking information 167 200 … … 169 202 170 203 204 171 205 if ( ! wp_next_scheduled( 'midwest_logistics_update_tracking_information' ) ) { 172 206 … … 174 208 175 209 210 176 211 wp_schedule_event(time(), 'hourly', 'midwest_logistics_update_tracking_information'); 177 212 … … 179 214 180 215 216 181 217 } 182 218 … … 189 225 190 226 227 228 191 229 midwest_logistics_revert_update_partial_orders(); 192 230 … … 199 237 200 238 239 240 201 241 update_option( 'midwest_logistics_db_version', '1.1' ); 202 242 … … 204 244 205 245 246 206 247 $MIDWESTLOGISTICS_activated = true; 207 248 … … 209 250 210 251 252 211 253 } 212 254 … … 214 256 215 257 258 216 259 } 217 260 … … 224 267 225 268 269 270 226 271 function midwest_logistics_deactivate() { 227 272 … … 229 274 230 275 276 231 277 wp_clear_scheduled_hook('midwest_logistics_inventory_stock_update'); 232 278 … … 234 280 235 281 282 236 283 wp_clear_scheduled_hook('midwest_logistics_update_tracking_information'); 237 284 … … 239 286 240 287 288 241 289 midwest_logistics_update_partial_orders(); 242 290 … … 244 292 245 293 294 246 295 } 247 296 … … 254 303 255 304 305 306 256 307 function midwest_logistics_unistall() { 257 308 … … 259 310 260 311 312 261 313 midwest_logistics_delete_table(); 262 314 … … 264 316 265 317 318 266 319 delete_option("midwest_logistics_settings"); 267 320 … … 269 322 270 323 324 271 325 delete_option("midwest_logistics_db_version"); 272 326 … … 274 328 275 329 330 276 331 //wp_clear_scheduled_hook('midwest_logistics_inventory_stock_update'); 277 332 … … 279 334 280 335 336 281 337 //wp_clear_scheduled_hook('midwest_logistics_update_tracking_information'); 282 338 … … 284 340 285 341 342 286 343 } 287 344 … … 304 361 305 362 363 364 365 366 306 367 /* 307 368 … … 309 370 310 371 372 311 373 * Registers the scripts needed for the Midwest Woocommerce. 312 374 … … 314 376 315 377 378 316 379 */ 317 380 … … 319 382 320 383 384 321 385 add_action( 'admin_enqueue_scripts', 'midwest_logistics_admin_script' ); 322 386 … … 324 388 325 389 390 326 391 function midwest_logistics_admin_script($hook) { 327 392 … … 329 394 330 395 396 331 397 wp_enqueue_script( 'midwest_logistics_admin_script', plugin_dir_url( __FILE__ ) . '../scripts/admin.js', false, '1.0.0' ); 332 398 … … 334 400 335 401 402 336 403 } 337 404 … … 344 411 345 412 413 414 346 415 function midwest_logistics_warn_phpversion() { 347 416 … … 349 418 350 419 420 351 421 ?> 352 422 … … 354 424 355 425 426 356 427 <div class="notice-error notice is-dismissible"> 357 428 … … 359 430 360 431 432 361 433 <p><strong><?php _e( "PHP version 5.3.0 is required to run this plugin.",MIDWESTLOGISTICS_NAME); ?></strong></p> 362 434 … … 364 436 365 437 438 366 439 </div> 367 440 … … 369 442 370 443 444 371 445 <?php 372 446 … … 374 448 375 449 450 376 451 } 377 452 … … 384 459 385 460 461 462 386 463 function midwest_logistics_no_woo() { 387 464 … … 389 466 390 467 468 391 469 if (! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 392 470 … … 394 472 395 473 474 396 475 ?> 397 476 … … 399 478 400 479 480 401 481 <div class="notice-error notice is-dismissible"> 402 482 … … 404 484 405 485 486 406 487 <p><strong><?php _e( "Woocommerce is required to run the " . MIDWESTLOGISTICS_NAME ." plugin. Please install or activate Woocommerce.",MIDWESTLOGISTICS_NAME); ?></strong></p> 407 488 … … 409 490 410 491 492 411 493 </div> 412 494 … … 414 496 415 497 498 416 499 <?php 417 500 … … 419 502 420 503 504 421 505 } 422 506 … … 424 508 425 509 510 426 511 427 512 … … 429 514 430 515 516 431 517 } 432 518 … … 439 525 440 526 527 528 441 529 function midwest_logistics_no_api() { 442 530 … … 444 532 445 533 534 446 535 $settingsOptions = get_option( 'Midwest_Logistics_settings' ); 447 536 … … 454 543 455 544 545 546 456 547 $apiKey = ""; 457 548 … … 459 550 460 551 552 461 553 $customerId = ""; 462 554 … … 464 556 465 557 558 466 559 $settingOptions = get_option('Midwest_Logistics_settings',''); 467 560 … … 469 562 470 563 564 471 565 if($settingOptions !== "") { 472 566 … … 474 568 475 569 570 476 571 $apiKey = $settingOptions["Midwest_Logistics_API_Key_field_0"]; 477 572 … … 479 574 480 575 576 481 577 $customerId = $settingOptions["Midwest_Logistics_customer_id_text_field_1"]; 482 578 … … 484 580 485 581 582 486 583 } 487 584 … … 489 586 490 587 588 491 589 if ($apiKey === "" || $customerId === "") { 492 590 … … 494 592 495 593 594 496 595 ?> 497 596 … … 499 598 500 599 600 501 601 <div class="notice-error notice is-dismissible"> 502 602 … … 504 604 505 605 606 506 607 <p><strong><?php _e( "An API key and customer id is required before " . MIDWESTLOGISTICS_NAME . " plugin can be used.",MIDWESTLOGISTICS_NAME); ?></strong></p> 507 608 … … 509 610 510 611 612 511 613 </div> 512 614 … … 514 616 515 617 618 516 619 <?php 517 620 … … 519 622 520 623 624 521 625 } 522 626 … … 524 628 525 629 630 526 631 } 527 632 … … 534 639 535 640 641 642 536 643 //this must be set for the wp scheduler to work. 537 644 … … 539 646 540 647 648 541 649 add_action( 'midwest_logistics_inventory_stock_update', 'midwest_logistics_inventory_stock_update' ); 542 650 … … 544 652 545 653 654 546 655 function midwest_logistics_inventory_stock_update() { 547 656 … … 554 663 555 664 665 666 556 667 $settingsOptions = get_option( 'Midwest_Logistics_settings' ); 557 668 … … 559 670 560 671 672 561 673 if($settingsOptions['Midwest_Logistics_select_field_1'] == "2" || $settingsOptions['Midwest_Logistics_select_field_1'] == "") { 562 674 … … 564 676 565 677 678 566 679 //if the dropdown is set to no don't worry about it. 567 680 … … 569 682 570 683 684 571 685 return; 572 686 … … 574 688 575 689 690 576 691 } 577 692 … … 584 699 585 700 701 702 586 703 $apiKey = ""; 587 704 … … 589 706 590 707 708 591 709 $settingOptions = get_option('Midwest_Logistics_settings',''); 592 710 … … 594 712 595 713 714 596 715 if($settingOptions !== "") { 597 716 … … 599 718 600 719 720 601 721 $apiKey = $settingOptions["Midwest_Logistics_API_Key_field_0"]; 602 722 … … 604 724 605 725 726 606 727 } 607 728 … … 614 735 615 736 737 738 616 739 617 740 … … 619 742 620 743 744 621 745 //simple Products 622 746 … … 624 748 625 749 750 626 751 $args = array( 627 752 … … 629 754 630 755 756 631 757 'posts_per_page' => 10000, 632 758 … … 634 760 635 761 762 636 763 'offset' => 0, 637 764 … … 639 766 640 767 768 641 769 'category' => '', 642 770 … … 644 772 645 773 774 646 775 'category_name' => '', 647 776 … … 649 778 650 779 780 651 781 'orderby' => 'date', 652 782 … … 654 784 655 785 786 656 787 'order' => 'DESC', 657 788 … … 659 790 660 791 792 661 793 'include' => '', 662 794 … … 664 796 665 797 798 666 799 'exclude' => '', 667 800 … … 669 802 670 803 804 671 805 'meta_key' => '_midwest_logistics_product_select', 672 806 … … 674 808 675 809 810 676 811 'meta_value' => 'Y', 677 812 … … 679 814 680 815 816 681 817 'post_type' => 'product', 682 818 … … 684 820 685 821 822 686 823 'post_mime_type' => '', 687 824 … … 689 826 690 827 828 691 829 'post_parent' => '', 692 830 … … 694 832 695 833 834 696 835 'author' => '', 697 836 … … 699 838 700 839 840 701 841 'author_name' => '', 702 842 … … 704 844 705 845 846 706 847 'post_status' => 'publish', 707 848 … … 709 850 710 851 852 711 853 'suppress_filters' => true 712 854 … … 714 856 715 857 858 716 859 ); 717 860 … … 719 862 720 863 864 721 865 $posts_array = get_posts( $args ); 722 866 … … 724 868 725 869 870 726 871 foreach ( $posts_array as $post) : setup_postdata( $posts_array ); 727 872 … … 729 874 730 875 876 731 877 //simple product 732 878 … … 734 880 735 881 882 736 883 if(get_post_meta($post->ID, '_manage_stock', true ) === "yes") { 737 884 … … 739 886 740 887 888 741 889 $SKUNumber = get_post_meta($post->ID, '_midwest_logistics_product_sku_text_field', true ); 742 890 … … 744 892 745 893 894 746 895 if($SKUNumber !== "") { 747 896 … … 749 898 750 899 900 751 901 $jsonArray = [ 752 902 … … 754 904 755 905 906 756 907 "apiKey" => $apiKey, 757 908 … … 759 910 760 911 912 761 913 "sku" => $SKUNumber, 762 914 … … 764 916 765 917 918 766 919 "request" => "productcheck" 767 920 … … 769 922 770 923 924 771 925 ]; 772 926 … … 779 933 780 934 935 936 781 937 $postString = json_encode ($jsonArray); 782 938 … … 789 945 790 946 947 948 791 949 $args = array( 792 950 … … 794 952 795 953 954 796 955 'body' => $postString, 797 956 … … 799 958 800 959 960 801 961 'timeout' => '60', 802 962 … … 804 964 805 965 966 806 967 'redirection' => '5', 807 968 … … 809 970 810 971 972 811 973 'httpversion' => '1.0', 812 974 … … 814 976 815 977 978 816 979 'blocking' => true, 817 980 … … 819 982 820 983 984 821 985 'headers' => array(), 822 986 … … 824 988 825 989 990 826 991 'cookies' => array() 827 992 … … 829 994 830 995 996 831 997 ); 832 998 … … 834 1000 835 1001 1002 836 1003 837 1004 … … 839 1006 840 1007 1008 841 1009 $wp_remote_post_response = wp_remote_post( MIDWESTLOGISTICS_API_URL,$args); 842 1010 … … 844 1012 845 1013 1014 846 1015 if(is_wp_error($wp_remote_post_response)) { 847 1016 … … 849 1018 850 1019 1020 851 1021 $httpcode = "500"; 852 1022 … … 854 1024 855 1025 1026 856 1027 $code = $wp_remote_post_response->get_error_code(); 857 1028 … … 859 1030 860 1031 1032 861 1033 $response = $wp_remote_post_response->get_error_messages($code); 862 1034 … … 864 1036 865 1037 1038 866 1039 if(is_array($response)) { 867 1040 … … 869 1042 870 1043 1044 871 1045 $response = $response[0]; 872 1046 … … 874 1048 875 1049 1050 876 1051 } 877 1052 … … 879 1054 880 1055 1056 881 1057 882 1058 … … 884 1060 885 1061 1062 886 1063 } else { 887 1064 … … 889 1066 890 1067 1068 891 1069 $httpcode = wp_remote_retrieve_response_code( $wp_remote_post_response ); 892 1070 … … 894 1072 895 1073 1074 896 1075 $response = $wp_remote_post_response["body"]; 897 1076 … … 899 1078 900 1079 1080 901 1081 } 902 1082 … … 904 1084 905 1085 1086 906 1087 907 1088 … … 914 1095 915 1096 1097 1098 916 1099 //$ch = curl_init( MIDWESTLOGISTICS_API_URL ); 917 1100 … … 919 1102 920 1103 1104 921 1105 //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 922 1106 … … 924 1108 925 1109 1110 926 1111 //curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); 927 1112 … … 929 1114 930 1115 1116 931 1117 //curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 932 1118 … … 939 1125 940 1126 1127 1128 941 1129 //$response = curl_exec( $ch ); 942 1130 … … 944 1132 945 1133 1134 946 1135 //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 947 1136 … … 949 1138 950 1139 1140 951 1141 if($httpcode == "200") { 952 1142 … … 954 1144 955 1145 1146 956 1147 $responseArray = midwest_logistics_inventory_json_parse($response); 957 1148 … … 959 1150 960 1151 1152 961 1153 if(is_array($responseArray)) { 962 1154 … … 964 1156 965 1157 1158 966 1159 if($responseArray["result"] = "200") { 967 1160 … … 969 1162 970 1163 1164 971 1165 $stockAmount = $responseArray["stockAmount"]; 972 1166 … … 974 1168 975 1169 1170 976 1171 $inStock = $responseArray["instock"]; 977 1172 … … 979 1174 980 1175 1176 981 1177 $responseText = $inStock; 982 1178 … … 984 1180 985 1181 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(); 1026 1186 } 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 1027 1727 1028 1728 … … 1034 1734 1035 1735 1736 1036 1737 } 1037 1738 … … 1039 1740 1040 1741 1742 1041 1743 } 1042 1744 … … 1044 1746 1045 1747 1748 1046 1749 } 1047 1750 … … 1054 1757 1055 1758 1759 1760 1056 1761 if($httpcode == "500") { 1057 1762 … … 1059 1764 1060 1765 1766 1061 1767 new WP_Error( MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." ); 1062 1768 … … 1064 1770 1065 1771 1772 1066 1773 $responseArray = array("result" => false, "message" => MIDWESTLOGISTICS_NAME . " API is down."); 1067 1774 … … 1069 1776 1070 1777 1778 1071 1779 } 1072 1780 … … 1079 1787 1080 1788 1789 1790 1081 1791 //add the log 1082 1792 … … 1084 1794 1085 1795 1796 1086 1797 midwest_logistics_add_communication_log($postString,$response,$post->ID,"product",get_the_title(),$responseText); 1087 1798 … … 1089 1800 1090 1801 1802 1091 1803 } 1092 1804 … … 1094 1806 1095 1807 1808 1096 1809 } 1097 1810 … … 1099 1812 1100 1813 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 1842 function 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 1956 function 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 1372 2048 1373 2049 … … 1379 2055 1380 2056 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 1597 2066 1598 2067 … … 1605 2074 1606 2075 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 2076 function 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 ); 1691 2161 1692 2162 … … 1706 2176 1707 2177 1708 1709 1710 1711 function midwest_logistics_create_table() { 2178 function midwest_logistics_delete_table() { 2179 1712 2180 1713 2181 … … 1719 2187 1720 2188 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 1802 2228 1803 2229 … … 1809 2235 1810 2236 1811 function midwest_logistics_create_order_table() { 2237 2238 2239 2240 2241 2242 2243 2244 function midwest_logistics_update_partial_orders() { 2245 1812 2246 1813 2247 … … 1819 2253 1820 2254 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 1882 2361 1883 2362 … … 1894 2373 1895 2374 1896 function midwest_logistics_delete_table() { 2375 2376 2377 function midwest_logistics_revert_update_partial_orders() { 2378 1897 2379 1898 2380 … … 1904 2386 1905 2387 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 1912 2445 1913 2446 … … 1924 2457 1925 2458 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 1932 2463 1933 2464 … … 1939 2470 1940 2471 2472 1941 2473 } 1942 2474 … … 1949 2481 1950 2482 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_name1977 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 wP1989 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_id2025 2026 2027 2028 FROM wp_midwest_logistics_orders2029 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_id2094 2095 2096 2097 FROM $order_table_name2098 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 2146 2483 2147 2484 … … 2157 2494 2158 2495 2496 2159 2497 //function debug_me() { 2160 2498 … … 2162 2500 2163 2501 2502 2164 2503 // var_dump(wp_next_scheduled( 'midwest_logistics_inventory_stock_update' )); 2165 2504 … … 2167 2506 2168 2507 2508 2169 2509 //} 2170 2510 … … 2172 2512 2173 2513 2514 2174 2515 //add_action( 'wp_loaded', 'midwest_logistics_inventory_stock_update' ); 2175 2516 … … 2182 2523 2183 2524 2525 2526 -
midwest-logistics/trunk/midwest-wholesale.php
r2383128 r2437678 4 4 * Plugin URI: https://plugins.skynet-solutions.net/ 5 5 * Description: Midwest Wholesale Plugin allows you to automatically add Woocommerce orders into the Midwest Logistics order system. 6 * Version: 1.1.1 46 * Version: 1.1.15 7 7 * WC requires at least: 3.0.0 8 * WC tested up to: 4. 5.18 * WC tested up to: 4.8.0 9 9 * Author: Skynet Solutions Inc. 10 10 * Author URI: http://www.skynet-solutions.net/ -
midwest-logistics/trunk/readme.txt
r2383128 r2437678 3 3 Tags: Midwest Logistics, Distribution, Shipping 4 4 Requires at least: 4.0 5 Tested up to: 5. 3.25 Tested up to: 5.6.0 6 6 Requires PHP: 5.4 7 Stable tag: 1.1.1 47 Stable tag: 1.1.15 8 8 License: GPLv3 9 9
Note: See TracChangeset
for help on using the changeset viewer.