From 69c74d93404dc718a0a1600eef8d5de435b2cbf7 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Sun, 21 Oct 2018 16:39:58 +0200 Subject: [PATCH] order delivery process --- ...ass-wiaas-admin-order-delivery-process.php | 11 ++++ ...iaas-admin-order-delivery-process-flow.php | 60 +++++++++++++++++ .../views/html-order-process-flow.php | 65 +++++++++++++++++++ .../html-order-select-delivery-process.php | 62 ++++++++++++++++++ .../wiaas/includes/class-wiaas-admin.php | 2 + .../includes/class-wiaas-delivery-process.php | 33 ++++++++-- 6 files changed, 226 insertions(+), 7 deletions(-) create mode 100644 backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-order-delivery-process.php create mode 100644 backend/app/plugins/wiaas/includes/admin/delivery-process/class-wiaas-admin-order-delivery-process-flow.php create mode 100644 backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-process-flow.php create mode 100644 backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-select-delivery-process.php diff --git a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-order-delivery-process.php b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-order-delivery-process.php new file mode 100644 index 0000000..3648dae --- /dev/null +++ b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-order-delivery-process.php @@ -0,0 +1,11 @@ +ID; + + $process = Wiaas_Delivery_Process::get_order_delivery_process($order_id); + + if ($process === NULL){ + $list_of_delivery_processes = Wiaas_Delivery_Process::get_available_delivery_processes(); + require 'views/html-order-select-delivery-process.php'; + }else{ + $title = $process['name']; + $steps = $process['steps']; + + require 'views/html-order-process-flow.php'; + } + + } + + public static function add_delivery_dates_meta_box(){ + // global $post; + + // $order_id = $post->ID; + + // $suppliers = Wiaas_Order::get_suppliers($order_id); + + // require 'views/html-order-delivery-dates.php'; + + } +} + +Wiaas_Admin_Order_Process_Flow::init(); \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-process-flow.php b/backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-process-flow.php new file mode 100644 index 0000000..b0b31ec --- /dev/null +++ b/backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-process-flow.php @@ -0,0 +1,65 @@ + + + + +
+

+
+ $step){ + $count = $index + 1; + echo ''; + echo '
'; + echo $step['full_desc']; + echo '
'; + } + ?> +
+ + \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-select-delivery-process.php b/backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-select-delivery-process.php new file mode 100644 index 0000000..48cedc8 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/admin/delivery-process/views/html-order-select-delivery-process.php @@ -0,0 +1,62 @@ + + + + +
+

Please select a process for the order:

+
+ $process){ + echo ''; + } + ?> +
+ + \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-admin.php b/backend/app/plugins/wiaas/includes/class-wiaas-admin.php index 497a74b..67bcd13 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-admin.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-admin.php @@ -20,6 +20,8 @@ class Wiaas_Admin { require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php'; // Admin organization interface require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php'; + // Admin order delivery process + require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-delivery-process.php'; require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php'; diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php index 34b58c3..328a2d0 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-delivery-process.php @@ -19,8 +19,6 @@ class Wiaas_Delivery_Process { } private static function _init_hooks() { - add_action('woocommerce_new_order', array( __CLASS__, 'create_delivery_process_for_order' )); - add_filter( 'gform_entry_meta', array(__CLASS__, 'extend_gravity_form_entry_meta'), 10, 2 ); add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_process_step'), 5, 3 ); @@ -80,7 +78,25 @@ class Wiaas_Delivery_Process { $order = wc_get_order($order_id); $order->update_status('completed', 'Completed order delivery process.', true); } - } + } + + /** + * List available delivery processes + * + * @return array + */ + public static function get_available_delivery_processes(){ + $forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true ); + $result = array(); + foreach($forms as $form){ + $result[] = array( + 'title' => str_replace(self::$process_form_title_prefix, '', $form->title), + 'id' => $form->id + ); + } + + return $result; + } /** * Retrieves delivery process instance for order @@ -92,7 +108,7 @@ class Wiaas_Delivery_Process { public static function get_order_delivery_process($order_id) { $process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id'); - if (!isset($process_entry_id)) { + if (empty($process_entry_id)) { return null; } @@ -132,13 +148,13 @@ class Wiaas_Delivery_Process { } /** - * Automatically create delivery process instance when order is created + * create delivery process instance * @param $order_id */ - public static function create_delivery_process_for_order($order_id) { + public static function create_delivery_process_for_order($order_id, $form_id) { $process_form = null; $forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true ); - $process_form = $forms[0]; + $process_form = GFFormsModel::get_form($form_id); if(isset($process_form)) { $order = wc_get_order( $order_id ); $new_process_entry = array( @@ -150,7 +166,10 @@ class Wiaas_Delivery_Process { add_post_meta($order_id, 'wiaas_delivery_process_id', $process_form->id); add_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id); + + return true; } + return false; } /**