Merge branch 'fixes' into 'development'

Fixes

See merge request saburly/wiaas/new-wiaas!71
This commit was merged in pull request #71.
This commit is contained in:
Bilal Catic
2018-11-19 10:15:26 +00:00
5 changed files with 61 additions and 53 deletions

View File

@@ -473,8 +473,8 @@ class Wiaas_Cart {
'_wiaas_supplier_organization_id',
'_wiaas_product_price',
'_wiaas_earliest_installation_additional_days',
'wiaas_installation',
'wiaas_installation_date'
'_wiaas_installation',
'_wiaas_installation_date'
) );
}

View File

@@ -88,12 +88,15 @@ class Wiaas_Delivery_Process_Step_Assignee {
$mapped_assignees = array();
$order_id = self::get_order_id_for_step($step);
$order_id = self::_get_order_id_for_step($step);
$order = wc_get_order($order_id);
foreach ($assignees as $assignee) {
/**
* Handle step assignee for installation company field
*/
if (strpos($assignee->get_type(), 'wiaas_installation_') !== false) {
$item_id = $assignee->get_id();
@@ -120,11 +123,15 @@ class Wiaas_Delivery_Process_Step_Assignee {
continue;
}
/**
* Handle step assignee for order role
*/
if ($assignee->get_type() === 'wiaas_order_role') {
$order_role = $assignee->get_id();
// Assign step to order customer
if ($order_role === 'customer') {
$customer_user_id = $order->get_customer_id();
@@ -157,7 +164,7 @@ class Wiaas_Delivery_Process_Step_Assignee {
* @return bool|int Order id on success, false if step does not have associated order id
*
*/
public static function get_order_id_for_step(Gravity_Flow_Step $step) {
private static function _get_order_id_for_step(Gravity_Flow_Step $step) {
$entry = $step->get_entry();

View File

@@ -23,7 +23,7 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
$settings_api = $this->get_common_settings_api();
$forms = $this->get_action_forms_choices();
$forms = Wiaas_Delivery_Process_Action::get_action_forms();
$form_choices[] = array( 'label' => esc_html__( 'Select a Form', 'wiaas' ), 'value' => '' );
foreach ( $forms as $form ) {
@@ -86,8 +86,18 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return $label;
}
/**
* Update status
*
* @param bool $status
*/
public function update_step_status($status = false) {
/**
* If status is being updated after manual step completion ('Next Step' or 'Previous Step') change default
* behavior of settings status to cancelled if manual action is sending flow to next step.
* Instead of default cancelled status set complete status for this step.
*/
if ($status === 'cancelled' && $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' )) {
list( $base_admin_action, $step_id ) = rgexplode( '|', $admin_action, 2 );
@@ -104,10 +114,10 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
}
/**
* Process Wiass Delivery Process Step
*
* Process Wiaas Delivery Process Step
*
*
* @return bool
* @return bool We will always return false because step will be completed only by manual user action
*/
function process() {
@@ -198,28 +208,22 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return $entry_meta;
}
/**
* Retrieves forms that are valid options for delivery step action
*
* PRIVATE
*
*/
/**
* Create action entry to trigger subworkflow
* @param $target_form
* @param $order_id
*
* @return array
*/
public function get_action_forms_choices() {
return Wiaas_Delivery_Process_Action::get_action_forms();
}
/**
* Retrieves target form entry id created when step was started
* @return int
*/
public function get_target_form_entry_id() {
$value = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id');
return absint($value);
}
private function _create_single_action_entry($target_form, $order_id) {
$action_entries_ids = array();
@@ -248,6 +252,14 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
}
/**
* Create action form entries for every bundle in order to trigger subworkflows
*
* @param $target_form
* @param $order_id
*
* @return array
*/
private function _create_per_bundle_action_entries($target_form, $order_id) {
$action_entries_ids = array();

View File

@@ -306,30 +306,16 @@ class Wiaas_Order_Fields {
}
}
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 '':
}
}
/**
* Create new entry for order delivery process action form
*
* @param int $order_id
* @param array $form
* @param int|null $bundle_item_id
*
* @return array|bool
*/
public static function map_order_to_entry($order_id, $form, $bundle_item_id = null) {
if (empty($form['fields']) ||
@@ -461,6 +447,7 @@ class Wiaas_Order_Fields {
$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

View File

@@ -20,7 +20,8 @@ class Wiaas_Document_Download {
}
/**
* Handle download for order documents by gravity flow steps
* Handle download of order documents by gravity flow steps for wordpress administration interface
*
*/
public static function admin_gf_order_document_download() {
@@ -44,6 +45,8 @@ class Wiaas_Document_Download {
}
/**
* Handle document download for wordpress administration interface
*
* Since only REST api uses JWT Authentication this endpoint will work only for users
* that are logged in directly to wordpress
*/
@@ -84,7 +87,8 @@ class Wiaas_Document_Download {
}
/**
* Download order other document (not binded to any bundle)
* Download order other document (not related to any order item)
*
* @param int $order_id
* @param string $document_key
*/
@@ -113,8 +117,6 @@ class Wiaas_Document_Download {
$file_path = wiaas_get_document_version_path($order_document['version']);
error_log($file_path);
if (!file_exists($file_path)) {
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
}