Handle process visualization and going from one step to another
This commit is contained in:
@@ -11,21 +11,22 @@ defined( 'ABSPATH' ) || exit;
|
||||
class Wiaas_Delivery_Process {
|
||||
|
||||
public static function init() {
|
||||
self::_register_delivery_process_step_type();
|
||||
self::_register_delivery_process();
|
||||
|
||||
self::_init_hooks();
|
||||
}
|
||||
|
||||
private static function _init_hooks() {
|
||||
add_action('woocommerce_new_order', array( __CLASS__, 'create_delivery_process_for_order' ));
|
||||
|
||||
// add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 3 );
|
||||
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers our Delivery Process Step Type as available Gravity Flow Step Type
|
||||
*
|
||||
* Registers our Delivery Process Addons
|
||||
*
|
||||
*/
|
||||
private static function _register_delivery_process_step_type() {
|
||||
private static function _register_delivery_process() {
|
||||
require_once( 'delivery-process/class-wiaas-delivery-process-step.php' );
|
||||
|
||||
require_once( 'delivery-process/class-wiaas-delivery-process-addon.php' );
|
||||
@@ -39,9 +40,6 @@ class Wiaas_Delivery_Process {
|
||||
require_once( 'delivery-process/class-wiaas-field-order-supplier-select.php' );
|
||||
require_once( 'delivery-process/class-wiaas-field-order-bundle-document.php' );
|
||||
|
||||
|
||||
require_once( 'delivery-process/class-wiaas-date-list-field.php' );
|
||||
|
||||
Gravity_Flow_Steps::register( new Wiaas_Delivery_Process_Step() );
|
||||
|
||||
GFAddOn::register( 'Wiaas_Delivery_Process_Addon' );
|
||||
@@ -55,7 +53,8 @@ class Wiaas_Delivery_Process {
|
||||
public static function maybe_complete_parent_order($entry_id, $form) {
|
||||
$entry = GFAPI::get_entry($entry_id);
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
|
||||
$order_id = empty($order_field) ? null : absint($entry[$order_field->id]);
|
||||
|
||||
if (!isset($order_id)) {
|
||||
return;
|
||||
@@ -277,17 +276,7 @@ class Wiaas_Delivery_Process {
|
||||
continue;
|
||||
}
|
||||
|
||||
$action_code = 'manual';
|
||||
$action_form = GFAPI::get_form($step->target_form_id);
|
||||
$has_action_form = $action_form !== false;
|
||||
|
||||
if ($has_action_form) {
|
||||
|
||||
$delivery_settings = rgar($action_form, 'wiaas_delivery_process');
|
||||
|
||||
$action_code = empty($delivery_settings['delivery_action_code']) ? 'manual' : $delivery_settings['delivery_action_code'];
|
||||
}
|
||||
|
||||
$action_code = Wiaas_Delivery_Process_Action::get_process_step_action_form_action_code($step);
|
||||
$info = $step->get_feed_meta();
|
||||
|
||||
$status = $step->get_status();
|
||||
@@ -310,44 +299,40 @@ class Wiaas_Delivery_Process {
|
||||
|
||||
return $delivery_process;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Automatically create delivery process instance when order is created
|
||||
* @param $order_id
|
||||
*/
|
||||
public static function create_delivery_process_for_order($order_id) {
|
||||
$process_form = null;
|
||||
|
||||
$forms = GFAPI::get_forms();
|
||||
foreach ( $forms as $form ) {
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
if ( ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'process'){
|
||||
$process_form = $form;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($process_form)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$order = wc_get_order( $order_id );
|
||||
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
|
||||
$order_field_id = $order_field->id;
|
||||
|
||||
$new_process_entry = array(
|
||||
'form_id' => $process_form->id,
|
||||
"$order_field_id" => $order_id,
|
||||
'wiaas_delivery_order_id' => $order_id,
|
||||
);
|
||||
$process_entry_id = GFAPI::add_entry( $new_process_entry );
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );
|
||||
|
||||
|
||||
add_filter( 'gform_notification', 'rw_notification_attachments', 10, 3 );
|
||||
function rw_notification_attachments( $notification, $form, $entry ) {
|
||||
|
||||
$fileupload_fields = GFAPI::get_fields_by_type( $form, array( 'fileupload' ) , true);
|
||||
|
||||
if ( ! is_array( $fileupload_fields ) ) {
|
||||
return $notification;
|
||||
}
|
||||
|
||||
$notification['attachments'] = rgar( $notification, 'attachments', array() );
|
||||
$upload_root = RGFormsModel::get_upload_root();
|
||||
|
||||
foreach( $fileupload_fields as $field ) {
|
||||
|
||||
$url = rgar( $entry, $field->id );
|
||||
|
||||
if ( empty( $url ) ) {
|
||||
continue;
|
||||
} elseif ( $field->multipleFiles ) {
|
||||
$uploaded_files = json_decode( stripslashes( $url ), true );
|
||||
foreach ( $uploaded_files as $uploaded_file ) {
|
||||
$attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $uploaded_file );
|
||||
$notification['attachments'][] = $attachment;
|
||||
}
|
||||
} else {
|
||||
$attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $url );
|
||||
$notification['attachments'][] = $attachment;
|
||||
}
|
||||
}
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user