Enable admin to enter installation date on delivery process:
:
This commit is contained in:
@@ -24,6 +24,18 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
|
||||
parent::init();
|
||||
|
||||
add_filter( 'gform_enqueue_scripts', array( $this, 'filter_gform_enqueue_scripts' ) );
|
||||
}
|
||||
|
||||
public function filter_gform_enqueue_scripts( ) {
|
||||
|
||||
wp_enqueue_script( 'gform_datepicker_init' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
|
||||
*
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Field_Order_Bundle_Installation_Date extends GF_Field_Date {
|
||||
|
||||
public $type ='wiaas_order_bundle_installation_date';
|
||||
|
||||
public $inputType = 'date';
|
||||
|
||||
public $dateType = 'datepicker';
|
||||
|
||||
public function get_input_type() {
|
||||
return 'date';
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Bundle Install Date', 'wiaas' );
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GF_Fields::register( new Wiaas_Field_Order_Bundle_Installation_Date() );
|
||||
@@ -76,6 +76,33 @@ class Wiaas_Order_Fields {
|
||||
// save changes to order
|
||||
switch ($field->type) {
|
||||
|
||||
case 'wiaas_order_bundle_installation_date':
|
||||
/**
|
||||
* Persist bundle installation date
|
||||
*/
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
error_log($new_value);
|
||||
|
||||
$bundle_item->update_meta_data('wiaas_installation_date', $new_value);
|
||||
$bundle_item->save_meta_data();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle_document':
|
||||
/**
|
||||
* Persist delivery flow documents for bundle
|
||||
@@ -171,7 +198,7 @@ class Wiaas_Order_Fields {
|
||||
|
||||
$selected_installation = $field->get_selected_installation($new_value);
|
||||
|
||||
if (empty($selected_installation)) {
|
||||
if ( empty($selected_installation) ) {
|
||||
// no installation selected
|
||||
continue;
|
||||
}
|
||||
@@ -394,6 +421,14 @@ class Wiaas_Order_Fields {
|
||||
return false;
|
||||
}
|
||||
|
||||
// installation is already selected
|
||||
if (!empty($bundle_item->get_meta('wiaas_installation', true))) {
|
||||
|
||||
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $bundle_item->get_meta('wiaas_installation', true);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundled_items = wc_pb_get_bundled_order_items($bundle_item, $order);
|
||||
|
||||
$installation_items = array();
|
||||
@@ -408,7 +443,7 @@ class Wiaas_Order_Fields {
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($installation_items) && $field->isRequired) {
|
||||
if (empty($installation_items)) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user