Changeset 3187953
- Timestamp:
- 11/13/2024 05:57:24 PM (17 months ago)
- Location:
- midwest-logistics
- Files:
-
- 27 added
- 2 deleted
- 13 edited
-
tags/1.1.15/classes/class-wc-ml-shipping-method.php (modified) (1 diff)
-
tags/1.1.16/midwest-wholesale.php (modified) (1 diff)
-
tags/1.1.16/nbproject (added)
-
tags/1.1.16/nbproject/private (added)
-
tags/1.1.16/nbproject/private/private.xml (added)
-
tags/1.1.26 (added)
-
tags/1.1.26/classes (added)
-
tags/1.1.26/classes/class-ml-api.php (added)
-
tags/1.1.26/classes/class-ml-order.php (added)
-
tags/1.1.26/classes/class-ml-settings-orders.php (added)
-
tags/1.1.26/classes/class-ml-settings.php (added)
-
tags/1.1.26/classes/class-ml-stock.php (added)
-
tags/1.1.26/classes/class-ml-ups-shipping.php (added)
-
tags/1.1.26/classes/class-ml-usps-shipping.php (added)
-
tags/1.1.26/classes/class-wc-ml-shipping-method.php (added)
-
tags/1.1.26/classes/class-wc-ml-shipping-options.php (added)
-
tags/1.1.26/data (added)
-
tags/1.1.26/data/data-usps-flat-rate-boxes.php (added)
-
tags/1.1.26/data/data-usps-services.php (added)
-
tags/1.1.26/inc (added)
-
tags/1.1.26/inc/logFunctions.php (added)
-
tags/1.1.26/inc/productFunctions.php (added)
-
tags/1.1.26/inc/setupFunctions.php (added)
-
tags/1.1.26/inc/trackingFunctions.php (added)
-
tags/1.1.26/license.txt (added)
-
tags/1.1.26/midwest-wholesale.php (added)
-
tags/1.1.26/readme.txt (added)
-
tags/1.1.26/scripts (added)
-
tags/1.1.26/scripts/admin.js (added)
-
trunk/classes/class-ml-api.php (modified) (2 diffs)
-
trunk/classes/class-ml-order.php (modified) (16 diffs)
-
trunk/classes/class-ml-settings.php (modified) (3 diffs)
-
trunk/classes/class-ml-stock.php (modified) (3 diffs)
-
trunk/classes/class-ml-usps-shipping.php (modified) (1 diff)
-
trunk/classes/class-wc-ml-shipping-method.php (modified) (1 diff)
-
trunk/inc/orderFunctions.php (deleted)
-
trunk/inc/productFunctions.php (modified) (5 diffs)
-
trunk/inc/settingsFunctions.php (deleted)
-
trunk/inc/trackingFunctions.php (modified) (3 diffs)
-
trunk/midwest-wholesale.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/scripts/admin.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
midwest-logistics/tags/1.1.15/classes/class-wc-ml-shipping-method.php
r2437677 r3187953 50 50 if(is_array($this->shipping_options)) { 51 51 foreach($this->shipping_options as $option) { 52 $shipping_options[$option["id"]] = $ option["value"];52 $shipping_options[$option["id"]] = $data["default_shipping"]; 53 53 } 54 54 } -
midwest-logistics/tags/1.1.16/midwest-wholesale.php
r2481616 r3187953 6 6 * Version: 1.1.16 7 7 * WC requires at least: 3.0.0 8 * WC tested up to: 4.5.18 * WC tested up to: 5.0.0 9 9 * Author: Skynet Solutions Inc. 10 10 * Author URI: http://www.skynet-solutions.net/ -
midwest-logistics/trunk/classes/class-ml-api.php
r3008368 r3187953 39 39 } 40 40 41 $apiTimeout = "60"; 42 $settingOptions = get_option('Midwest_Logistics_settings',''); 43 if (!empty( $settingOptions ) ) { 44 if(isset($settingOptions['Midwest_Logistics_api_timeout_setting'])) { 45 $apiTimeout = $settingOptions['Midwest_Logistics_api_timeout_setting']; 46 } 47 } 48 if(!is_numeric($apiTimeout)) { 49 $apiTimeout = "60"; 50 } 51 41 52 $args = array( 42 53 'body' => $data, 43 'timeout' => '60',54 'timeout' => $apiTimeout, 44 55 'redirection' => '5', 45 56 'httpversion' => '1.0', … … 57 68 if(is_wp_error($wp_remote_post_response)) { 58 69 $response["code"] = $wp_remote_post_response->get_error_code(); 59 $response["response"] = $wp_remote_post_response->get_error_messages($response["code"]); 60 if(is_array($response)) { 61 $response = $response[0]; 62 } 63 70 $response["response"] = $wp_remote_post_response->get_error_message($response["code"]); 64 71 } else { 65 72 $response["code"] = wp_remote_retrieve_response_code( $wp_remote_post_response ); -
midwest-logistics/trunk/classes/class-ml-order.php
r3045832 r3187953 1 1 <?php 2 2 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; // at the beginning of the file 3 3 /* 4 4 * To change this license header, choose License Headers in Project Properties. … … 12 12 * 13 13 * @author mburton 14 * 15 * When it comes to the status of the order there are three statuses possible. 16 * 1 = do not send to Midwest 17 * 2 = Send to Midwest. 18 * 3 = Sent to Midwest 14 19 */ 15 20 class ML_Order { … … 18 23 //this must be set for the wp scheduler to work. 19 24 add_action( 'woocommerce_order_status_changed',array($this, 'midwest_logistics_process_order') ); 20 add_action( 'woocommerce_admin_order_data_after_order_details',array($this, 'midwest_logistics_order_status_box') ); 21 add_action( 'woocommerce_process_shop_order_meta',array($this, 'midwest_logistics_order_status_box_update'), 10, 2 ); 22 add_action( 'wp_ajax_midwest_logistics_process_shop_order',array($this, 'midwest_logistics_admin_ajax_process_order'),100 ); 25 //add_action( 'woocommerce_admin_order_data_after_order_details',array($this, 'midwest_logistics_order_status_box') ); 26 //add_action( 'woocommerce_process_shop_order_meta',array($this, 'midwest_logistics_order_status_box_update'), 10, 2 ); 27 28 //Used in Orders with errors and on the order screen to process orders. 29 add_action( 'wp_ajax_midwest_logistics_process_shop_order',array($this, 'midwest_logistics_admin_ajax_process_order'),100 ); 30 //Used on the order screen to cancel orders. 31 add_action( 'wp_ajax_midwest_logistics_cancel_shop_order',array($this, 'midwest_logistics_admin_ajax_cancel_order'),100 ); 32 23 33 add_action( 'admin_notices',array($this, 'midwest_logistics_admin_order_status_notification_notice'),100 ); 24 34 add_action( 'admin_notices',array($this, 'midwest_logistics_admin_order_error_notification_notice'),100 ); … … 27 37 add_filter( 'woocommerce_order_item_meta_end',array($this, 'midwest_logisitcs_woocommerce_email_order_item_meta_fields'), 100, 3 ); 28 38 add_filter( 'woocommerce_order_item_get_formatted_meta_data',array($this, 'midwest_logisitcs_order_item_get_formatted_meta_data'), 10, 1 ); 29 add_action( 'midwest_logistics_update_tracking_information',array($this, 'midwest_logistics_order_cron_job') ); 39 add_action( 'add_meta_boxes',array($this, 'add_midwest_meta_box'),10,1 ); 40 30 41 } 31 function midwest_logistics_process_order($orderId ) {42 function midwest_logistics_process_order($orderId,$ignoreStatus = false) { 32 43 $settingOptions = get_option('Midwest_Logistics_settings',''); 33 44 if ( empty( $settingOptions ) ) { … … 51 62 52 63 $default_shipping = $shipping_settings_data["default_shipping"]; 53 if($default_shipping === "" ) {64 if($default_shipping === "" || $default_shipping == "5") { //5 is old shipping 54 65 $default_shipping = "100000045"; 55 66 } … … 84 95 85 96 // Get an instance of the WC_Order object (same as before) 86 97 if($ignoreStatus == true) { 98 //when submitting the order manually via the interface we don't care that it is in the correct status. 99 $midwest_logistics_order_status_setting = "wc-" . $order->get_status(); 100 } 87 101 if("wc-" . $order->get_status() === $midwest_logistics_order_status_setting) { 88 102 //proccess that order; … … 236 250 ] 237 251 ]; 238 252 239 253 $httpcode = "500"; 240 254 $postString = json_encode ($jsonArray); … … 264 278 $order->update_meta_data('_midwest_logistics_CRM_order_id', esc_attr( $CRMorderId ) ); 265 279 $order->update_meta_data('_midwest_logistics_CRM_order_status', esc_attr( "2" ) ); 280 $note = "Fulfillment order accepted by Midwest Logistics. Order# " . $CRMorderId; 281 $order->add_order_note($note); 282 266 283 } else { 267 284 $order->update_meta_data('_midwest_logistics_CRM_order_status', esc_attr( "3" ) ); … … 291 308 } 292 309 } 293 310 /* 294 311 function midwest_logistics_order_status_box($wccm_before_checkout) { 295 312 $orderId = get_the_ID(); … … 347 364 } 348 365 } 366 349 367 function midwest_logistics_order_status_box_update() { 350 368 if(isset($_POST['Midwest_logistics_order_status'])) { … … 373 391 } 374 392 } 393 * * 394 */ 395 375 396 function midwest_logistics_admin_ajax_process_order() { 376 397 if(isset($_POST['order'])) { … … 386 407 387 408 //mark it to be sent 388 $order->update_meta_data('_midwest_logistics_CRM_order_status', esc_attr("2" ));409 $order->update_meta_data('_midwest_logistics_CRM_order_status',"2"); 389 410 $order->save_meta_data(); 390 $this->midwest_logistics_process_order($postedOrder );411 $this->midwest_logistics_process_order($postedOrder,true); 391 412 392 413 … … 408 429 echo json_encode($response); 409 430 exit(); 431 } 432 } 433 function midwest_logistics_admin_ajax_cancel_order() { 434 if(isset($_POST['order'])) { 435 $response = array("code"=>200,"message"=>""); 436 437 $postedOrder = filter_input(INPUT_POST, "order"); 438 if($postedOrder == false) { 439 $response = array( 440 "code"=>500, 441 "message"=>"Order Not Found." 442 ); 443 echo json_encode($response); 444 exit(); 445 } 446 447 $order = wc_get_order( $postedOrder ); 448 if ( empty( $order ) ) { 449 $response = array( 450 "code"=>500, 451 "message"=>"Order Not Found." 452 ); 453 echo json_encode($response); 454 exit(); 455 } 456 $currentCRMId = $order->get_meta('_midwest_logistics_CRM_order_id' ); 457 if($currentCRMId == "") { 458 $response = array( 459 "code"=>500, 460 "message"=>"No Midwest Logistics order found." 461 ); 462 echo json_encode($response); 463 exit(); 464 } 465 466 $settingOptions = get_option('Midwest_Logistics_settings',''); 467 $midwest_logistics_api_key = $settingOptions["Midwest_Logistics_API_Key_field_0"]; 468 if($midwest_logistics_api_key == "") { 469 $response = array( 470 "code"=>500, 471 "message"=>"Invalid Midwest Logistics API Key." 472 ); 473 echo json_encode($response); 474 exit(); 475 } 476 $jsonArray = [ 477 "apiKey" => $midwest_logistics_api_key, 478 "request" => "cancelorders", 479 "orders" => [ 480 [ 481 "CRMID" => $currentCRMId 482 ] 483 ] 484 ]; 485 486 $httpcode = "500"; 487 $postString = json_encode ($jsonArray); 488 489 $API = new ML_API(); 490 $response = $API->send($postString); 491 if($response != null) { 492 $httpcode = $response["code"]; 493 $response = $response["response"]; 494 } 495 496 $responseText = ""; 497 $message = ""; 498 $code = 500; 499 if($httpcode == "200") { 500 if(json_decode($response) !== null) { 501 $jsonResponse = json_decode($response); 502 $curl_result = $jsonResponse -> {"result"}; 503 $responseText = $jsonResponse -> {"message"}; 504 505 if($curl_result === "200") { 506 $CRMorder = $jsonResponse -> {"orders"}; 507 if(is_array($CRMorder)) { 508 $apireturnedOrder = $CRMorder[0]; 509 $CRMorderId = $apireturnedOrder -> CRMOrderId; 510 $responseStatus = $apireturnedOrder -> status; 511 512 //if the order was not found then we are good. 513 if($apireturnedOrder->message == "") { 514 $responseStatus = "200"; 515 } 516 if(strtolower($apireturnedOrder->message) == "order not found.") { 517 $responseStatus = "200"; 518 } 519 520 if($responseStatus == "200") { 521 $order->update_meta_data('_midwest_logistics_CRM_order_id', "" ); 522 $order->update_meta_data('_midwest_logistics_CRM_order_status',"1"); 523 $order->save_meta_data(); 524 $code = 200; 525 526 $note = "Midwest Logistics Fulfillment order canceled."; 527 $order->add_order_note($note); 528 } else { 529 $message = "Cannot Cancel order. Api says: " . $apireturnedOrder->message; 530 531 $note = "Midwest Logistics Fulfillment order cannot be canceled. Message: " . $apireturnedOrder->message; 532 $order->add_order_note($note); 533 } 534 535 } 536 } else { 537 $message = $responseText; 538 } 539 } else { 540 new WP_Error( MIDWESTLOGISTICS_NAME . ' API',"Invalid Call" ); 541 } 542 } 543 if($httpcode == "500") { 544 new WP_Error( MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." ); 545 } 546 547 //add the log 548 midwest_logistics_add_communication_log($postString,$response,$order ->get_order_number(),"order",$currentCRMId,$responseText); 549 550 $response = array( 551 "code"=>$code, 552 "message"=>$message 553 ); 554 echo json_encode($response); 555 exit(); 556 410 557 } 411 558 } … … 447 594 function midwest_logistics_admin_order_error_notification_notice() { 448 595 449 450 $orderId = get_the_ID(); 596 if(!isset($_GET['id'])) { 597 return; 598 } 599 $orderId = $_GET['id']; 451 600 $order = wc_get_order( $orderId ); 452 601 if ( empty( $order ) ) { … … 573 722 574 723 } 575 576 577 578 724 ?> 579 725 … … 672 818 } 673 819 674 function midwest_logistics_order_cron_job() { 820 function add_midwest_meta_box() { 821 822 $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) && wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() 823 ? wc_get_page_screen_id( 'shop-order' ) 824 : 'shop_order'; 825 826 //add_meta_box( 'midwest_order_meta_box', 'Midwest Logistics', array($this, 'output_meta_box'),"woocommerce_page_wc-orders","side"); 827 add_meta_box( 'midwest_order_meta_box', 'Midwest Logistics', array($this, 'output_meta_box'),$screen,"side"); 828 } 829 function output_meta_box($post) { 830 831 $order = wc_get_order($post); 832 if ( empty( $order ) ) { 833 return; 834 } 835 836 $orderStatus = $order->get_meta('_midwest_logistics_CRM_order_status'); 837 $currentCRMId = $order->get_meta('_midwest_logistics_CRM_order_id' ); 838 675 839 $settingOptions = get_option('Midwest_Logistics_settings',''); 676 840 if ( empty( $settingOptions ) ) { 677 841 return; 678 842 } 679 if(isset($settingOptions['Midwest_Logistics_auto_push_select_field'])) { 680 $midwest_logistics_auto_push_select_field = $settingOptions['Midwest_Logistics_auto_push_select_field']; 681 if($midwest_logistics_auto_push_select_field != "2") { 682 //don't auto push. 683 return; 684 } 685 } 686 687 688 $dayLimit = "160"; 689 if(isset($settingOptions['Midwest_Logistics_submit_order_limit'])) { 690 $dayLimit = $settingOptions['Midwest_Logistics_submit_order_limit']; 691 } 692 693 if(!is_numeric($dayLimit)) { 694 $dayLimit = "30"; 695 } 696 697 $order_status_setting = $settingOptions['Midwest_Logistics_select_field_2']; 698 $date = date_create(date('Y-m-d H:i:s')); 699 $startDate = $date->sub(new DateInterval('P' . $dayLimit . 'D')); 700 $args = array( 701 'limit'=> 10, 702 'type'=> 'shop_order', 703 'date_created'=> '>' .$startDate->format('Y-m-d H:i:s'), 704 'status' => $order_status_setting, 705 'order' => 'DESC', 706 '_midwest_logistics_CRM_order_status' => '3' 707 ); 708 $orders = wc_get_orders($args); 709 if(count($orders) > 0 ) { 710 foreach ($orders as $order) { 711 $order->update_meta_data( $orderId, '_midwest_logistics_CRM_order_status', esc_attr( "2" ) ); 712 $order->save_meta_data(); 713 $this->midwest_logistics_process_order($orderId); 714 } 843 844 if(empty($currentCRMId)) { 845 $currentCRMId = ""; 846 } 847 $midwest_logistics_order_status_setting = $settingOptions['Midwest_Logistics_select_field_2']; 848 $midwest_logistics_auto_push_select_field = $settingOptions['Midwest_Logistics_auto_push_select_field']; 849 850 if($orderStatus === "") { 851 $orderStatus = $midwest_logistics_auto_push_select_field; 852 if($orderStatus === "" || empty($orderStatus)) { 853 $orderStatus = "1"; 854 } 855 $order->update_meta_data('_midwest_logistics_CRM_order_status', esc_attr($orderStatus ) ); 856 $order->save_meta_data(); 857 } 858 if($orderStatus === "") { 859 $orderStatus = "1"; 860 } 861 $status = "Not sent"; 862 switch($orderStatus) { 863 case "1": 864 $status = "Not sent"; 865 break; 866 case "2": 867 $status = "Sent"; 868 break; 869 case "3": 870 $status = "Error"; 871 break; 872 } 873 ?> 874 <p class="form-field form-field-wide"> 875 <strong><?php _e("Order Id")?>:</strong> <?php echo $currentCRMId ?> 876 </p> 877 <p class="form-field form-field-wide"> 878 <strong><?php _e("Status")?>:</strong> <?php _e($status)?> 879 </p> 880 <?php 881 882 if($currentCRMId != "") { 883 ?> 884 <p class="form-field form-field-wide"> 885 <button type="button" data-order="<?php echo $order->get_id(); ?>" class="midwest-cancel-order-button button button-secondary"><?php _e("Cancel Order")?></button> 886 </p> 887 <?php 888 } else { 889 ?> 890 <p class="form-field form-field-wide"> 891 <button type="button" data-order="<?php echo $order->get_id(); ?>" class="midwest-send-order-button button button-secondary"><?php _e("Send Order")?></button> 892 </p> 893 <?php 715 894 } 716 895 } -
midwest-logistics/trunk/classes/class-ml-settings.php
r3008368 r3187953 28 28 add_settings_section( 29 29 'Midwest_Logistics_Midwest_Logistics_plugin_Page_section', 30 __( 'Settings for the ' . MIDWESTLOGISTICS_NAME . ' plugin', 'Midwest_Logistics' ),30 "", 31 31 array($this,'settings_section_callback'), 32 32 'Midwest_Logistics_plugin_Page' 33 33 ); 34 /*35 add_settings_field(36 'Midwest_Logistics_api_version',37 __( 'API Version:', 'Midwest_Logistics' ),38 array($this,'Midwest_Logistics_api_version_render'),39 'Midwest_Logistics_plugin_Page',40 'Midwest_Logistics_Midwest_Logistics_plugin_Page_section'41 );42 *43 */44 34 add_settings_field( 45 35 'Midwest_Logistics_text_field_0', … … 105 95 'Midwest_Logistics_plugin_Page', 106 96 'Midwest_Logistics_Midwest_Logistics_plugin_Page_section' 107 ); 97 ); 98 add_settings_field( 99 'Midwest_Logistics_tracking_order_count', 100 __( 'Order lookup batch count:', 'Midwest_Logistics' ), 101 array($this,'check_tracking_order_count'), 102 'Midwest_Logistics_plugin_Page', 103 'Midwest_Logistics_Midwest_Logistics_plugin_Page_section' 104 ); 105 add_settings_field( 106 'Midwest_Logistics_api_timeout_setting', 107 __( 'API Connection Timeout Seconds:', 'Midwest_Logistics' ), 108 array($this,'api_timeout_setting'), 109 'Midwest_Logistics_plugin_Page', 110 'Midwest_Logistics_Midwest_Logistics_plugin_Page_section' 111 ); 108 112 /* 109 113 * We decided to not atually let them choose since all the stock really does is update if Midwest adds stock otherwise Woocomerce reduces it when an order is placed. … … 283 287 <option value='180' <?php selected( $value, "180" ); ?>>180 Days</option> 284 288 </select> 289 <?php 290 } 291 public function check_tracking_order_count( ) { 292 $options = get_option( 'Midwest_Logistics_settings' ); 293 $value = "50"; 294 if(isset($options['Midwest_Logistics_tracking_order_count'])) { 295 $value = $options['Midwest_Logistics_tracking_order_count']; 296 } 297 if(empty($value)) { 298 $value = "50"; 299 } 300 $optionArray = ["5","10","15","20","25","30","35","40","45","50"]; 301 ?> 302 303 <select name='Midwest_Logistics_settings[Midwest_Logistics_tracking_order_count]'> 304 <?php 305 foreach($optionArray as $option ) { 306 ?><option value='<?php echo $option ?>' <?php selected( $value, $option ); ?>><?php echo $option ?></option><?php 307 } 308 ?> 309 </select> 310 <p>This option specifies how many orders are checked per hour for tracking updates. Orders are checked consecutively.</p> 311 <p>For best performance, this should be set as low as possible to check all orders in 24 hours</p> 312 <?php 313 } 314 public function api_timeout_setting( ) { 315 $options = get_option( 'Midwest_Logistics_settings' ); 316 $value = "60"; 317 if(isset($options['Midwest_Logistics_api_timeout_setting'])) { 318 $value = $options['Midwest_Logistics_api_timeout_setting']; 319 } 320 if(empty($value)) { 321 $value = "60"; 322 } 323 $optionArray = ["60","120","180","240","300"]; 324 ?> 325 326 <select name='Midwest_Logistics_settings[Midwest_Logistics_api_timeout_setting]'> 327 <?php 328 foreach($optionArray as $option ) { 329 ?><option value='<?php echo $option ?>' <?php selected( $value, $option ); ?>><?php echo $option ?></option><?php 330 } 331 ?> 332 </select> 333 <p>Default is 60 seconds. Do not change this setting unless requested by Midwest Logistics IT support.</p> 285 334 <?php 286 335 } -
midwest-logistics/trunk/classes/class-ml-stock.php
r3045832 r3187953 22 22 add_action( 'midwest_logistics_inventory_stock_update',array($this, 'get_inventory') ); 23 23 add_filter( 'woocommerce_product_data_store_cpt_get_products_query',array($this, 'handling_custom_meta_query_keys') , 10, 2 ); 24 25 add_action( 'add_meta_boxes',array($this, 'add_product_meta_box'),10,1 ); 26 add_action( 'wp_ajax_midwest_logistics_process_product_update_stock',array($this, 'admin_ajax_process_product_update_stock'),100 ); 24 27 } 25 28 public function get_SKUs() { … … 315 318 return $wp_query_args; 316 319 } 320 321 public function add_product_meta_box() { 322 323 add_meta_box( 324 'midwest_product_meta_box', // Unique ID 325 'Midwest Logistics', // Box title 326 array($this,'display_product_meta_box'), // Content callback 327 'product', // Post type 328 'side' 329 ); 330 331 } 332 public function display_product_meta_box($post) { 333 334 $product = wc_get_product($post); 335 if ( empty( $product ) ) { 336 return; 337 } 338 ?> 339 <p class="form-field form-field-wide"> 340 <p class="form-field form-field-wide"> 341 <strong><?php _e("Pull current inventory")?>:</strong> 342 </p> 343 <button type="button" data-product="<?php echo $product->get_id(); ?>" class="midwest-update-product-button button button-secondary"><?php _e("Pull Inventory")?></button> 344 </p> 345 <?php 346 347 } 348 349 350 public function admin_ajax_process_product_update_stock() { 351 352 $errormsg = ""; 353 $code = 200; 354 if(isset($_POST['pid'])) { 355 356 $postedProduct = $_POST['pid']; 357 if(!is_numeric($postedProduct)) { 358 echo json_encode($response); 359 exit(); 360 } 361 //get the list of skus to be updated. 362 $args = array( 363 'status' => 'publish', 364 'limit' => 1, 365 'include' => array((int) $postedProduct), 366 'type' => array('simple','variable'), 367 ); 368 369 $products = wc_get_products($args); 370 371 $skuArray = []; 372 if(count($products) > 0) { 373 foreach($products as $product) { 374 //$product->update_meta_data('_midwest_logistics_stock_updated', "Y" ); 375 //$product->save_meta_data(); 376 $updated = update_post_meta($product->get_id(),"_midwest_logistics_stock_updated","Y"); //using the Wordpress meta table becase that is where the prodcut meta is stored. 377 if ($product->is_type('variable')) { 378 $variations = $product->get_available_variations(); 379 foreach($variations as $variation) { 380 $variableProduct = wc_get_product($variation["variation_id"]); 381 if($variableProduct != null) { 382 383 $id = $variableProduct->get_id(); 384 $midwestSKU = $variableProduct->get_meta($this->metaKeySKU); 385 if($midwestSKU != "") { 386 array_push($skuArray, array( 387 "post_id" => $id, 388 "midwestSKU" => $midwestSKU, 389 "parent_id" => $variableProduct->get_parent_id() 390 )); 391 } 392 } 393 } 394 395 } else { 396 $id = $product->get_id(); 397 $midwestSKU = $product->get_meta($this->metaKeySKU); 398 if($midwestSKU != "") { 399 array_push($skuArray,array( 400 "post_id" => $id, 401 "midwestSKU" => $midwestSKU, 402 "parent_id" => $id 403 )); 404 } 405 406 } 407 } 408 } 409 $skus = false; 410 $skusArray = array(); 411 $skusJSONArray = array(); 412 413 if(count($skuArray) > 0) { 414 foreach ($skuArray as $singleSKU) { 415 $skus .= $singleSKU["midwestSKU"] . ","; 416 $skusJSONArray[] = $singleSKU["midwestSKU"]; 417 $skusArray[$singleSKU["midwestSKU"]] = array("id"=>$singleSKU["post_id"]); 418 419 //Set the product as checked since we are sending it. 420 $productId = $singleSKU["post_id"]; 421 $parentId = $singleSKU["parent_id"]; 422 $product = wc_get_product($parentId); 423 } 424 } 425 426 $apiKey = ""; 427 $settingOptions = get_option('Midwest_Logistics_settings',''); 428 if($settingOptions !== "") { 429 $apiKey = $settingOptions["Midwest_Logistics_API_Key_field_0"]; 430 } 431 432 433 if($skus != false) { 434 $skus = substr($skus, 0, -1); 435 $jsonArray = [ 436 "apiKey" => $apiKey, 437 "sku" => $skusJSONArray, 438 "request" => "productcheckbylist" 439 ]; 440 441 $API = new ML_API(); 442 443 $httpcode = "500"; 444 $postString = json_encode ($jsonArray); 445 446 $response = $API->send($postString); 447 448 if($response != null) { 449 $httpcode = $response["code"]; 450 $response = $response["response"]; 451 } 452 if($httpcode == "200") { 453 454 if(json_decode($response,true) !== null) { 455 $jsonResponse = json_decode($response,true); 456 $curl_result = $jsonResponse["result"]; 457 $products = $jsonResponse["products"]; 458 459 if(is_array($products)) { 460 foreach($products as $product) { 461 $stockAmount = $product["stock"]; 462 $inStock = $product["instock"]; 463 $sku = $product["sku"]; 464 $result = $product["result"]; 465 $message = $product["message"]; 466 467 if($result == 500) { 468 $code = 500; 469 $errormsg = $errormsg . "SKU: " .$sku . " is Invalid\n"; 470 } 471 if(is_numeric($stockAmount) ) { 472 if(isset($skusArray[$sku])) { 473 $productId = $skusArray[$sku]["id"]; 474 475 //Update the product. If it a variation thats okay. 476 $currentProduct = wc_get_product($productId); 477 if($currentProduct != null) { 478 wc_update_product_stock($currentProduct,$stockAmount,'set',false); //It updates later on. 479 } 480 481 $responseText = array( 482 "result" => "200", 483 "response" => true, 484 "message" => "Product Stock Updated Manually", 485 "stock" => $stockAmount, 486 "instock" => $inStock, 487 ); 488 489 490 midwest_logistics_add_communication_log($postString,json_encode($responseText),$productId,"product","stock_update", json_encode($responseText)); 491 492 } 493 } 494 } 495 } 496 } 497 } 498 499 if($httpcode == "500") { 500 new WP_Error( MIDWESTLOGISTICS_NAME . ' API',MIDWESTLOGISTICS_NAME . " API is down." ); 501 } 502 } 503 if($errormsg != "") { 504 $errormsg = "Errors occured while updating inventory. Please review and fix the following error(s)\n" . $errormsg; 505 } 506 $response = array("code"=>$code,"message"=>$errormsg); 507 } 508 509 echo json_encode($response); 510 exit(); 511 } 317 512 private function reset() { 318 513 $args = array( … … 346 541 } 347 542 } 348 349 350 351 543 } -
midwest-logistics/trunk/classes/class-ml-usps-shipping.php
r2529939 r3187953 2 2 if(class_exists("WC_Shipping_USPS")) { 3 3 class ML_USPS_Shipping extends WC_Shipping_USPS { 4 p rivate$flat_rate_boxes;5 p rivate$services;4 public $flat_rate_boxes; 5 public $services; 6 6 function __construct( $instance_id = 0 ) { 7 7 parent::__construct($instance_id); -
midwest-logistics/trunk/classes/class-wc-ml-shipping-method.php
r2632724 r3187953 356 356 357 357 function ML_add_your_shipping_method( $methods ) { 358 $methods['WC_ML_Shipping_Method'] = 'WC_ML_Shipping_Method'; 358 global $pagenow; 359 if ( $pagenow == 'admin.php' && $_GET['page'] == "wc-settings" && $_GET['tab'] == "shipping") { 360 $methods['WC_ML_Shipping_Method'] = 'WC_ML_Shipping_Method'; 361 } 359 362 return $methods; 360 363 } -
midwest-logistics/trunk/inc/productFunctions.php
r3045832 r3187953 214 214 215 215 $responseText = ""; 216 217 216 $responseArray = array("result" => "500", "message" => "No response from API"); 218 217 if($httpcode == "200") { 219 218 if(json_decode($response) !== null) { 220 219 $jsonResponse = json_decode($response); 221 222 $curl_result = $jsonResponse -> {"result"}; 223 224 if($curl_result === "200") { 225 $responseText = $jsonResponse -> {"message"}; 226 $responseArray = array("result" => true, "message" => $jsonResponse -> {"message"}); 227 } else { 228 $responseText = $jsonResponse -> {"message"}; 229 $responseArray = array("result" => false, "message" => $jsonResponse -> {"message"}); 230 231 } 220 $curl_result = $jsonResponse -> {"result"}; 221 $responseText = $jsonResponse -> {"message"}; 222 $responseArray = array("result" => $curl_result, "message" => $jsonResponse -> {"message"}); 232 223 } else { 233 224 new WP_Error( MIDWESTLOGISTICS_NAME . ' API',"Invalid Call" ); … … 242 233 $responseArray = array("result" => false, "message" => MIDWESTLOGISTICS_NAME . " API is down."); 243 234 } 235 236 $logResponse = json_encode( 237 array( 238 "request" => "productcheck", 239 "response" => $responseArray 240 ) 241 ); 244 242 245 243 //add the log 246 midwest_logistics_add_communication_log($postString,$ response,get_the_ID(),"product",get_the_title(),$responseText);244 midwest_logistics_add_communication_log($postString,$logResponse,get_the_ID(),"product",get_the_title(),$responseText); 247 245 return $responseArray; 248 246 } … … 270 268 if(is_array($responseArray)) { 271 269 272 if($responseArray["result"] === false) {270 if($responseArray["result"] === "500") { 273 271 274 272 if($responseArray["message"] == "The API key is invalid") { 275 273 ?> 276 274 <div class="notice-error notice is-dismissible"> 277 <p><strong><?php _e( "Your ". MIDWESTLOGISTICS_NAME . " API Key is invalid.",MIDWESTLOGISTICS_NAME); ?></strong></p>275 <p><strong><?php _e( "Your ". MIDWESTLOGISTICS_NAME . " API Key is invalid.",MIDWESTLOGISTICS_NAME); ?></strong></p> 278 276 </div> 279 277 <?php … … 281 279 ?> 282 280 <div class="notice-error notice is-dismissible"> 283 <p><strong><?php _e( "The ". MIDWESTLOGISTICS_NAME . " product SKU you entered is not valid for product: " . get_the_title(),MIDWESTLOGISTICS_NAME); ?></strong></p>281 <p><strong><?php _e( "The ". MIDWESTLOGISTICS_NAME . " product SKU you entered is not valid for product: " . get_the_title(),MIDWESTLOGISTICS_NAME); ?></strong></p> 284 282 </div> 285 283 <?php … … 313 311 if(is_array($responseArray)) { 314 312 315 if($responseArray["result"] === false) {313 if($responseArray["result"] === "500") { 316 314 if($responseArray["message"] == "The API key is invalid") { 317 315 ?> -
midwest-logistics/trunk/inc/trackingFunctions.php
r3008368 r3187953 40 40 } 41 41 42 /* Original SQL statement 43 $sql = "SELECT distinct t1.order_id,t4.meta_value as CRMID 44 FROM $table_name t1 45 JOIN $order_meta_table_name t2 on t2.order_item_id = t1.order_item_id 46 JOIN $order_table_name t3 on t3.id = t1.order_id 47 JOIN $order_table_meta_name t4 on t4.post_id = t3.id 48 WHERE post_type = 'shop_order' 49 AND t2.meta_key = '" . $woocommerce_tracking_number_meta_field . "' 50 AND t4.meta_key= '_midwest_logistics_CRM_order_id' 51 AND t2.meta_value = '' 52 AND post_status <> 'trash' 53 AND ( 54 t4.meta_value <> '0' 55 OR t4.meta_value <> '' 56 ) 57 AND ( 58 SELECT wppostmeta2.meta_value 59 FROM $order_table_meta_name wppostmeta2 60 WHERE wppostmeta2.meta_key = '_midwest_logistics_processed' 61 AND wppostmeta2.post_id = t4.post_id 62 LIMIT 1 63 ) IS NULL 64 AND DATEDIFF(NOW(),t3.post_date) < ". $dayLimit . " 65 ORDER BY t1.order_id DESC 66 LIMIT 1000"; 67 */ 42 $orderLimit = "50"; 43 if(isset($options['Midwest_Logistics_tracking_order_count'])) { 44 $orderLimit = $options['Midwest_Logistics_tracking_order_count']; 45 } 46 47 if(!is_numeric($orderLimit) || empty($orderLimit)) { 48 $orderLimit = "50"; 49 } 50 68 51 $date = date_create(date('Y-m-d H:i:s')); 69 52 $startDate = $date->sub(new DateInterval('P' . $dayLimit . 'D')); … … 73 56 //For now I check it as well before adding it to the list. 74 57 $args = array( 75 'limit'=> 1000,58 'limit'=> $orderLimit, 76 59 'type'=> 'shop_order', 77 60 'date_created'=> '>' .$startDate->format('Y-m-d H:i:s'), … … 389 372 } 390 373 391 add_action( 'init', 'mw_tracking_manual_run' );374 //add_action( 'init', 'mw_tracking_manual_run' ); 392 375 function mw_tracking_manual_run() { 393 $run_mw_tracking = filter_input( INPUT_GET, 'run_mw_tracking', FILTER_SANITIZE_URL ); 394 if(isset($run_mw_tracking)) { 395 if($run_mw_tracking == "Y") { 396 midwest_logistics_update_tracking_information(); 397 376 if(is_admin()) { 377 $run_mw_tracking = filter_input( INPUT_GET, 'run_mw_tracking', FILTER_SANITIZE_URL ); 378 if(isset($run_mw_tracking)) { 379 if($run_mw_tracking == "Y") { 380 midwest_logistics_update_tracking_information(); 381 } 398 382 } 399 383 } -
midwest-logistics/trunk/midwest-wholesale.php
r3045832 r3187953 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.2 56 * Version: 1.1.26 7 7 * WC requires at least: 6.0.0 8 * WC tested up to: 8.2.08 * WC tested up to: 9.3.3 9 9 * Author: Skynet Solutions Inc. 10 10 * Author URI: http://www.skynet-solutions.net/ … … 56 56 } 57 57 if ( !defined( 'MIDWESTLOGISTICS_SHIPPING_DEFAULT' ) ) { 58 define( 'MIDWESTLOGISTICS_SHIPPING_DEFAULT', ' 5');58 define( 'MIDWESTLOGISTICS_SHIPPING_DEFAULT', '100000045'); 59 59 } 60 60 if ( !defined( 'MIDWESTLOGISTICS_VALID' ) ) { -
midwest-logistics/trunk/readme.txt
r3045832 r3187953 3 3 Tags: Midwest Logistics, Distribution, Shipping 4 4 Requires at least: 5.0 5 Tested up to: 6. 4.15 Tested up to: 6.6.2 6 6 Requires PHP: 7.0 7 Stable tag: 1.1.2 57 Stable tag: 1.1.26 8 8 License: GPLv3 9 9 … … 75 75 76 76 == Changelog == 77 = 1.1.25 (2024-03-11) = 78 * Add - added ability to manage Midwest Logistics order. Customers can now manually submit the order and cancel the order. 79 77 80 = 1.1.25 (2024-02-21) = 78 81 * Update - updated stock to improve stock checking for new products or existing products when a customer first installs the plugin. -
midwest-logistics/trunk/scripts/admin.js
r2481617 r3187953 24 24 25 25 } 26 MW_bindElements(); 26 27 27 28 //communication sort tables … … 43 44 44 45 }); 46 function MW_bindElements() { 47 jQuery(".midwest-cancel-order-button").on("click",function() { 48 button = this; 49 currentText = this.innerHTML; 50 button.innerHTML = "Processing..."; 51 button.disabled = true; 52 orderId = this.getAttribute("data-order"); 53 jQuery.ajax({ 54 type: "POST", 55 url: ajaxurl, 56 data: { 57 action: 'midwest_logistics_cancel_shop_order' , 58 order: orderId 59 } 60 }).done(function( response ) { 61 JsonOB = JSON.parse(response); 62 code = JsonOB.code; 63 message = JsonOB.message; 64 if(code === 500) { 65 alert(message); 66 button.innerHTML = currentText; 67 button.disabled = false; 68 } else { 69 window.location = window.location; 70 } 71 72 }); 73 74 75 }); 76 jQuery(".midwest-send-order-button").on("click",function() { 77 button = this; 78 currentText = this.innerHTML; 79 button.innerHTML = "Processing..."; 80 button.disabled = true; 81 orderId = this.getAttribute("data-order"); 82 jQuery.ajax({ 83 type: "POST", 84 url: ajaxurl, 85 data: { 86 action: 'midwest_logistics_process_shop_order' , 87 order: orderId 88 } 89 }).done(function( response ) { 90 JsonOB = JSON.parse(response); 91 code = JsonOB.code; 92 message = JsonOB.message; 93 if(code === 500) { 94 alert(message); 95 button.innerHTML = currentText; 96 button.disabled = false; 97 } 98 window.location = window.location; 99 100 }); 101 102 103 }); 104 jQuery(".midwest-update-product-button").on("click",function() { 105 button = this; 106 currentText = this.innerHTML; 107 button.innerHTML = "Processing..."; 108 button.disabled = true; 109 productid = this.getAttribute("data-product"); 110 jQuery.ajax({ 111 type: "POST", 112 url: ajaxurl, 113 data: { 114 action: 'midwest_logistics_process_product_update_stock' , 115 pid: productid 116 } 117 }).done(function( response ) { 118 JsonOB = JSON.parse(response); 119 code = JsonOB.code; 120 message = JsonOB.message; 121 if(code === 500) { 122 alert(message); 123 button.innerHTML = currentText; 124 button.disabled = false; 125 } else { 126 button.disabled = false; 127 button.innerHTML = "Inventory Updated!"; 128 button.style.backgroundColor = "#28a745"; 129 button.style.color = "#fff"; 130 setTimeout(function() { 131 if (window.location.hash) { 132 window.location.href = window.location.href.split('#')[0]; 133 } else { 134 window.location.reload(); 135 } 136 },1000); 137 } 138 139 }); 140 141 142 }); 143 } 45 144 46 145 function replaceUrlParam(url, paramName, paramValue) {
Note: See TracChangeset
for help on using the changeset viewer.