From 8d4f75cc41fb83ade3f141338104b07b192d38b7 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Sat, 3 Nov 2018 11:15:52 +0100 Subject: [PATCH] Handle process navigation better --- .../css/wiaas-admin-delivery-process.css | 10 ++ .../assets/js/wiaas-admin-delivery-process.js | 8 ++ .../class-wiaas-admin-delivery-process.php | 111 +++++++++++++----- .../wiaas/includes/class-wiaas-cart.php | 29 ++++- .../class-wiaas-delivery-process-step.php | 2 +- .../product/class-wiaas-product-supplier.php | 17 ++- .../user/wiaas-organization-functions.php | 27 +++++ .../process/ValidateQuestionnaireItem.jsx | 2 +- 8 files changed, 168 insertions(+), 38 deletions(-) create mode 100644 backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css create mode 100644 backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js diff --git a/backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css b/backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css new file mode 100644 index 0000000..430216a --- /dev/null +++ b/backend/app/plugins/wiaas/assets/css/wiaas-admin-delivery-process.css @@ -0,0 +1,10 @@ +.wiaas_delivery_step_nav { + + + +} + + +.gravityflow_workflow_detail #postbox-container-1 > div:nth-child(2) { + display: none; +} diff --git a/backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js b/backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js new file mode 100644 index 0000000..10341bb --- /dev/null +++ b/backend/app/plugins/wiaas/assets/js/wiaas-admin-delivery-process.js @@ -0,0 +1,8 @@ +jQuery(document).ready(function ($) { + $('.wiaas_delivery_step_nav').click(function (e) { + var action = $(this).data('step'); + + $('#wiaas_delivery_process_navigation_action').val(action); + + }); +}); diff --git a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php index 512a03e..caf1120 100644 --- a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php +++ b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php @@ -8,14 +8,26 @@ class Wiaas_Admin_Delivery_Process { add_action( 'gravityflow_title_entry_detail', array( __CLASS__, 'process_title' ), 10, 3 ); - add_action('add_meta_boxes', array(__CLASS__, 'add_delivery_process_metabox'), 100); add_action( 'wp_ajax_wiaas_create_order_delivery_process', array(__CLASS__, 'wiaas_ajax_create_order_delivery_process') ); - add_filter('gravityflow_admin_actions_workflow_detail', array (__CLASS__, 'filter_process_send_to_step_options'), 10, 5); + add_action('gravityflow_entry_detail', array(__CLASS__, 'maybe_display_delivery_process_navigation'), 9, 3); + + add_filter('gravityflow_admin_action_feedback', array(__CLASS__, 'maybe_process_admin_step_change_action'), 10, 4); + + add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 ); } + public static function enqueue_scripts() { + + $plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) ); + + wp_enqueue_script( 'wiaas_admin_delivery_process', $plugin_url . '/assets/js/wiaas-admin-delivery-process.js' ); + wp_enqueue_style( 'wiaas_admin_delivery_process', $plugin_url . '/assets/css/wiaas-admin-delivery-process.css' ); + } + + public static function add_delivery_process_metabox() { add_meta_box( @@ -29,45 +41,84 @@ class Wiaas_Admin_Delivery_Process { } - public static function filter_process_send_to_step_options($admin_actions, $current_step, $steps, $form, $entry) { + public static function maybe_process_admin_step_change_action($feedback, $admin_action, $form, $entry) { - $delivery_process_actions = array(); + $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' ); - if ( $current_step ) { + list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 ); - $previous_step_id = null; - // get previous step id for current step - foreach ($steps as $index => $step) { + if ( $base_admin_action == 'send_to_step' ) { + $step_id = $action_id; + $api = new Gravity_Flow_API( $form['id'] ); + $api->send_to_step( $entry, $step_id ); + $entry = GFAPI::get_entry( $entry['id'] ); + $new_step = $api->get_current_step( $entry ); + $feedback = $new_step ? + sprintf( esc_html__( 'Sent to step: %s', 'wiaas' ), $new_step->get_name() ) : + esc_html__( 'Workflow Complete', 'wiaas' ); + } - $next_step = gravity_flow()->get_next_step($step, $entry, $form); + return $feedback; + } - if ($next_step && $next_step->get_id() === $current_step->get_id()) { - $previous_step_id = $step->get_id(); - } - } + public static function maybe_display_delivery_process_navigation($form, $entry, $current_step) { - if (! empty($previous_step_id)) { + if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) || empty( $current_step ) ) { + return; + } - $delivery_process_actions[] = array( - 'label' => esc_html__( 'Previous step', 'wiaas' ), - 'value' => 'send_to_step|' . $previous_step_id - ); - } + $steps = gravity_flow()->get_steps($form['id'], $entry); - // get next step id for current step - $next_step = gravity_flow()->get_next_step($current_step, $entry, $form); - if ($next_step) { + // get next step id + $next_step = gravity_flow()->get_next_step($current_step, $entry, $form); + $next_step_id = empty($next_step) ? null : $next_step->get_id(); - $delivery_process_actions[] = array( - 'label' => esc_html__( 'Next step', 'wiaas' ), - 'value' => 'send_to_step|' . $next_step->get_id() - ); - } - } + // get previous step id + foreach ($steps as $step) { - return $delivery_process_actions; - } + $next = gravity_flow()->get_next_step($step, $entry, $form); + if ($next && $next->get_id() === $current_step->get_id()) { + $previous_step = $step; + } + } + $previous_step_id = empty($previous_step) ? null : $previous_step->get_id(); + + // bail out if none exist + if ( empty($next_step_id) && empty($previous_step_id) ) { + + return; + } + + /** + * @reference Gravity_Flow::maybe_process_admin_action for used field names + * which are being checked there + * + */ + + ?> + +
+ + + + + + class="button wiaas_delivery_step_nav" + style="float:right; margin-left: 20px;" value="NEXT STEP"> + + + class="button wiaas_delivery_step_nav" + style="float:right;" value="PREV STEP"> +
+ add_meta_data( '_wiaas_documents', $item_documents, true ); } + // save simple product information that needs to be avaialable later on + // even if this data is changed or removed from product at that time + $simple_product_meta = array(); + if(wc_pb_is_bundled_cart_item($cart_item)) { + + $product = $cart_item['data']; + + $simple_product_meta['_wiaas_category'] = Wiaas_Product_Category::get_category($product); + $simple_product_meta['_wiaas_price'] = $product->get_price(); + $simple_product_meta['_wiaas_manufacturer_product_no'] = $product->get_meta('_manufacturer_product_no'); + $simple_product_meta['_wiaas_supplier_product_no'] = $product->get_meta('_supplier_product_no'); + // get supplier + if ($supplier_organization_id = Wiaas_Product_Supplier::get_supplier_organisation_id_from_product($product->get_id())) { + $info = wiaas_get_organization_info($supplier_organization_id); + + $simple_product_meta['_wiaas_supplier_info'] = $info; + } + + + } + return $order_item; } diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php index bc6b668..5c15849 100644 --- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php +++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php @@ -94,7 +94,7 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step { public function update_step_status($status = false) { - if ($status === 'cancelled' && $admin_action = rgpost( 'gravityflow_admin_action' )) { + if ($status === 'cancelled' && $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' )) { list( $base_admin_action, $step_id ) = rgexplode( '|', $admin_action, 2 ); diff --git a/backend/app/plugins/wiaas/includes/product/class-wiaas-product-supplier.php b/backend/app/plugins/wiaas/includes/product/class-wiaas-product-supplier.php index 6d25327..5982a13 100644 --- a/backend/app/plugins/wiaas/includes/product/class-wiaas-product-supplier.php +++ b/backend/app/plugins/wiaas/includes/product/class-wiaas-product-supplier.php @@ -68,15 +68,24 @@ class Wiaas_Product_Supplier { * Retrieve organisation id of the supplier of the product * * @param $product_id - * @return int organization_id + * @return int|false organization_id */ public static function get_supplier_organisation_id_from_product($product_id) { $supplier_terms = wp_get_object_terms($product_id, 'supplier'); - $supplier_organisation_slug = $supplier_terms[0]->slug; - $supplier_organisation_id = get_term_by('slug', $supplier_organisation_slug, 'wiaas-user-organization')->term_id; + if (empty( $supplier_terms )) { - return $supplier_organisation_id; + return false; + } + + $supplier_organisation_slug = $supplier_terms[0]->slug; + $supplier_organisation = get_term_by('slug', $supplier_organisation_slug, 'wiaas-user-organization'); + + if ($supplier_organisation) { + return $supplier_organisation->term_id; + } + + return $supplier_organisation ? $supplier_organisation->term_id : false; } } diff --git a/backend/app/plugins/wiaas/includes/user/wiaas-organization-functions.php b/backend/app/plugins/wiaas/includes/user/wiaas-organization-functions.php index 4b9eeda..e68884f 100644 --- a/backend/app/plugins/wiaas/includes/user/wiaas-organization-functions.php +++ b/backend/app/plugins/wiaas/includes/user/wiaas-organization-functions.php @@ -110,4 +110,31 @@ function wiaas_get_organization_user_ids($organization_id) { $user_ids = get_objects_in_term($organization_id, Wiaas_User_Organization::TAXONOMY_NAME); return is_wp_error($user_ids) ? array() : $user_ids; +} + +function wiaas_get_organization_info($organization_id) { + + $organization = get_term($organization_id); + + if ($organization) { + + $user_ids = wiaas_get_organization_user_ids($organization_id); + + $email = null; + + if (! empty($user_ids)) { + + $user = get_userdata($user_ids[0]); + + $email = $user ? $user->user_email : null; + } + + return array( + 'name' => $organization->name, + 'description' => $organization->description, + 'vat_code' => get_term_meta($organization_id, '_wiaas_organization_vat'), + 'phone' => get_term_meta($organization_id, '_wiaas_organization_phone'), + 'email' => $email + ); + } } \ No newline at end of file diff --git a/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx b/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx index 5b1b5e6..cc5a4af 100644 --- a/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx +++ b/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx @@ -37,7 +37,7 @@ class ValidateQuestionnaireItem extends Component { { customerDocuments &&
- {orderPackage.packageName} + {orderPackage.name} { customerDocuments.map(document =>
{