delivery step actions
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Order_Fields {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'gform_field_standard_settings', array( __CLASS__, 'field_settings' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom settings for form order fields
|
||||
*
|
||||
* @param int $position
|
||||
*/
|
||||
public static function field_settings( $position ) {
|
||||
if ( $position === 20 ) {
|
||||
// After Field description setting.
|
||||
?>
|
||||
|
||||
<li class="wiaas_doc_type_filter field_setting">
|
||||
|
||||
<label for="wiaas-doc-type-filter" class="section_label">
|
||||
<?php esc_html_e( 'Document Type', 'wiaas' ); ?>
|
||||
</label>
|
||||
<select id="wiaas-doc-type-filter" onchange="SetFieldProperty('wiaasDocTypeFilter',this.value);">
|
||||
<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="customer_acceptance"><?php esc_html_e( 'Customer acceptance', 'wiaas' ); ?></option>
|
||||
</select>
|
||||
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_value_from_order_field($entry, $field) {
|
||||
|
||||
switch ($field->type) {
|
||||
|
||||
case 'wiaas_order_bundle':
|
||||
$value = $entry[$field->id];
|
||||
list ($order_id, $item_id) = explode('|', $value);
|
||||
|
||||
if ( ! empty($order_id) && ! empty($item_id)) {
|
||||
|
||||
return array(
|
||||
'id' => $item_id,
|
||||
'name' => $field->get_selected_bundle_display_name($value)
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
case '':
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
$entry = array();
|
||||
|
||||
foreach ($form['fields'] as $field) {
|
||||
|
||||
switch ($field->type) {
|
||||
|
||||
case 'wiaas_order':
|
||||
|
||||
$entry[(string) $field->id] = $order->get_id();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle':
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($bundle_item)) {
|
||||
|
||||
$entry[(string) $field->id] = $order->get_id() . '|' . $bundle_item->get_id();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle_document':
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($bundle_item)) {
|
||||
|
||||
$documents = wiaas_get_order_item_documents($bundle_item, $field->wiaasDocTypeFilter);
|
||||
|
||||
if ( empty($documents) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($documents)) {
|
||||
|
||||
$document = $documents[0];
|
||||
|
||||
$entry[$field->id] = $document['version'];
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Order_Fields::init();
|
||||
Reference in New Issue
Block a user