Files
old-new-wiaas/backend/app/plugins/wiaas/includes/admin/delivery-process/class-wiaas-admin-delivery-process-flow.php

86 lines
2.2 KiB
PHP
Raw Normal View History

2018-10-21 16:39:58 +02:00
<?php
class Wiaas_Admin_Order_Process_Flow {
public static function init() {
2018-11-29 11:13:15 +01:00
add_action( 'admin_menu', array(__CLASS__, 'add_delivery_process_page') );
2018-11-29 11:13:15 +01:00
add_action( 'gravityflow_entry_detail', array( __CLASS__, 'display_process_steps_details' ), 10, 3 );
2018-10-21 16:39:58 +02:00
}
2018-11-29 11:13:15 +01:00
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')
);
}
2018-11-29 11:13:15 +01:00
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;
}
2018-11-29 11:13:15 +01:00
$order = wc_get_order($order_id);
2018-11-29 11:13:15 +01:00
if ( !$order ) {
return;
}
2018-11-29 11:13:15 +01:00
$delivery_process = Wiaas_Delivery_Process::get_order_delivery_process_entry($order->get_id());
2018-11-29 11:13:15 +01:00
if ($delivery_process &&
wp_verify_nonce($_POST['wiaas_delivery_process_navigation_nonce'], 'wiaas_delivery_process_navigation') &&
GFAPI::current_user_can_any( 'manage_wiaas_order_delivery_process' )) {
2018-11-29 11:13:15 +01:00
self::_maybe_process_admin_step_change_action($delivery_process);
2018-11-03 05:15:38 +01:00
2018-11-29 11:13:15 +01:00
// refresh order
$order = wc_get_order($order_id);
}
2018-11-03 05:15:38 +01:00
2018-11-29 11:13:15 +01:00
require 'views/html-admin-delivery-process-page.php';
}
2018-11-03 05:15:38 +01:00
2018-11-29 11:13:15 +01:00
private static function _maybe_process_admin_step_change_action($entry) {
$admin_action = rgpost( 'wiaas_delivery_process_navigation_action' );
if ($admin_action === 'complete') {
2018-11-29 11:13:15 +01:00
$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;
2018-11-29 11:13:15 +01:00
$api = new Gravity_Flow_API( $entry['form_id'] );
$api->send_to_step( $entry, $step_id );
}
2018-10-21 16:39:58 +02:00
}
2018-10-21 16:39:58 +02:00
}
Wiaas_Admin_Order_Process_Flow::init();