Handle assigment for order delivery flow
This commit is contained in:
@@ -9,6 +9,21 @@ class Wiaas_Order_Fields {
|
||||
public static function init() {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
public static function display_order_document_fields($file_path, $field) {
|
||||
|
||||
if ($field->type === 'wiaas_order_bundle_document') {
|
||||
|
||||
$field = new Wiaas_Field_Order_Bundle_Document();
|
||||
|
||||
return $field->get_download_url($file_path);
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,11 +45,20 @@ class Wiaas_Order_Fields {
|
||||
<option value="configuration"><?php esc_html_e( 'Configuration', 'wiaas' ); ?></option>
|
||||
<option value="order_questionaire"><?php esc_html_e( 'Order Questionaire', 'wiaas' ); ?></option>
|
||||
<option value="installation_protocol"><?php esc_html_e( 'Installation protocol', 'wiaas' ); ?></option>
|
||||
<option value="install_guide"><?php esc_html_e( 'Installation Guide', 'wiaas' ); ?></option>
|
||||
<option value="customer_acceptance"><?php esc_html_e( 'Customer acceptance', 'wiaas' ); ?></option>
|
||||
</select>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="wiaas_installation_organization_filter field_setting">
|
||||
<input type="checkbox" id="wiaas-installation-organization-filter"
|
||||
onclick="var value = jQuery(this).is(':checked'); SetFieldProperty('wiaasOnlyInstallationOrg', value);""/>
|
||||
<label for="wiaas-installation-organization-filter" class="inline">
|
||||
<?php esc_html_e( 'Only installation', 'wiaas' ); ?>
|
||||
</label>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -73,8 +97,6 @@ class Wiaas_Order_Fields {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
$entry = array();
|
||||
|
||||
foreach ($form['fields'] as $field) {
|
||||
@@ -87,8 +109,15 @@ class Wiaas_Order_Fields {
|
||||
|
||||
break;
|
||||
|
||||
case 'workflow_user':
|
||||
$entry[(string) $field->id] = $order->get_customer_id(); // save customer if needed
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle':
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
@@ -103,6 +132,8 @@ class Wiaas_Order_Fields {
|
||||
|
||||
case 'wiaas_order_bundle_document':
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
@@ -110,31 +141,80 @@ class Wiaas_Order_Fields {
|
||||
|
||||
if (! empty($bundle_item)) {
|
||||
|
||||
$documents = wiaas_get_order_item_documents($bundle_item, $field->wiaasDocTypeFilter);
|
||||
$documents = wiaas_get_standard_package_order_item_documents($order, $bundle_item_id);
|
||||
|
||||
if ( empty($documents) && $field->isRequired) {
|
||||
$filtered_documents = array();
|
||||
|
||||
foreach ($documents as $document) {
|
||||
|
||||
if ($document['type'] === $field->wiaasDocTypeFilter) {
|
||||
|
||||
$filtered_documents[] = $document;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty($filtered_documents) && $field->isRequired ) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($documents)) {
|
||||
if (! empty ($filtered_documents) && ! $field->multipleFiles) {
|
||||
|
||||
$document = $documents[0];
|
||||
$document = $filtered_documents[0];
|
||||
|
||||
$entry[$field->id] = $document['version'];
|
||||
|
||||
} else if (! empty ($filtered_documents) ) {
|
||||
|
||||
$versions = array();
|
||||
foreach ($filtered_documents as $filtered_document) {
|
||||
$versions[] = $filtered_document['version'];
|
||||
}
|
||||
|
||||
$entry[$field->id] = json_encode($versions);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_supplier':
|
||||
$suppliers = wiaas_get_order_suppliers($order);
|
||||
case 'wiaas_order_installation_select':
|
||||
|
||||
$supplier_ids = array_keys($suppliers);
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
$supplier_id = $supplier_ids[0];
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
$entry[(string) $field->id] = 'wiaas_organization_order_' . $order_id . '|' . $supplier_id;
|
||||
$bundled_items = wc_pb_get_bundled_order_items($bundle_item, $order);
|
||||
|
||||
$installation_items = array();
|
||||
|
||||
foreach ($bundled_items as $id => $bundled_item) {
|
||||
|
||||
$product = $bundled_item->get_product();
|
||||
|
||||
if ($product && Wiaas_Product_Category::is_installation($product)) {
|
||||
|
||||
$installation_items[] = $bundled_item;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($installation_items) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($installation_items) === 1) {
|
||||
|
||||
$installation_item = $installation_items[0];
|
||||
|
||||
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $installation_item->get_id();
|
||||
} else if (count($installation_items) > 1) {
|
||||
|
||||
// force admin to select installation
|
||||
$entry[(string) $field->id] = '0';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user