86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
|
|
class Wiaas_Admin_Order_Process_Flow {
|
|
|
|
public static function init() {
|
|
|
|
add_action( 'admin_menu', array(__CLASS__, 'add_delivery_process_page') );
|
|
|
|
add_action( 'gravityflow_entry_detail', array( __CLASS__, 'display_process_steps_details' ), 10, 3 );
|
|
}
|
|
|
|
public static function add_delivery_process_page() {
|
|
add_submenu_page(
|
|
'edit.php?post_type=shop_order',
|
|
__( 'Order Delivery', 'wiaas' ),
|
|
null,
|
|
'read',
|
|
'wiaas-order-delivery',
|
|
array(__CLASS__, 'output_delivery_process')
|
|
);
|
|
}
|
|
|
|
public static function output_delivery_process() {
|
|
$order_id = absint( $_GET['id'] );
|
|
|
|
$has_access = Wiaas_Access_Management::can_current_user_read_order($order_id);
|
|
|
|
if (! $has_access) {
|
|
|
|
echo "<h2>You don't have permission to view this order.</h2>";
|
|
|
|
return;
|
|
}
|
|
|
|
$order = wc_get_order($order_id);
|
|
|
|
if ( !$order ) {
|
|
return;
|
|
}
|
|
|
|
$delivery_process = Wiaas_Delivery_Process::get_order_delivery_process_entry($order->get_id());
|
|
|
|
if ($delivery_process &&
|
|
wp_verify_nonce($_POST['wiaas_delivery_process_navigation_nonce'], 'wiaas_delivery_process_navigation') &&
|
|
GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' )) {
|
|
|
|
self::_maybe_process_admin_step_change_action($delivery_process);
|
|
|
|
// refresh order
|
|
$order = wc_get_order($order_id);
|
|
}
|
|
|
|
require 'views/html-admin-delivery-process-page.php';
|
|
}
|
|
|
|
private static function _maybe_process_admin_step_change_action($entry) {
|
|
|
|
$admin_action = rgpost( 'wiaas_delivery_process_navigation_action' );
|
|
|
|
if ($admin_action === 'complete') {
|
|
|
|
$api = new Gravity_Flow_API( $entry['form_id'] );
|
|
|
|
$current_step = $api->get_current_step($entry);
|
|
|
|
if ( $current_step ) {
|
|
$current_step->purge_assignees();
|
|
$current_step->update_step_status( 'complete' );
|
|
}
|
|
|
|
$api->process_workflow($entry['id']);
|
|
}
|
|
|
|
list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 );
|
|
|
|
if ( $base_admin_action == 'send_to_step' ) {
|
|
$step_id = $action_id;
|
|
$api = new Gravity_Flow_API( $entry['form_id'] );
|
|
$api->send_to_step( $entry, $step_id );
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
Wiaas_Admin_Order_Process_Flow::init();
|