| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class WC_Settings_Routeapp_Order_Recover file. |
| 4 |
* |
| 5 |
* @package Routeapp\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! class_exists( 'WC_Settings_Routeapp_Order_Recover' ) ) : |
| 13 |
|
| 14 |
class WC_Settings_Routeapp_Order_Recover extends WC_Settings_Page { |
| 15 |
|
| 16 |
public function __construct() { |
| 17 |
$this->id = 'routeapp_order_recover'; |
| 18 |
$this->label = __( 'Route Orders Sync', 'routeapp' ); |
| 19 |
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
| 20 |
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); |
| 21 |
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); |
| 22 |
} |
| 23 |
|
| 24 |
public static function get_route_public_instance(){ |
| 25 |
global $routeapp_public; |
| 26 |
return $routeapp_public; |
| 27 |
} |
| 28 |
|
| 29 |
public function get_settings() { |
| 30 |
|
| 31 |
$settings = apply_filters( 'routeapp_order_recover_settings', array( |
| 32 |
array( |
| 33 |
'name' => __( 'Route - Orders Sync', 'routeapp_order_recover' ), |
| 34 |
'type' => 'title', |
| 35 |
'desc' => '', |
| 36 |
'id' => 'routeapp_route_insurance_order_recover', |
| 37 |
), |
| 38 |
array( |
| 39 |
'name' => __( 'From', 'routeapp' ), |
| 40 |
'type' => 'text', |
| 41 |
'desc' => "Select starting date for triggering the order reconcile", |
| 42 |
'id' => 'routeapp_order_recover_from', |
| 43 |
'class' => 'route-datepicker', |
| 44 |
), |
| 45 |
array( |
| 46 |
'name' => __( 'To', 'routeapp' ), |
| 47 |
'type' => 'text', |
| 48 |
'desc' => "Select ending date for triggering the order reconcile", |
| 49 |
'id' => 'routeapp_order_recover_to', |
| 50 |
'class' => 'route-datepicker', |
| 51 |
), |
| 52 |
array( |
| 53 |
'name' => __( 'Reconcile existing orders', 'routeapp' ), |
| 54 |
'type' => 'checkbox', |
| 55 |
'desc' => __( 'When enabled, will update Route Charge and Route Protection on Orders section', 'routeapp'), |
| 56 |
'id' => 'routeapp_order_recover_reconcile_backend', |
| 57 |
'default' => 'no' |
| 58 |
), |
| 59 |
array( |
| 60 |
'name' => __( 'Sync tracking numbers', 'routeapp' ), |
| 61 |
'type' => 'checkbox', |
| 62 |
'desc' => __( 'When enabled, will read tracking from supported providers and sync shipments to Route for each order in the date range', 'routeapp'), |
| 63 |
'id' => 'routeapp_order_recover_sync_tracking', |
| 64 |
'default' => 'no' |
| 65 |
), |
| 66 |
array( |
| 67 |
'type' => 'sectionend', |
| 68 |
'id' => 'route_insurance_order_recover' |
| 69 |
), |
| 70 |
) ); |
| 71 |
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
public function output() { |
| 76 |
wp_enqueue_style('route-order-sync-spinner-css', plugin_dir_url(dirname(__FILE__)) . 'public/css/jquery-spinner.min.css', array(), 1, false); |
| 77 |
wp_enqueue_script('route-order-sync-spinner', plugin_dir_url(dirname(__FILE__)) . 'public/js/jquery-spinner.min.js', array('jquery'), 1, false); |
| 78 |
wp_enqueue_script('jquery-ui-datepicker'); |
| 79 |
wp_enqueue_script('route-order-sync-custom', plugin_dir_url(dirname(__FILE__)) . 'public/js/routeapp-order-sync.js', array('jquery'), 1, true); |
| 80 |
|
| 81 |
// Localize the script with new data |
| 82 |
wp_localize_script('route-order-sync-custom', 'routeapp_ajax', array( |
| 83 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 84 |
'nonce' => wp_create_nonce('routeapp_order_recover_nonce') // Optional: Add a nonce for security |
| 85 |
)); |
| 86 |
|
| 87 |
$settings = $this->get_settings(); |
| 88 |
WC_Admin_Settings::output_fields( $settings ); |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Save function to handle the processing of orders based on specified date range and batch size. |
| 94 |
* This function processes orders in batches to avoid timeouts and server overload. |
| 95 |
* It checks if the necessary POST parameters are set, fetches the orders in batches, |
| 96 |
* processes each batch, and updates the order count accordingly. |
| 97 |
*/ |
| 98 |
public function save() { |
| 99 |
$settings = $this->get_settings(); |
| 100 |
|
| 101 |
WC_Admin_Settings::save_fields($settings); |
| 102 |
} |
| 103 |
|
| 104 |
} |
| 105 |
endif; |
| 106 |
|