Handle process navigation better
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
.wiaas_delivery_step_nav {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
.gravityflow_workflow_detail #postbox-container-1 > div:nth-child(2) {
|
||||
display: none;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
*
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<div style="padding:10px; height:40px">
|
||||
|
||||
<input id="wiaas_delivery_process_navigation_action" type="hidden" name="wiaas_delivery_process_navigation_action">
|
||||
<input type="hidden" name="_gravityflow_admin_action" value="1">
|
||||
|
||||
<input
|
||||
data-step="send_to_step|<?php esc_attr_e($next_step_id, 'wiaas') ?>"
|
||||
type="submit"
|
||||
<?php disabled(empty($next_step_id), true, true) ?>
|
||||
class="button wiaas_delivery_step_nav"
|
||||
style="float:right; margin-left: 20px;" value="NEXT STEP">
|
||||
|
||||
<input
|
||||
data-step="send_to_step|<?php esc_attr_e($previous_step_id, 'wiaas') ?>"
|
||||
type="submit"
|
||||
<?php disabled(empty($previous_step_id), true, true) ?>
|
||||
class="button wiaas_delivery_step_nav"
|
||||
style="float:right;" value="PREV STEP">
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
public static function wiaas_ajax_create_order_delivery_process() {
|
||||
|
||||
@@ -294,8 +294,12 @@ class Wiaas_Cart {
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist used payment type information for package in corresponding order line item.
|
||||
* Also for standard package type list of addons and options will be saved.
|
||||
* Persist additional metadata for every order item
|
||||
* This includes:
|
||||
*
|
||||
* 1. payment info
|
||||
* 2. relation info for addons and options
|
||||
* 3. prices for simple products
|
||||
*
|
||||
* @param $order_item
|
||||
* @param $cart_item_key
|
||||
@@ -374,6 +378,27 @@ class Wiaas_Cart {
|
||||
$order_item->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;
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class ValidateQuestionnaireItem extends Component {
|
||||
{
|
||||
customerDocuments &&
|
||||
<div>
|
||||
{orderPackage.packageName}
|
||||
{orderPackage.name}
|
||||
{
|
||||
customerDocuments.map(document => <div key={'package-document-' + document.key}>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user