Handle assigment for order delivery flow

This commit is contained in:
Almira Krdzic
2018-11-02 10:30:25 +01:00
parent 4b0fc6c61d
commit cdbefc7ef0
25 changed files with 1131 additions and 1047 deletions

View File

@@ -27,24 +27,58 @@ class Wiaas_Delivery_Process {
*
*/
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' );
require_once( 'delivery-process/class-wiaas-delivery-process-action.php' );
require_once( 'delivery-process/class-wiaas-delivery-process-step-assignee.php' );
require_once( 'delivery-process/class-wiaas-delivery-process-step.php' );
// order fields
require_once( 'delivery-process/class-wiaas-order-fields.php' );
require_once( 'delivery-process/class-wiaas-field-order-number.php' );
require_once( 'delivery-process/class-wiaas-field-order-bundle-select.php' );
require_once( 'delivery-process/class-wiaas-field-order-supplier-select.php' );
require_once( 'delivery-process/class-wiaas-field-order-bundle.php' );
require_once( 'delivery-process/class-wiaas-field-order-installation-select.php' );
require_once( 'delivery-process/class-wiaas-field-order-bundle-document.php' );
require_once( 'delivery-process/class-wiaas-field-order-document.php' );
Gravity_Flow_Steps::register( new Wiaas_Delivery_Process_Step() );
GFAddOn::register( 'Wiaas_Delivery_Process_Addon' );
}
public static function create_delivery_process_for_order($order_id, $process_id) {
$process_form = null;
$process_form = GFAPI::get_form($process_id);
if( $process_form ) {
$new_process_entry = array(
'wiaas_delivery_order_id' => $order_id,
'form_id' => $process_id,
);
$order_fields = GFCommon::get_fields_by_type($process_form, array('wiaas_order'));
if (! empty($order_fields)) {
$order_field = $order_fields[0];
$new_process_entry[$order_field['id']] = $order_id;
}
$process_entry_id = GFAPI::add_entry( $new_process_entry );
update_post_meta($order_id, 'wiaas_delivery_process_id', $process_id);
update_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id);
return $process_entry_id;
}
return false;
}
/**
* Maybe complete parent order for completed delivery process
* @param $entry_id
@@ -147,7 +181,7 @@ class Wiaas_Delivery_Process {
return $data;
}
public static function update_customer_acceptance_status($order_id,$status, $reason) {
public static function update_customer_acceptance_status($order_id, $status, $reason) {
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
@@ -228,10 +262,12 @@ class Wiaas_Delivery_Process {
public static function get_order_delivery_process_entry($order_id) {
$order = wc_get_order($order_id);
$process_entry_id = $order->get_meta('wiaas_delivery_process_entry_id', true);
if (!isset($process_entry_id)) {
return array();
if (empty($process_entry_id)) {
return array();
}
return GFAPI::get_entry($process_entry_id);
@@ -246,7 +282,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');
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id', true);
if (empty($process_entry_id)) {
return null;
@@ -263,7 +299,22 @@ class Wiaas_Delivery_Process {
$delivery_process = array(
'id' => $process_form['id'],
'name' => $process_form['title'],
'steps' => array()
'steps' => array(
array(
'short_desc' => 'Order placed',
'status' => 'complete',
'order_id' => $order_id,
'process_id' => $process_entry_id,
'step_id' => -1,
),
array(
'short_desc' => 'Assign process',
'status' => 'complete',
'order_id' => $order_id,
'process_id' => $process_entry_id,
'step_id' => 0,
)
)
);
$current_step = $api->get_current_step($process_instance);
@@ -302,37 +353,3 @@ class Wiaas_Delivery_Process {
}
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;
}