handle order actions
This commit is contained in:
@@ -2,15 +2,14 @@
|
||||
|
||||
class Wiaas_Delivery_Process_Action {
|
||||
|
||||
public static function init() {
|
||||
public static function is_action_form($form) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Wiaas_Delivery_Process_Step $step
|
||||
*/
|
||||
public static function get_step_action_form(Wiaas_Delivery_Process_Step $step) {
|
||||
public static function get_process_step_action_form($step) {
|
||||
|
||||
if (empty($step->target_form_id)) {
|
||||
|
||||
@@ -19,15 +18,36 @@ class Wiaas_Delivery_Process_Action {
|
||||
|
||||
$action_form = GFAPI::get_form($step->target_form_id);
|
||||
|
||||
if (! $action_form) {
|
||||
|
||||
return null;
|
||||
}
|
||||
return $action_form;
|
||||
}
|
||||
|
||||
public static function get_step_action_entries(Wiaas_Delivery_Process_Step $step) {
|
||||
public static function get_process_step_action_form_action_code($step) {
|
||||
|
||||
$action_form = self::get_step_action_form($step);
|
||||
$action_form = self::get_process_step_action_form($step);
|
||||
|
||||
if (empty($action_form)) {
|
||||
|
||||
return 'manual';
|
||||
}
|
||||
|
||||
$delivery_settings = rgar($action_form, 'wiaas_delivery_process');
|
||||
|
||||
return empty($delivery_settings) ? 'manual' : $delivery_settings['delivery_action_code'];
|
||||
}
|
||||
|
||||
public static function process_step_has_customer_acceptance_action($step) {
|
||||
|
||||
return self::get_process_step_action_form_action_code($step) === 'customer-acceptance';
|
||||
}
|
||||
|
||||
public static function process_step_has_customer_validate_questionnaires_action($step) {
|
||||
|
||||
return self::get_process_step_action_form_action_code($step) === 'validate-questionnaire';
|
||||
}
|
||||
|
||||
public static function get_process_step_action_entries(Wiaas_Delivery_Process_Step $step) {
|
||||
|
||||
$action_form = self::get_process_step_action_form($step);
|
||||
|
||||
if (!$action_form) {
|
||||
|
||||
@@ -35,7 +55,6 @@ class Wiaas_Delivery_Process_Action {
|
||||
}
|
||||
|
||||
$search_criteria = array(
|
||||
'status' => 'active',
|
||||
'field_filters' => array(
|
||||
array( 'key' => 'wiaas_delivery_process_id',
|
||||
'value' => $step->get_entry_id()
|
||||
@@ -67,18 +86,210 @@ class Wiaas_Delivery_Process_Action {
|
||||
return $action_forms;
|
||||
}
|
||||
|
||||
public static function is_action_form($form) {
|
||||
public static function complete_action_step($action_id) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
$action_entry = GFAPI::get_entry($action_id);
|
||||
|
||||
return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action';
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$workflow = new Gravity_Flow_API($action_form['id']);
|
||||
|
||||
$current_step = $workflow->get_current_step($action_entry);
|
||||
|
||||
if ( $current_step ) {
|
||||
|
||||
$new_status = $current_step->get_type() === 'approval' ? 'approved' : 'complete';
|
||||
|
||||
$assignees = $current_step->get_assignees();
|
||||
|
||||
foreach ($assignees as $assignee) {
|
||||
|
||||
$current_step->process_assignee_status($assignee, $new_status, $action_form);
|
||||
}
|
||||
}
|
||||
|
||||
gravity_flow()->process_workflow($action_form, $action_entry['id']);
|
||||
}
|
||||
|
||||
public static function get_customer_step_actions(Wiaas_Delivery_Process_Step $step) {
|
||||
public static function upload_customer_questionnaire($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
|
||||
$document_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'wiaas_order_bundle_document')[0];
|
||||
|
||||
|
||||
$new_file = $document_field->get_single_file_value($action_entry['form_id'], 'file');
|
||||
|
||||
$action_entry[$document_field->id] = $new_file;
|
||||
|
||||
GFAPI::update_entry($action_entry);
|
||||
}
|
||||
|
||||
public static function get_customer_acceptance_action_data($action_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_id);
|
||||
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
|
||||
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'fileupload')[0];
|
||||
$acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
|
||||
$decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
|
||||
$expiration_date_field = GFCommon::get_fields_by_type($action_form, 'date')[0];
|
||||
|
||||
$file_paths = json_decode($action_entry[$acceptance_documents_field->id]);
|
||||
|
||||
$documents = array();
|
||||
|
||||
foreach ($file_paths as $file_path) {
|
||||
|
||||
$info = pathinfo( $file_path );
|
||||
|
||||
$documents[] = array(
|
||||
'name' => $info['basename'],
|
||||
'url' => $acceptance_documents_field->get_download_url( $file_path, true )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'action_id' => $action_entry['id'],
|
||||
'documents' => $documents,
|
||||
'expiration' => $action_entry[$expiration_date_field->id],
|
||||
'decline_reason' => $action_entry[$decline_reason_field->id],
|
||||
'status' => ($action_entry[$acceptance_field->id] === 'accept') ? 1 : -1
|
||||
);
|
||||
}
|
||||
|
||||
public static function is_customer_acceptance_uploaded($action_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_id);
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
|
||||
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'fileupload')[0];
|
||||
|
||||
return ! empty( $action_entry[$acceptance_documents_field->id]);
|
||||
}
|
||||
|
||||
public static function update_customer_acceptance_status($action_id, $new_status, $reason) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_id);
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
|
||||
$decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
|
||||
|
||||
$action_entry[$acceptance_field->id] = $new_status;
|
||||
$action_entry[$decline_reason_field->id] = $reason;
|
||||
|
||||
GFAPI::update_entry($action_entry);
|
||||
}
|
||||
|
||||
public static function upload_customer_acceptance_document($action_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_id);
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'fileupload')[0];
|
||||
|
||||
$old_value = $action_entry[$acceptance_documents_field->id];
|
||||
|
||||
$value = $acceptance_documents_field->get_single_file_value($action_form['id'], 'file');
|
||||
|
||||
if ($acceptance_documents_field->multipleFiles ) {
|
||||
|
||||
$value = array( $value );
|
||||
|
||||
$old_value = json_decode( $old_value );
|
||||
|
||||
if (! empty($old_value)) {
|
||||
|
||||
$old_value = is_array( $old_value ) ? $old_value : array( $old_value );
|
||||
|
||||
$value = array_merge( $value, $old_value );
|
||||
}
|
||||
|
||||
$value = json_encode( $value );
|
||||
}
|
||||
|
||||
$action_entry[$acceptance_documents_field->id] = $value;
|
||||
|
||||
$result = GFAPI::update_entry($action_entry);
|
||||
|
||||
return ! is_wp_error($result);
|
||||
}
|
||||
|
||||
public static function get_customer_validate_questionnaires_action_data($action_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_id);
|
||||
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$order_id = $action_entry['wiaas_delivery_order_id'];
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
|
||||
// we need to collect document, bundle id and current status
|
||||
$bundle_item_id = null; $status = null;
|
||||
|
||||
$bundle_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle')[0];
|
||||
$bundle_item_id = absint(explode('|', $action_entry[$bundle_field->id])[1]);
|
||||
|
||||
if (empty($bundle_item_id)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
$document_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'wiaas_order_bundle_document')[0];
|
||||
$file_path = $action_entry[$document_field->id];
|
||||
|
||||
$info = pathinfo( $action_entry[$document_field->id] );
|
||||
|
||||
$document = array(
|
||||
'name' => $info['basename'],
|
||||
'url' => $document_field->get_download_url( $file_path, true )
|
||||
);
|
||||
|
||||
$discussion_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'workflow_discussion')[0];
|
||||
$discussion_items = json_decode($action_entry[$discussion_field->id], ARRAY_A);
|
||||
|
||||
$formated_comments = array();
|
||||
|
||||
if (is_array($discussion_items)) {
|
||||
foreach ($discussion_items as $item) {
|
||||
|
||||
$formated_comments[] = $discussion_field->format_discussion_item( $item, 'text', $action_id );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$action_workflow_api = new Gravity_Flow_API($action_form['id']);
|
||||
$action_step = $action_workflow_api->get_current_step($action_entry);
|
||||
$status = 'validated';
|
||||
|
||||
if (! empty($action_step)) {
|
||||
|
||||
if ($action_step->get_type() === 'approval') {
|
||||
|
||||
$status = 'not-validated';
|
||||
}
|
||||
|
||||
if ($action_step->get_type() === 'user_input') {
|
||||
|
||||
$status = 'invalid';
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'item_id' => $bundle_item_id,
|
||||
'order_id' =>$order->get_id(),
|
||||
'action_id' => $action_entry['id'],
|
||||
'document' => $document,
|
||||
'status' => $status,
|
||||
'comments' => $formated_comments
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Wiaas_Delivery_Process_Action::init();
|
||||
|
||||
@@ -27,39 +27,42 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
public function init() {
|
||||
|
||||
parent::init();
|
||||
|
||||
add_action( 'gravityflow_entry_detail', array( $this, 'display_process_steps_details' ), 10, 3 );
|
||||
|
||||
add_action('gravityflow_title_entry_detail', array( $this, 'process_title' ), 10, 3);
|
||||
|
||||
add_filter( 'gform_upload_path', array( $this, 'post_file_upload' ), 10, 2 );
|
||||
}
|
||||
|
||||
public function init_ajax() {
|
||||
parent::init_ajax();
|
||||
add_action( 'wp_ajax_wiaas_get_action_entry', array( $this, 'ajax_get_action_entry' ) );
|
||||
|
||||
// this AJAX action is here and not in /admin folder because of Gravity Forms extension logic
|
||||
add_action( 'wp_ajax_wiaas_delivery_get_form', array( $this, 'ajax_get_form' ) );
|
||||
}
|
||||
|
||||
public function ajax_get_form() {
|
||||
|
||||
public function post_file_upload($path_info, $form_id) {
|
||||
$form_id = isset( $_GET['form_id'] ) ? absint( $_GET['form_id'] ) : 0;
|
||||
|
||||
$wp_uploads = wp_upload_dir();
|
||||
$field_id = sanitize_text_field( rgget( 'field_id' ) );
|
||||
|
||||
if ( empty( $wp_uploads['subdir'] ) ) {
|
||||
$path_info['path'] = $wp_uploads['path'] . wiaas_documents_base_dir();
|
||||
$path_info['url'] = $wp_uploads['url'] . wiaas_documents_base_dir();
|
||||
$path_info['subdir'] = wiaas_documents_base_dir();
|
||||
} else {
|
||||
$new_subdir = wiaas_documents_base_dir() . $wp_uploads['subdir'];
|
||||
$entry_id = absint( rgget( 'entry_id' ) );
|
||||
|
||||
$path_info['path'] = str_replace( $wp_uploads['subdir'], $new_subdir, $wp_uploads['path'] );
|
||||
$path_info['url'] = str_replace( $wp_uploads['subdir'], $new_subdir, $wp_uploads['url'] );
|
||||
$path_info['subdir'] = str_replace( $wp_uploads['subdir'], $new_subdir, $wp_uploads['subdir'] );
|
||||
}
|
||||
$field_values = array( $field_id => $entry_id );
|
||||
|
||||
error_log($path_info);
|
||||
gravity_form_enqueue_scripts( $form_id, true );
|
||||
|
||||
return $path_info;
|
||||
$is_admin = isset( $_GET['is_admin'] );
|
||||
if ( $is_admin ) {
|
||||
wp_enqueue_style( 'common', site_url() . '/wp-admin/css/common.css', array(), $this->_version );
|
||||
} else {
|
||||
wp_enqueue_style( 'common', get_stylesheet_directory_uri() . '/style.css', array(), $this->_version );
|
||||
}
|
||||
|
||||
wp_print_styles();
|
||||
wp_print_scripts();
|
||||
// Render an AJAX-enabled form.
|
||||
// https://www.gravityhelp.com/documentation/article/embedding-a-form/#function-call
|
||||
$html = gravity_form( $form_id, true, false, false, $field_values, true, 1, false );
|
||||
printf( "<div id='wiaas-delivery-process-form' style='padding:10px;'>%s</div>", $html );
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
@@ -125,170 +128,6 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function display_process_steps_details($form, $entry, $current_step) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
if ($delivery_settings['delivery_form_type'] === 'action') {
|
||||
return;
|
||||
}
|
||||
|
||||
$workflow_api = new Gravity_Flow_API($form['id']);
|
||||
|
||||
$steps = $workflow_api->get_steps();
|
||||
|
||||
foreach ($steps as $index => $step) {
|
||||
|
||||
if (! $step->is_active()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_step_running = $step->get_status() === 'pending';
|
||||
$is_current_step = $step->get_id() === $current_step->get_id();
|
||||
|
||||
$disabled_style = $is_step_running ? '' : 'opacity: 0.5';
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox" style="<?php esc_attr_e($disabled_style, 'wiaas') ?>">
|
||||
|
||||
<h3>
|
||||
<span><?php esc_html_e($step->get_name(), 'wiaas') ?></span>
|
||||
</h3>
|
||||
|
||||
<?php
|
||||
if ($is_current_step) {
|
||||
Gravity_Flow_Entry_Detail::maybe_show_instructions(true, true, $current_step, $form, $entry);
|
||||
|
||||
$action_form = GFAPI::get_form( $step->target_form_id );
|
||||
|
||||
if (empty($action_form)) {
|
||||
|
||||
echo '</div>';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$action_delivery_settings = rgar($action_form, 'wiaas_delivery_process');
|
||||
|
||||
?>
|
||||
|
||||
<div class="submitbox" style="padding: 10px;">
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
if (! $action_delivery_settings['automatic_action_entries_enabled']) {
|
||||
|
||||
$form_url = admin_url( 'admin-ajax.php' ) . '?action=gravityflowparentchild_get_form&order_id=65&form_id=' . $action_form['id'] . '&wiaas_delivery_process_id=' . $entry['id'];
|
||||
$form_url .= '&is_admin=1';
|
||||
|
||||
$form_link = sprintf(
|
||||
'<a href="%s&TB_iframe=true&width=600&height=550" class="button button-primary thickbox">' .
|
||||
'<i class="fa fa-plus"></i> ' . $action_form['title'] . '</a>',
|
||||
$form_url );
|
||||
|
||||
echo $form_link;
|
||||
}
|
||||
|
||||
echo '<br><br><br>';
|
||||
|
||||
$page_size = 20;
|
||||
$search_criteria = array(
|
||||
'status' => 'active',
|
||||
'field_filters' => array(
|
||||
array( 'key' => 'wiaas_delivery_process_id',
|
||||
'value' => $entry['id']
|
||||
),
|
||||
),
|
||||
);
|
||||
$sorting = array( 'key' => 'date_created', 'direction' => 'DESC' );
|
||||
$paging = array( 'offset' => 0, 'page_size' => $page_size );
|
||||
|
||||
$entries = GFAPI::get_entries( $action_form, $search_criteria, $sorting, $paging );
|
||||
|
||||
foreach ($entries as $action_entry) {
|
||||
$this->_display_step_action_entry($action_form, $action_entry);
|
||||
}
|
||||
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function _display_step_action_entry($action_form, $action_entry) {
|
||||
$workflow_api = new Gravity_Flow_API($action_entry['form_id']);
|
||||
|
||||
$current_action_step = $workflow_api->get_current_step($action_entry);
|
||||
|
||||
|
||||
?>
|
||||
<table>
|
||||
|
||||
<?php
|
||||
foreach ($action_form['fields'] as $field) {
|
||||
|
||||
if ($field->type === 'wiaas_order') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($field->type === 'workflow_discussion') {
|
||||
|
||||
echo '<tr><td colspan="2">' . $field->get_value_entry_detail($action_entry[$field->id]) . '</td></tr>';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $field->get_value_entry_detail($action_entry[$field->id]);
|
||||
$label = $field->get_field_label(false, $action_entry[$field->id]);
|
||||
|
||||
echo '<tr>' .
|
||||
'<td><strong>' . $label . ' : </strong></td>' .
|
||||
'<td>' . $value . '</td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
if (! empty($current_action_step)) {
|
||||
|
||||
?>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<a class="button" href="<?php echo $current_action_step->get_entry_url() ?>">
|
||||
View
|
||||
<?php echo $current_action_step->get_status_label($current_action_step->get_status()) ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<hr>
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function scripts() {
|
||||
|
||||
@@ -346,75 +185,85 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
'title' => esc_html__( 'Delivery Process', 'wiaas' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'delivery_form_type',
|
||||
'name' => 'delivery_process',
|
||||
'label' => esc_html__( 'Delivery Form Type', 'wiaas' ),
|
||||
'type' => 'delivery_form_type',
|
||||
),
|
||||
array(
|
||||
'name' => 'delivery_action_code',
|
||||
'label' => esc_html__( 'Action code', 'wiaas' ),
|
||||
'type' => 'delivery_action_code',
|
||||
),
|
||||
array(
|
||||
'name' => 'delivery_action_form_type',
|
||||
'label' => esc_html__( 'Automatic?', 'wiaas' ),
|
||||
'type' => 'delivery_action_form_automatic',
|
||||
'type' => 'delivery_process',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function settings_delivery_form_type() {
|
||||
public function settings_delivery_process() {
|
||||
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_form_type',
|
||||
'choices' => array(
|
||||
array( 'value' => 'process', 'label' => 'Process Form' ),
|
||||
array( 'value' => 'action', 'label' => 'Action Form' ),
|
||||
array( 'value' => 'process', 'label' => 'Process Form' )
|
||||
),
|
||||
'after_select' => '<p class="description"> Choose if this form will be used as process form or action form.</p>' .
|
||||
'<p class="description"> <strong>Process form</strong> defines order delivery process workflow.</p>' .
|
||||
'<p class="description"> <strong>Action form</strong> defines custom order data that is collected from delivery process participants.</p>'
|
||||
));
|
||||
}
|
||||
|
||||
public function settings_delivery_action_code() {
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_action_code',
|
||||
'choices' => array(
|
||||
array( 'value' => '', 'label' => 'Select action code ...' ),
|
||||
array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
|
||||
array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
|
||||
array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' )
|
||||
),
|
||||
'after_select' => '<p class="description"> Choose action code for action form.</p>'
|
||||
));
|
||||
}
|
||||
|
||||
public function settings_delivery_action_form_automatic() {
|
||||
?>
|
||||
<br /> <br /> <br />
|
||||
<?php
|
||||
|
||||
$this->settings_checkbox_and_select(array(
|
||||
'checkbox' => array(
|
||||
'label' => esc_html__( 'Enable', 'wiaas' ),
|
||||
'name' => 'automatic_action_entries_enabled',
|
||||
'defeault_value' => '0',
|
||||
),
|
||||
'select' => array(
|
||||
'name' => 'automatic_action_entries_type',
|
||||
|
||||
$settings = $this->get_current_settings();
|
||||
|
||||
if ($settings['delivery_form_type'] !== 'process') {
|
||||
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_action_code',
|
||||
'choices' => array(
|
||||
array(
|
||||
'value' => 'single',
|
||||
'label' => esc_html__( 'Single entry', 'wiaas' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'bundle',
|
||||
'label' => esc_html__( 'Entry per bundle', 'wiaas' ),
|
||||
)
|
||||
array( 'value' => '', 'label' => 'Select action code ...' ),
|
||||
array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
|
||||
array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
|
||||
array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' )
|
||||
),
|
||||
'after_select' => '<p class="description">Automatic entries can be created once per order or per every bundle in order.</p>' .
|
||||
'<p class="description">Automatic entry will not be created if any required field cannot be populated.</p>',
|
||||
)
|
||||
'after_select' => '<p class="description"> Choose action code for action form.</p>'
|
||||
));
|
||||
|
||||
|
||||
$this->settings_checkbox_and_select(array(
|
||||
'checkbox' => array(
|
||||
'label' => esc_html__( 'Automatic', 'wiaas' ),
|
||||
'name' => 'automatic_action_entries_enabled',
|
||||
'default_value' => '0',
|
||||
),
|
||||
'select' => array(
|
||||
'name' => 'automatic_action_entries_type',
|
||||
'choices' => array(
|
||||
array(
|
||||
'value' => 'single',
|
||||
'label' => esc_html__( 'Single entry', 'wiaas' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'bundle',
|
||||
'label' => esc_html__( 'Entry per bundle', 'wiaas' ),
|
||||
)
|
||||
),
|
||||
'after_select' => '<p class="description">Automatic entries can be created once per order or per every bundle in order.</p>' .
|
||||
'<p class="description">Automatic entry will not be created if any required field cannot be populated.</p>',
|
||||
)
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_country',
|
||||
'choices' => array(
|
||||
array( 'value' => 'se', 'label' => 'Sweden' ),
|
||||
array( 'value' => 'dk', 'label' => 'Denmark' ),
|
||||
array( 'value' => 'fi', 'label' => 'Finland' )
|
||||
),
|
||||
'after_select' => '<p class="description"> Choose country for which this process is defined.</p>'
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -79,9 +79,16 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
|
||||
public function update_step_status($status = false) {
|
||||
|
||||
if ($status === 'cancelled') {
|
||||
if (isset( $_POST['_gravityflow_admin_action'] ) ) {
|
||||
|
||||
$status = 'complete';
|
||||
$admin_action = rgpost( 'gravityflow_admin_action' );
|
||||
|
||||
list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 );
|
||||
|
||||
if ($base_admin_action === 'send_to_step' && $this->get_status() === 'pending') {
|
||||
|
||||
$status = 'complete';
|
||||
}
|
||||
}
|
||||
|
||||
parent::update_step_status($status);
|
||||
@@ -262,12 +269,9 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
return $action_entries_ids;
|
||||
}
|
||||
|
||||
$new_entry = array_merge($new_entry,array(
|
||||
'form_id' => $this->target_form_id,
|
||||
'wiaas_delivery_process_id' => $this->get_entry_id(),
|
||||
'wiaas_delivery_order_id' => $order_id,
|
||||
'wiaas_delivery_step_name' => $this->get_name(),
|
||||
));
|
||||
$new_entry['form_id'] = $target_form['id'];
|
||||
$new_entry['wiaas_delivery_process_id'] = $this->get_entry_id();
|
||||
$new_entry['wiaas_delivery_order_id'] = $order_id;
|
||||
|
||||
$entry_id = GFAPI::add_entry( $new_entry );
|
||||
|
||||
|
||||
@@ -28,30 +28,33 @@ class Wiaas_Field_Order_Bundle_Select extends GF_Field_Select {
|
||||
return $this->get_selected_bundle_display_name($value);
|
||||
}
|
||||
|
||||
public function get_field_input( $form, $value = '', $entry = null ) {
|
||||
|
||||
$this->choices = array();
|
||||
|
||||
$order_id = null;
|
||||
|
||||
if (! empty($entry)) {
|
||||
|
||||
$order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order' ) )[0];
|
||||
|
||||
$order_id = ! empty($order_field) ? $entry[$order_field->id] : null;
|
||||
|
||||
} else if( ! empty($value)) {
|
||||
|
||||
list ($order_id, $item_id) = explode('|', $value);
|
||||
}
|
||||
|
||||
if (! empty($order_id)) {
|
||||
|
||||
$this->choices = $this->get_selected_bundle_display_name($order_id);
|
||||
}
|
||||
|
||||
return parent::get_field_input( $form, $value, $entry );
|
||||
}
|
||||
// public function get_field_input( $form, $value = '', $entry = null ) {
|
||||
//
|
||||
// $this->choices = array();
|
||||
//
|
||||
// $order_id = null;
|
||||
//
|
||||
// if (! empty($entry)) {
|
||||
//
|
||||
// $order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order' ) )[0];
|
||||
//
|
||||
// $order_id = ! empty($order_field) ? $entry[$order_field->id] : null;
|
||||
//
|
||||
// } else if( ! empty($value)) {
|
||||
//
|
||||
// list ($order_id, $item_id) = explode('|', $value);
|
||||
// } else {
|
||||
//
|
||||
// $order_id = absint(rgget('order_id'));
|
||||
// }
|
||||
//
|
||||
// if (! empty($order_id)) {
|
||||
//
|
||||
// $this->choices = $this->get_selected_bundle_display_name($order_id);
|
||||
// }
|
||||
//
|
||||
// return parent::get_field_input( $form, $value, $entry );
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,13 +65,14 @@ class Wiaas_Order_Fields {
|
||||
|
||||
public static function map_order_to_entry($order_id, $form, $bundle_item_id = null) {
|
||||
|
||||
|
||||
if (empty($form['fields']) ||
|
||||
empty(GFCommon::get_fields_by_type( $form, array('wiaas_order')) ) ) {
|
||||
// form does not have order field so cannot be mapped
|
||||
return false;
|
||||
}
|
||||
|
||||
error_log(json_encode('here'));
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
Reference in New Issue
Block a user