Persist workflow entry fields to order
This commit is contained in:
@@ -598,11 +598,21 @@ class Wiaas_Order {
|
||||
|
||||
if (wiaas_is_order_item__standard_package($order_item)) {
|
||||
$documents = wiaas_get_standard_package_order_item_documents($order, $product_line['id']);
|
||||
|
||||
if (! empty($order_item['wiaas_delivery_documents'])) {
|
||||
|
||||
$documents = array_merge($documents, $order_item['wiaas_delivery_documents']);
|
||||
}
|
||||
|
||||
$data['line_items'][$index] ['documents'] = $documents;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$order_delivery_documents = $order->get_meta('wiaas_delivery_documents', true);
|
||||
$order_delivery_documents = empty($order_delivery_documents) ? array() : $order_delivery_documents;
|
||||
$data['documents'] = $order_delivery_documents;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,74 +24,6 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
|
||||
parent::init();
|
||||
|
||||
add_filter('gravityflow_get_users_args', array ($this, 'allow_only_administrator_to_be_assigned_to_step'));
|
||||
|
||||
add_filter('gravityflow_assignee_choices', array ($this, 'add_orders_assignee_choices'));
|
||||
|
||||
add_filter('gravityflow_step_assignees', array ($this, 'maybe_assign_organization_to_step'), 10, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle organization assignee for step (Map users from organization as assignees to step)
|
||||
*
|
||||
* @param $assignees
|
||||
* @param Gravity_Flow_Step $step
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function maybe_assign_organization_to_step($assignees, Gravity_Flow_Step $step) {
|
||||
|
||||
$mapped_assignees = array();
|
||||
|
||||
foreach ($assignees as $assignee) {
|
||||
|
||||
if (strpos($assignee->get_type(), 'wiaas_organization_order_') !== false) {
|
||||
|
||||
$organization_id = $assignee->get_id();
|
||||
|
||||
$user_ids = wiaas_get_organization_user_ids($organization_id);
|
||||
|
||||
if (empty($user_ids)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$user_id = $user_ids[0];
|
||||
|
||||
$mapped_assignees[] = $step->get_assignee( array(
|
||||
'id' => $user_id,
|
||||
'type' => 'user_id',
|
||||
'editable_fields' => $assignee->get_editable_fields()
|
||||
) );
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$mapped_assignees[] = $assignee;
|
||||
}
|
||||
|
||||
return $mapped_assignees;
|
||||
}
|
||||
|
||||
|
||||
public function allow_only_administrator_to_be_assigned_to_step($args) {
|
||||
|
||||
$args['role'] = 'administrator';
|
||||
|
||||
//$args['exclude'] = array( 1 ); // exclude super admin user
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
public static function add_orders_assignee_choices($choices) {
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
|
||||
*
|
||||
|
||||
@@ -91,8 +91,7 @@ class Wiaas_Order_Installation_Select extends GF_Field_Select {
|
||||
return $this->get_selected_installation_display_name($value);
|
||||
}
|
||||
|
||||
|
||||
public function get_selected_installation_display_name($value) {
|
||||
public function get_selected_installation($value) {
|
||||
|
||||
$value = $value ? str_replace('wiaas_installation_', '', $value) : '';
|
||||
|
||||
@@ -100,12 +99,17 @@ class Wiaas_Order_Installation_Select extends GF_Field_Select {
|
||||
|
||||
if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) {
|
||||
|
||||
$item = $order->get_item($item_id);
|
||||
|
||||
return $item->get_name();
|
||||
return $order->get_item($item_id);
|
||||
}
|
||||
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_selected_installation_display_name($value) {
|
||||
|
||||
$item = $this->get_selected_installation($value);
|
||||
|
||||
return ! empty($item) ? $item->get_name() : '';
|
||||
}
|
||||
|
||||
public function post_convert_field() {
|
||||
|
||||
@@ -11,8 +11,192 @@ class Wiaas_Order_Fields {
|
||||
add_action( 'gform_field_standard_settings', array( __CLASS__, 'field_settings' ) );
|
||||
|
||||
add_filter('gform_fileupload_entry_value_file_path', array( __CLASS__, 'display_order_document_fields' ), 999, 2);
|
||||
|
||||
add_action('gform_post_update_entry', array(__CLASS__, 'maybe_map_entry_to_order'), 10, 2);
|
||||
|
||||
add_action('gform_after_update_entry', array(__CLASS__, 'maybe_apply_user_input_changes'), 10, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Workflow user input are handled separately in gravity flow. We get them here
|
||||
* and then try to apply changes to order
|
||||
*
|
||||
* @param $form
|
||||
* @param $entry_id
|
||||
* @param $original_entry
|
||||
*/
|
||||
public static function maybe_apply_user_input_changes($form, $entry_id, $original_entry) {
|
||||
|
||||
$entry = GFAPI::get_entry($entry_id);
|
||||
|
||||
self::maybe_map_entry_to_order($entry, $original_entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Persist workflow entry change to order
|
||||
*
|
||||
* @param $entry
|
||||
* @param $old_entry
|
||||
*/
|
||||
public static function maybe_map_entry_to_order($entry, $old_entry) {
|
||||
|
||||
$form = GFAPI::get_form($old_entry['form_id']);
|
||||
|
||||
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
|
||||
|
||||
if (empty($order_field)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$order_id = $entry[$order_field->id];
|
||||
|
||||
// get order process entry
|
||||
$order = wc_get_order($order_id);
|
||||
$process_entry = Wiaas_Delivery_Process::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if ( !$order || empty($process_entry) ) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// apply entry changes to order properties
|
||||
foreach ($form['fields'] as $field) {
|
||||
|
||||
$old_value = $old_entry[$field->id];
|
||||
$new_value = $entry[$field->id];
|
||||
|
||||
// check if field changed
|
||||
if ($old_value === $new_value || empty($new_value)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// save changes to order
|
||||
switch ($field->type) {
|
||||
|
||||
case 'wiaas_order_bundle_document':
|
||||
/**
|
||||
* Persist delivery flow documents for bundle
|
||||
*/
|
||||
|
||||
// get corresponding bundle field
|
||||
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
|
||||
|
||||
if (empty($bundle_field)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
|
||||
|
||||
if (empty($bundle_item)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_documents = $bundle_item['wiaas_delivery_documents'];
|
||||
if (empty($bundle_documents)) {
|
||||
$bundle_documents = array();
|
||||
}
|
||||
|
||||
$new_documents = $field->multipleFiles ? json_decode( $new_value ) : array( $new_value );
|
||||
if (! empty($old_value) ) {
|
||||
|
||||
$old_documents = $field->multipleFiles ? json_decode( $old_value ) : array( $old_value );
|
||||
$added_documents = array_diff($new_documents, $old_documents);
|
||||
} else {
|
||||
|
||||
$added_documents = $new_documents;
|
||||
}
|
||||
|
||||
|
||||
foreach ($added_documents as $added_document) {
|
||||
$info = pathinfo( $added_document );
|
||||
|
||||
$bundle_documents[] = array(
|
||||
'name' => $info['basename'],
|
||||
'extension' => $info['extension'],
|
||||
'url' => $field->get_download_url( $added_document, true ),
|
||||
'type' => $field->wiaasDocTypeFilter
|
||||
);
|
||||
}
|
||||
|
||||
$bundle_item->update_meta_data('wiaas_delivery_documents', $bundle_documents);
|
||||
$bundle_item->save_meta_data();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_document':
|
||||
/**
|
||||
* Persist delivery flow documents for order
|
||||
*/
|
||||
$new_documents = $field->multipleFiles ? json_decode( $new_value ) : array( $new_value );
|
||||
|
||||
if (! empty($old_value) ) {
|
||||
|
||||
$old_documents = $field->multipleFiles ? json_decode( $old_value ) : array( $old_value );
|
||||
$added_documents = array_diff($new_documents, $old_documents);
|
||||
} else {
|
||||
|
||||
$added_documents = $new_documents;
|
||||
}
|
||||
|
||||
$order_documents = $order->get_meta('wiaas_delivery_documents', true);
|
||||
if (empty($order_documents)) {
|
||||
$order_documents = array();
|
||||
}
|
||||
|
||||
foreach ($added_documents as $added_document) {
|
||||
$info = pathinfo( $added_document );
|
||||
|
||||
$order_documents[] = array(
|
||||
'name' => $info['basename'],
|
||||
'extension' => $info['extension'],
|
||||
'url' => $field->get_download_url( $added_document, true ),
|
||||
'type' => $field->wiaasDocTypeFilter
|
||||
);
|
||||
}
|
||||
|
||||
$order->update_meta_data('wiaas_delivery_documents', $order_documents);
|
||||
$order->save_meta_data();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_installation_select':
|
||||
/**
|
||||
* Persist installation for bundle
|
||||
*/
|
||||
|
||||
$selected_installation = $field->get_selected_installation($new_value);
|
||||
|
||||
if (empty($selected_installation)) {
|
||||
// no installation selected
|
||||
continue;
|
||||
}
|
||||
|
||||
// get corresponding bundle field
|
||||
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
|
||||
|
||||
if (empty($bundle_field)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
|
||||
|
||||
if (empty($bundle_item)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item->update_meta_data('wiaas_installation', $selected_installation->get_id());
|
||||
$bundle_item->save_meta_data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Order Fields group to the form editor.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import OrderDocumentsGroup from './OrderDocumentsGroup.jsx';
|
||||
import {orderTexts} from '../../../constants/ordersConstants';
|
||||
import WiaasBox from "../../../mainComponents/box/WiaasBox";
|
||||
|
||||
class OrderDocuments extends Component {
|
||||
render() {
|
||||
@@ -18,7 +19,22 @@ class OrderDocuments extends Component {
|
||||
/>))
|
||||
}
|
||||
{
|
||||
orderInfo.orderDocuments && <OrderDocumentsGroup key={'order-package-0'} documentsGroup={{documents: orderInfo.documents, packageName: orderTexts.labels.OTHER_DOCS}} />
|
||||
orderInfo.documents && <div>
|
||||
<WiaasBox mainTitle={orderTexts.labels.OTHER_DOCS}>
|
||||
{
|
||||
orderInfo.documents.map((document, index) => (
|
||||
<a className="document-link-big" key={'order-document-' + index} download href={document.url}>
|
||||
<span className="document-link">
|
||||
<i className={`fa fa-4x fa-${document.icon}`} aria-hidden="true"></i>
|
||||
<div>
|
||||
{document.name}
|
||||
</div>
|
||||
</span>
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</WiaasBox>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -27,13 +27,31 @@ class OrderDocumentsGroup extends Component {
|
||||
documentsGroup.documents.length > 0 &&
|
||||
<WiaasBox mainTitle={documentsGroup.name}>
|
||||
{
|
||||
documentsGroup.documents.map(document => <a id={'document-' + document.key} key={'order-document-' + document.key}>
|
||||
<div onClick={() => {this.downloadDocument(orderId, documentsGroup.orderItemId, document)}} className="document-link-big">
|
||||
<i className={`fa fa-4x fa-${document.icon}`} aria-hidden="true"></i>
|
||||
<div>
|
||||
{document.name}
|
||||
</div>
|
||||
</div></a>)
|
||||
documentsGroup.documents.map((document, index) => {
|
||||
if (document.url) {
|
||||
|
||||
return (
|
||||
<a key={'order-document-' + index} download href={document.url}>
|
||||
<div className="document-link" className="document-link-big">
|
||||
<i className={`fa fa-4x fa-${document.icon}`} aria-hidden="true"></i>
|
||||
<div>
|
||||
{document.name}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<a id={'document-' + document.key} key={'order-document-' + document.key}>
|
||||
<div onClick={() => {this.downloadDocument(orderId, documentsGroup.orderItemId, document)}} className="document-link-big">
|
||||
<i className={`fa fa-4x fa-${document.icon}`} aria-hidden="true"></i>
|
||||
<div>
|
||||
{document.name}
|
||||
</div>
|
||||
</div></a>
|
||||
);
|
||||
})
|
||||
}
|
||||
</WiaasBox>
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class CustomerAcceptance extends Component {
|
||||
{
|
||||
customerAcceptance.documents.map((document, index) => <div key={'acceptance-documnet-' + index}>
|
||||
<span className="document-link">
|
||||
<i className={'fa fa-file'}></i> <a target="_blank" href={document.url}> {document.name} </a>
|
||||
<i className={'fa fa-file'}></i> <a download href={document.url}> {document.name} </a>
|
||||
</span>
|
||||
<span className="document-status">
|
||||
{document.validation} <div className={'status-icon ' + document.validation}></div>
|
||||
|
||||
@@ -48,7 +48,7 @@ class ValidateQuestionnaireItem extends Component {
|
||||
<div>
|
||||
|
||||
<span className="document-link">
|
||||
<i className={'fa fa-file'}></i> <a target="_blank" href={document.url}> {document.name} </a>
|
||||
<i className={'fa fa-file'}></i> <a download href={document.url}> {document.name} </a>
|
||||
</span>
|
||||
<br />
|
||||
<span className="document-status">
|
||||
@@ -79,7 +79,7 @@ class ValidateQuestionnaireItem extends Component {
|
||||
<Row>
|
||||
<Col>
|
||||
<span className="document-link">
|
||||
<i className={'fa fa-file'}></i> <a target="_blank" href={document.url}> {document.name} </a>
|
||||
<i className={'fa fa-file'}></i> <a download href={document.url}> {document.name} </a>
|
||||
</span>
|
||||
<br />
|
||||
<span className="document-status">
|
||||
|
||||
@@ -43,7 +43,10 @@ export const fromWCOrder = (WCOrder) => {
|
||||
email: WCOrder.billing.email,
|
||||
address: formatAddress(WCOrder.billing)
|
||||
},
|
||||
documents: WCOrder.documents || [],
|
||||
documents: WCOrder.documents ? WCOrder.documents.map(document => {
|
||||
document.icon = getDocumentIcon(document.extension);
|
||||
return document;
|
||||
}) : [],
|
||||
packages: WCOrder['line_items'].map(packageLine => {
|
||||
return {
|
||||
id: packageLine['product_id'],
|
||||
|
||||
Reference in New Issue
Block a user