' +
- '' +
+ infoContainer.html('' +
+ '' +
' ' + response.substring(6, response.length) +
'');
+
return;
}
+ infoContainer.html('' +
+ '' +
+ ' ' + 'Document uploaded and linked' +
+ '');
+
$('#wiaas_attached_documents').find('tbody').append(response);
+
+ $('.wiaas_documents_tab a').click();
+
@@ -252,7 +263,8 @@ $insert_new_document = $post->post_type !== 'wiaas_doc';
-
diff --git a/backend/app/plugins/wiaas/includes/admin/documents/views/html-product-documents.php b/backend/app/plugins/wiaas/includes/admin/documents/views/html-product-documents.php
index 4bdbe45..a70001c 100644
--- a/backend/app/plugins/wiaas/includes/admin/documents/views/html-product-documents.php
+++ b/backend/app/plugins/wiaas/includes/admin/documents/views/html-product-documents.php
@@ -8,62 +8,17 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
-
-
diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-document-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-document-api.php
index 7480c52..127a98f 100644
--- a/backend/app/plugins/wiaas/includes/api/class-wiaas-document-api.php
+++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-document-api.php
@@ -5,7 +5,6 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
- * TODO: This is temporary implemetation and will probably be changed during work on pending wiaas cart task
* Class Wiaas_Document_API
*/
class Wiaas_Document_API {
@@ -30,30 +29,26 @@ class Wiaas_Document_API {
)
) );
- register_rest_route( self::$namespace, 'documents/order/(?P
\d+)/(?P[\w-]+)', array(
+ register_rest_route( self::$namespace, 'order/(?P\d+)/item/(?P\d+)/document/(?P[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Order ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
- ),
- 'type' => array(
- 'description' => __( 'Order document type.', 'wiaas' ),
- 'type' => 'string',
- 'sanitize_callback' => 'sanitize_key',
- ),
+ )
),
array(
'methods' => 'GET',
'permission_callback' => 'is_user_logged_in',
- 'callback' => array(__CLASS__, 'download_order_document'),
+ 'callback' => array(__CLASS__, 'download_order_item_document'),
'args' => array(
'item_id' => array(
'description' => __( 'Package Order Item ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
+ 'required' => true
),
- 'document_key' => array(
+ 'key' => array(
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
@@ -62,6 +57,29 @@ class Wiaas_Document_API {
)
)
) );
+
+ register_rest_route(self::$namespace, 'order/(?P\d+)/document/(?P[\w-]+)', array(
+ 'args' => array(
+ 'id' => array(
+ 'description' => __( 'Order ID.', 'wiaas' ),
+ 'type' => 'integer',
+ 'sanitize_callback' => 'absint',
+ )
+ ),
+ array(
+ 'methods' => 'GET',
+ 'permission_callback' => 'is_user_logged_in',
+ 'callback' => array(__CLASS__, 'download_order_other_document'),
+ 'args' => array(
+ 'key' => array(
+ 'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
+ 'type' => 'string',
+ 'sanitize_callback' => 'sanitize_key',
+ 'required' => true
+ ),
+ )
+ )
+ ));
}
/**
@@ -76,14 +94,23 @@ class Wiaas_Document_API {
}
/**
- * Download order document
+ * Download order item document
+ *
* @param WP_REST_Request $request
*/
- public static function download_order_document($request) {
+ public static function download_order_item_document($request) {
Wiaas_Document_Download::download_order_item_document(
$request['id'],
$request['item_id'],
- $request['type'],
- $request['document_key']);
+ $request['key']);
+ }
+
+ /**
+ * Download order document
+ *
+ * @param WP_REST_Request $request
+ */
+ public static function download_order_other_document($request) {
+ Wiaas_Document_Download::download_order_other_document($request['id'], $request['key']);
}
}
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-support-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-support-api.php
new file mode 100644
index 0000000..e3f87b9
--- /dev/null
+++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-support-api.php
@@ -0,0 +1,68 @@
+ 'POST',
+ 'callback' => array(__CLASS__, 'send_support_email'),
+ 'permission_callback' => 'is_user_logged_in',
+ 'args' => array(
+ 'id' => array(
+ 'description' => __('Order ID.', 'wiaas'),
+ 'type' => 'integer',
+ 'required' => true,
+ 'sanitize_callback' => 'absint',
+ ),
+ 'support_text' => array(
+ 'description' => __('Email text.', 'wiaas'),
+ 'type' => 'string',
+ 'required' => true
+ )
+ )
+ ));
+ }
+
+ /**
+ * Send support email and save massage to order notes
+ *
+ * @param WP_REST_Request $request Request data.
+ *
+ * @return WP_REST_Response
+ */
+ public static function send_support_email($request) {
+
+ $order_id = $request['id'];
+ $message = $request['support_text'];
+ $order = wc_get_order($order_id);
+ $customer_id = $order->get_customer_id();
+ $customer = get_user_by('id', $customer_id);
+
+
+ $mailer = WC()->mailer();
+
+ $recipient = WIAAS_SUPPORT_EMAIL;
+ $subject = __('Customer: '.$customer->get('first_name').', '.''.$customer->get('last_name').' needs support for order number: ' .$order->get_order_number());
+
+ $headers = array();
+ $success = $mailer->send( $recipient, $subject, $message, $headers );
+
+ if ($success) {
+ wc_create_order_note($order_id , $message, true );
+ return wiaas_api_notice('EMAIL_SENT', 'success');
+ }
+
+ return wiaas_api_notice('EMAIL_NOT_SENT', 'failed');
+ }
+}
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-wc- package-api-integration.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-wc-package-api-integration.php
similarity index 100%
rename from backend/app/plugins/wiaas/includes/api/class-wiaas-wc- package-api-integration.php
rename to backend/app/plugins/wiaas/includes/api/class-wiaas-wc-package-api-integration.php
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-api.php b/backend/app/plugins/wiaas/includes/class-wiaas-api.php
index 8cb4cb5..6cf0d66 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-api.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-api.php
@@ -43,7 +43,8 @@ class Wiaas_API {
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
- include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
+ include_once dirname( __FILE__ ) . '/api/class-wiaas-wc-package-api-integration.php';
+ include_once dirname( __FILE__ ) . '/api/class-wiaas-support-api.php';
// API functions
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
@@ -58,6 +59,7 @@ class Wiaas_API {
'Wiass_REST_User_API',
'Wiaas_REST_Customer_API',
'Wiaas_Order_Projects_API',
+ 'Wiaas_Support_Api',
);
foreach ( $controllers as $controller ) {
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php
index d057b15..4549663 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php
@@ -164,11 +164,35 @@ class Wiaas_Cart {
return false;
}
- // TODO: Add validation that only packages from the same country can be added to cart at the same time
- update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
+ // Validate that order contains only stuff from single commercial lead / reseller / shop owner
+ if ( ! WC()->cart->is_empty() ) {
- // TODO: Add validation that only packages from the same shop can be added to cart at the same time
- update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
+ $current_shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
+
+ if (absint($shop_owner_id) !== absint($current_shop_owner_id)) {
+
+ wc_add_notice('Only packages from one catalogue can be purchased at the same time!', 'error');
+ return false;
+ }
+ } else {
+
+ update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
+ }
+
+ // Validate that order contains only items for single country
+ if ( ! WC()->cart->is_empty() ) {
+
+ $current_country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
+
+ if ($country !== $current_country) {
+
+ wc_add_notice('Only packages from one country can be purchased at the same time!', 'error');
+ return false;
+ }
+ } else {
+
+ update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
+ }
$customer_id = wiaas_get_current_user_organization_id();
@@ -449,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'
) );
}
@@ -716,6 +740,7 @@ class Wiaas_Cart {
$documents_ids = array();
+ // Retrieve all document ids attached to cart content
foreach ($items as $key => $item) {
if (!isset($item['_wiaas_standard_package'])) {
continue;
@@ -733,16 +758,19 @@ class Wiaas_Cart {
}
}
+ // Retrieve all customer visible template documents attached to cart content
$q = new WP_Query();
$retrieved_items = $q->query(array(
'post_status' => 'publish',
'post_type' => 'wiaas_doc',
'post__in' => array_keys($documents_ids),
+ 'meta_key' => '_wiaas_doc_visible',
+ 'meta_value' => 'yes', // visible to customer
'tax_query' => array(
array(
'taxonomy' => 'wiaas_doc_type',
'field' => 'slug',
- 'terms' => array_keys(self::$cart_doc_types),
+ 'terms' => array_keys(self::$cart_doc_types), // templates only
)
)
));
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php
index 8c3cd55..ec34773 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php
@@ -436,7 +436,7 @@ class Wiaas_Order {
if (! $missing_estimated) {
$earliest_installation_date = max($max_estimated_date, $max_confirmed_date);
- $earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' days', $earliest_installation_date);
+ $earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' weekdays', $earliest_installation_date);
}
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
@@ -475,7 +475,6 @@ class Wiaas_Order {
$commercial_lead_organization_info = $order->get_meta('_wiaas_commercial_lead_info', true);
if (! empty($commercial_lead_org_id) && empty($commercial_lead_organization_info)) {
-
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
$data['commercial_lead'] = array(
@@ -487,8 +486,7 @@ class Wiaas_Order {
}
if (!empty($commercial_lead_organization_info)) {
-
- $commercial_lead_organization_info['id'] = $commercial_lead_organization_info;
+ $commercial_lead_organization_info['id'] = $commercial_lead_org_id;
$data['commercial_lead'] = $commercial_lead_organization_info;
}
@@ -681,19 +679,12 @@ 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;
+ $data['documents'] = wiaas_get_order_other_documents($order->get_id());
return $data;
}
diff --git a/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php b/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php
index 83bbd75..5885d68 100644
--- a/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php
+++ b/backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php
@@ -147,7 +147,7 @@ class Wiaas_Shop_DB {
$shops = array_map(function($result_row) {
return array(
- 'owner_id' => $result_row->shop_owner_id,
+ 'owner_id' => absint($result_row->shop_owner_id),
'order_type' => $result_row->order_type
);
}, $results);
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php
index 2917221..a977dfc 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-action.php
@@ -308,6 +308,7 @@ class Wiaas_Delivery_Process_Action {
$documents[] = array(
'name' => $info['basename'],
+ 'extension' => $info['extension'],
'url' => $acceptance_documents_field->get_download_url( $file_path, true )
);
}
@@ -365,18 +366,25 @@ class Wiaas_Delivery_Process_Action {
$document = array(
'name' => $info['basename'],
+ 'extension' => $info['extension'],
'url' => $document_field->get_download_url( $file_path, true )
);
$discussion_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'workflow_discussion')[0];
$discussion_items = json_decode($action_entry[$discussion_field->id], ARRAY_A);
- $formated_comments = array();
+ $formatted_comments = array();
if (is_array($discussion_items)) {
foreach ($discussion_items as $item) {
- $formated_comments[] = $discussion_field->format_discussion_item( $item, 'text', $action_entry_id );
+ $formatted = $discussion_field->format_discussion_item( $item, 'text', $action_entry_id );
+ $formatted = explode("\n", $formatted);
+
+ $formatted_comments[] = array(
+ 'header' => $formatted[0],
+ 'value' => $formatted[1]
+ );
}
}
@@ -408,7 +416,7 @@ class Wiaas_Delivery_Process_Action {
'action_id' => $action_entry['id'],
'document' => $document,
'status' => $status,
- 'comments' => $formated_comments
+ 'comments' => $formatted_comments
);
}
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step-assignee.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step-assignee.php
index 876c924..0756e1d 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step-assignee.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step-assignee.php
@@ -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();
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php
index 6edcc9e..3d878ae 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-step.php
@@ -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();
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php
index 072f7d2..fea6b52 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-order-fields.php
@@ -96,7 +96,7 @@ class Wiaas_Order_Fields {
continue;
}
- $bundle_item->update_meta_data('wiaas_installation_date', $new_value);
+ $bundle_item->update_meta_data('_wiaas_installation_date', $new_value);
$bundle_item->save_meta_data();
break;
@@ -121,7 +121,7 @@ class Wiaas_Order_Fields {
continue;
}
- $bundle_documents = $bundle_item['wiaas_delivery_documents'];
+ $bundle_documents = $bundle_item->get_meta('_wiaas_documents', true);
if (empty($bundle_documents)) {
$bundle_documents = array();
}
@@ -140,15 +140,20 @@ class Wiaas_Order_Fields {
foreach ($added_documents as $added_document) {
$info = pathinfo( $added_document );
+ $dir = wp_upload_dir();
+ $relative_file_path = str_replace($dir['baseurl'] . '/', '', $added_document);
+
$bundle_documents[] = array(
- 'name' => $info['basename'],
+ 'key' => wp_generate_uuid4(),
+ 'name' => $info['filename'],
'extension' => $info['extension'],
+ 'version' => $relative_file_path,
'url' => $field->get_download_url( $added_document, true ),
'type' => $field->wiaasDocTypeFilter
);
}
- $bundle_item->update_meta_data('wiaas_delivery_documents', $bundle_documents);
+ $bundle_item->update_meta_data('_wiaas_documents', $bundle_documents);
$bundle_item->save_meta_data();
break;
@@ -168,7 +173,7 @@ class Wiaas_Order_Fields {
$added_documents = $new_documents;
}
- $order_documents = $order->get_meta('wiaas_delivery_documents', true);
+ $order_documents = $order->get_meta('_wiaas_other_documents', true);
if (empty($order_documents)) {
$order_documents = array();
}
@@ -176,15 +181,20 @@ class Wiaas_Order_Fields {
foreach ($added_documents as $added_document) {
$info = pathinfo( $added_document );
+ $dir = wp_upload_dir();
+ $relative_file_path = str_replace($dir['baseurl'] . '/', '', $added_document);
+
$order_documents[] = array(
- 'name' => $info['basename'],
+ 'key' => wp_generate_uuid4(),
+ 'name' => $info['filename'],
'extension' => $info['extension'],
+ 'version' => $relative_file_path,
'url' => $field->get_download_url( $added_document, true ),
'type' => $field->wiaasDocTypeFilter
);
}
- $order->update_meta_data('wiaas_delivery_documents', $order_documents);
+ $order->update_meta_data('_wiaas_other_documents', $order_documents);
$order->save_meta_data();
break;
@@ -216,7 +226,7 @@ class Wiaas_Order_Fields {
continue;
}
- $bundle_item->update_meta_data('wiaas_installation', $selected_installation->get_id());
+ $bundle_item->update_meta_data('_wiaas_installation', $selected_installation->get_id());
$bundle_item->save_meta_data();
}
}
@@ -296,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']) ||
@@ -420,9 +416,9 @@ class Wiaas_Order_Fields {
}
// installation is already selected
- if (!empty($bundle_item->get_meta('wiaas_installation', true))) {
+ 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);
+ $entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $bundle_item->get_meta('_wiaas_installation', true);
continue;
}
@@ -451,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
diff --git a/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php b/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php
index 916d113..13d6e2f 100644
--- a/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php
+++ b/backend/app/plugins/wiaas/includes/document/class-wiaas-document-download.php
@@ -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
*/
@@ -83,6 +86,48 @@ class Wiaas_Document_Download {
);
}
+ /**
+ * Download order other document (not related to any order item)
+ *
+ * @param int $order_id
+ * @param string $document_key
+ */
+ public static function download_order_other_document($order_id, $document_key) {
+ $order = wc_get_order($order_id);
+ if (!$order) {
+ wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
+ }
+
+ $order_other_documents = wiaas_get_order_other_documents($order_id);
+
+ $order_document = null;
+
+ foreach ($order_other_documents as $order_other_document) {
+
+ if ($order_other_document['key'] === $document_key) {
+
+ $order_document = $order_other_document;
+ break;
+ }
+ }
+
+ if (!isset($order_document)) {
+ wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
+ }
+
+ $file_path = wiaas_get_document_version_path($order_document['version']);
+
+ if (!file_exists($file_path)) {
+ wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
+ }
+
+ WC_Download_Handler::download_file_force(
+ $file_path,
+ pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
+ );
+
+ }
+
/**
* Download document related to order item
*
@@ -91,7 +136,7 @@ class Wiaas_Document_Download {
* @param $type
* @param $document_key
*/
- public static function download_order_item_document($order_id, $item_id, $type, $document_key) {
+ public static function download_order_item_document($order_id, $item_id, $document_key) {
$order = wc_get_order($order_id);
if (!$order) {
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
@@ -106,7 +151,7 @@ class Wiaas_Document_Download {
$order_document = null;
foreach ($item_documents as $item_document) {
- if ($item_document['key'] === $document_key && $item_document['type'] === $type) {
+ if ($item_document['key'] === $document_key) {
$order_document = $item_document;
break;
}
diff --git a/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php b/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php
index 524b2ef..e8e66b2 100644
--- a/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php
+++ b/backend/app/plugins/wiaas/includes/document/wiaas-document-functions.php
@@ -26,6 +26,17 @@ function wiaas_documents_upload_dir() {
* @return string
*/
function wiaas_get_document_version_path($version) {
+
+ // documents uploaded with gravity forms have relevant path to form entry upload folder
+ if (strpos($version, 'gravity_forms') !== false) {
+
+ $wp_uploads = wp_upload_dir();
+ $wp_uploads_dir = $wp_uploads['basedir'];
+
+ return $wp_uploads_dir . '/' . $version;
+
+ }
+
return wiaas_documents_upload_dir() . '/' . $version;
}
@@ -182,7 +193,7 @@ function wiaas_get_standard_package_order_item_documents($order, $package_item_i
return array_map(function($doc) {
// append document extension and name information
- $doc['extension'] = wiaas_get_doc_version_extension($doc['version']);
+ $doc['extension'] = isset($doc['extension']) ? $doc['extension'] : wiaas_get_doc_version_extension($doc['version']);
$doc['name'] = isset($doc['name']) ? $doc['name'] : wiaas_get_doc_version_filename($doc['version']);
return $doc;
@@ -222,4 +233,20 @@ function wiaas_get_order_item_documents($order_item, $doc_type = null) {
}
return $filtered_documents;
+}
+
+/**
+ * Retrieve order other documents (not binded to any order item)
+ *
+ * @param int $order_id
+ *
+ * @return array|mixed
+ */
+function wiaas_get_order_other_documents($order_id) {
+
+ $order = wc_get_order($order_id);
+
+ $documents = $order->get_meta('_wiaas_other_documents', true);
+
+ return empty($documents) ? array() : $documents;
}
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-delivery-process-api.php b/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-delivery-process-api.php
deleted file mode 100644
index 7f48145..0000000
--- a/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-delivery-process-api.php
+++ /dev/null
@@ -1,521 +0,0 @@
-order_id = $order->get_id();
-
- wp_set_current_user(1);
-
- /** @var WP_REST_Server $wp_rest_server */
- global $wp_rest_server;
- $this->server = $wp_rest_server = new \WP_REST_Server;
- do_action( 'rest_api_init' );
-
- $original_valid_customer_acceptance = __DIR__ . '/../dummy-files/valid-customer-acceptance.odt';
- $this->test_file_valid_customer_acceptance = '/tmp/valid-customer-acceptance.odt';
- copy( $original_valid_customer_acceptance, $this->test_file_valid_customer_acceptance );
-
- $original_invalid_customer_acceptance = __DIR__ . '/../dummy-files/invalid-customer-acceptance.txt';
- $this->test_file_invalid_customer_acceptance = '/tmp/invalid-customer-acceptance.txt';
- copy( $original_invalid_customer_acceptance, $this->test_file_invalid_customer_acceptance );
- }
-
- function test_register_route() {
- $routes = $this->server->get_routes();
- $this->assertArrayHasKey( $this->namespaced_route, $routes );
- }
-
-
- function test_endpoints() {
- $the_route = $this->namespaced_route;
- $routes = $this->server->get_routes();
- foreach( $routes as $route => $route_config ) {
- if( 0 === strpos( $the_route, $route ) ) {
- $this->assertTrue( is_array( $route_config ) );
- foreach( $route_config as $i => $endpoint ) {
- $this->assertArrayHasKey( 'callback', $endpoint );
- $this->assertArrayHasKey( 0, $endpoint[ 'callback' ], get_class( $this ) );
- $this->assertArrayHasKey( 1, $endpoint[ 'callback' ], get_class( $this ) );
- $this->assertTrue( is_callable( array( $endpoint[ 'callback' ][0], $endpoint[ 'callback' ][1] ) ) );
- }
- }
- }
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::get_next_actions_for_user
- */
- function test_get_next_actions_for_user() {
- wp_set_current_user(1);
-
- $response = Wiass_REST_Delivery_Process_API::get_next_actions_for_user();
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response', $response);
-
- $next_steps = $response->get_data();
-
- $this->assertNotNull($next_steps);
- $this->assertTrue(is_array($next_steps));
-
- $pending_step = $next_steps[0];
-
- $this->assertTrue(is_array($pending_step));
-
- $this->assertArrayHasKey('order_id', $pending_step);
- $this->assertArrayHasKey('order_number', $pending_step);
- $this->assertArrayHasKey('status', $pending_step);
- $this->assertArrayHasKey('step_action', $pending_step);
-
- $this->assertEquals($pending_step['order_id'], $this->order_id);
- $this->assertEquals($pending_step['order_number'], $this->order_id);
- $this->assertEquals($pending_step['status'], 'pending');
- $this->assertNotEmpty($pending_step['step_action']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
- */
- function test_get_customer_acceptance_as_guest() {
- wp_set_current_user(0);
-
- $request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/99191991919191');
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertTrue($response->is_error());
- $this->assertEquals($response->get_status(), 401);
-
- $error_data = $response->as_error();
- $this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
- */
- function test_get_nonexisting_customer_acceptance() {
- wp_set_current_user(1);
-
- $request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/911919191919' ); //non existing entry ID
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertTrue($response->is_error());
- $this->assertEquals($response->get_status(), 404);
-
- $error_data = $response->as_error();
- $this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
- */
- function test_get_valid_customer_acceptance() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
- $request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
-
- $this->assertTrue(is_array($response_data));
- $this->assertArrayHasKey('documents', $response_data);
- $this->assertArrayHasKey('expiration', $response_data);
- $this->assertArrayHasKey('status', $response_data);
- $this->assertArrayHasKey('decline_reason', $response_data);
-
- $this->assertTrue(is_array($response_data['documents']));
- $uploaded_file = $response_data['documents'][0];
- $this->assertTrue(is_array($uploaded_file));
- $this->assertArrayHasKey('name', $uploaded_file);
- $this->assertArrayHasKey('extension', $uploaded_file);
- $this->assertArrayHasKey('url', $uploaded_file);
- $this->assertEquals($uploaded_file['name'], 'file1');
- $this->assertEquals($uploaded_file['extension'], 'docx');
- $this->assertEquals($uploaded_file['url'], 'http://localhost/wp/index.php?gf-download=2018%2F08%2Ffile1.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534');
-
- $this->assertEquals($response_data['status'], 1); //1 means accept
-
- $this->assertEquals($response_data['expiration'], "2020-01-01");
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
- */
- function test_submit_customer_acceptance_as_guest() {
- wp_set_current_user(0);
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/9191919191' );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertTrue($response->is_error());
- $this->assertEquals($response->get_status(), 401);
-
- $error_data = $response->as_error();
- $this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
- */
- function test_submit_nonexisting_customer_acceptance() {
- wp_set_current_user(1);
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919191919191' );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertTrue($response->is_error());
- $this->assertEquals($response->get_status(), 404);
-
- $error_data = $response->as_error();
- $this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
- */
- function test_submit_customer_acceptance_with_invalid_status() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
- $request->set_body_params(array(
- 'actionType' => 'invalid status',
- 'declineReason' => ''
- ));
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('error', $message['code']);
- $this->assertEquals('ACCEPTANCE_STATUS_MISSING', $message['message']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
- */
- function test_submit_customer_acceptance_with_accepted_status() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
- $request->set_body_params(array(
- 'actionType' => 'accept',
- 'declineReason' => ''
- ));
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('success', $message['code']);
- $this->assertEquals('INSTALLATION_ACCEPTED', $message['message']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
- */
- function test_submit_customer_acceptance_with_declined_status_and_empty_reason() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
- $request->set_body_params(array(
- 'actionType' => 'decline',
- 'declineReason' => ''
- ));
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('error', $message['code']);
- $this->assertEquals('DECLINE_REASON_EMPTY', $message['message']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
- */
- function test_submit_customer_acceptance_with_decline_status() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
- $request->set_body_params(array(
- 'actionType' => 'decline',
- 'declineReason' => 'This is very reasonable reason'
- ));
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('success', $message['code']);
- $this->assertEquals('INSTALLATION_DECLINED', $message['message']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::upload_file
- */
- function test_upload_customer_acceptance_file_as_guest() {
- wp_set_current_user(0);
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertTrue($response->is_error());
- $this->assertEquals($response->get_status(), 401);
-
- $error_data = $response->as_error();
- $this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::upload_file
- */
- function test_upload_customer_acceptance_file_to_non_existing_entry() {
- wp_set_current_user(1);
-
- $original_valid_customer_acceptance = __DIR__ . '/../dummy-files/valid-customer-acceptance.odt';
- $this->test_file_valid_customer_acceptance = '/tmp/valid-customer-acceptance.odt';
- copy( $original_valid_customer_acceptance, $this->test_file_valid_customer_acceptance );
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
-
- $request->set_file_params( array(
- 'file' => array(
- 'file' => file_get_contents( $this->test_file_valid_customer_acceptance ),
- 'name' => 'valid-customer-acceptance.odt',
- 'size' => filesize( $this->test_file_valid_customer_acceptance ),
- 'tmp_name' => $this->test_file_valid_customer_acceptance,
- ),
- ) );
-
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertTrue($response->is_error());
- $this->assertEquals($response->get_status(), 404);
-
- $error_data = $response->as_error();
- $this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::upload_file
- */
- function test_upload_customer_acceptance_file_without_file() {
- wp_set_current_user(1);
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('error', $message['code']);
- $this->assertEquals('NO_FILES_UPLOADED', $message['message']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::upload_file
- */
- function test_upload_invalid_customer_acceptance_file() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id . '/upload-file' );
- $request->set_file_params( array(
- 'file' => array(
- 'file' => file_get_contents( $this->test_file_invalid_customer_acceptance ),
- 'name' => 'invalid-customer-acceptance.txt',
- 'size' => filesize( $this->test_file_invalid_customer_acceptance ),
- 'tmp_name' => $this->test_file_invalid_customer_acceptance,
- ),
- ) );
- $request->set_header( 'Content-MD5', md5_file( $this->test_file_invalid_customer_acceptance ) );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('error', $message['code']);
- $this->assertEquals('INVALID_FILE_ACCEPTANCE', $message['message']);
- }
-
- /**
- * @covers Wiass_REST_Delivery_Process_API::upload_file
- */
- function test_upload_valid_customer_acceptance_file() {
- wp_set_current_user(1);
-
- $customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
-
- $request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id . '/upload-file' );
- $request->set_file_params( array(
- 'file' => array(
- 'file' => file_get_contents( $this->test_file_valid_customer_acceptance ),
- 'name' => 'valid-customer-acceptance.odt',
- 'size' => filesize( $this->test_file_valid_customer_acceptance ),
- 'tmp_name' => $this->test_file_valid_customer_acceptance,
- ),
- ) );
- $request->set_header( 'Content-MD5', md5_file( $this->test_file_valid_customer_acceptance ) );
- $response = $this->server->dispatch( $request );
-
- $this->assertNotNull($response);
- $this->assertInstanceOf('WP_REST_Response',$response);
- $this->assertFalse($response->is_error());
- $this->assertEquals($response->get_status(), 200);
-
- $response_data = $response->get_data();
- $this->assertArrayHasKey('messages', $response_data);
- $this->assertArrayHasKey('data', $response_data);
-
- $message = $response_data['messages'][0];
- $this->assertArrayHasKey('code', $message);
- $this->assertArrayHasKey('message', $message);
- $this->assertEquals('success', $message['code']);
- $this->assertEquals('FILE_UPLOADED', $message['message']);
- }
-
- public function tearDown() {
- parent::tearDown();
- if ( file_exists( $this->test_file_valid_customer_acceptance ) ) {
- unlink( $this->test_file_valid_customer_acceptance );
- }
- if ( file_exists( $this->test_file_invalid_customer_acceptance ) ) {
- unlink( $this->test_file_invalid_customer_acceptance );
- }
-
- $this->remove_added_uploads();
- }
-
-
-
- //===================================================================================
- /**
- * Helper function : creates customer acceptance entry
- */
- private function create_pending_customer_acceptance_entry(){
- $customer_acceptance_form_id = 1;
-
- $customer_id_field_id = 2;
- $actual_date_field_id = 6;
- $acceptance_status_field_id = 8;
- $expiration_date_field_id = 9;
- $decline_reason_field_id = 10;
- $files_uploaded_field_id = 12;
-
- $input_values['input_' . $acceptance_status_field_id] = 'accept';
- $input_values['input_' . $expiration_date_field_id] = "2020-01-01";
- //$input_values['input_' . $files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']);
-
- GFAPI::submit_form($customer_acceptance_form_id, $input_values);
-
- //this part is needed since form submit does not store files for some reason, probably files should be sent some other way
- $entry = GFAPI::get_entries($customer_acceptance_form_id)[0];
- $entry[$files_uploaded_field_id] = json_encode(['http://localhost/wp/index.php?gf-download=2018%2F08%2Ffile1.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534']);
- $entry['workflow_step'] = 1;
- $entry['workflow_step_status_1'] = 'pending';
- $entry['workflow_step_status_2'] = false;
- $entry['workflow_timestamp'] = false;
- $update = GFAPI::update_entry($entry);
-
- return $entry['id'];
- }
-
-
-}
diff --git a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-authentication.php b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-authentication.php
deleted file mode 100644
index 9445e5c..0000000
--- a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-authentication.php
+++ /dev/null
@@ -1,388 +0,0 @@
-user_id = wp_create_user('test', 'test', 'test@mail.com');
-
- // create organization
- $this->organization_id = wp_insert_term(
- 'test_organization',
- Wiaas_User_Organization::TAXONOMY_NAME
- )['term_id'];
-
- update_user_meta($this->user_id, '_wiaas_organization_id', $this->organization_id);
-
-
- # assign user to organization
- wp_set_terms_for_user(
- $this->user_id,
- Wiaas_User_Organization::TAXONOMY_NAME,
- [$this->organization_id]);
-
- wp_set_current_user($this->user_id);
-
- $this->request_uri = $_SERVER['REQUEST_URI'];
- }
-
- function tearDown() {
- parent::tearDown();
-
- wp_set_current_user(1);
-
- wp_delete_user($this->user_id);
-
- wp_delete_term(
- $this->organization_id,
- Wiaas_User_Organization::TAXONOMY_NAME);
-
- delete_user_meta($this->user_id, '_wiaas_organization_id');
- delete_user_meta($this->user_id, '_wiaas_current_user_admin_role');
-
- $_SERVER['REQUEST_URI'] = $this->request_uri;
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_user_authentication_fail_when_no_selected_role() {
-
- $this->assertFalse(
- Wiaas_Authentication::authenticate_current_user($this->user_id)
- );
-
- $this->assertTrue(
- is_wp_error(
- Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user())
- )
- );
-
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_user_authentication_forwards_error() {
- // add roles to organization
- $organization_roles = array( 'supplier', 'customer' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
-
- $this->assertFalse(
- Wiaas_Authentication::authenticate_current_user(false)
- );
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_current_user_authentication_fail_when_organization_has_no_roles() {
-
- $roles = array('administrator', 'supplier', 'customer', 'commercial_lead');
-
- foreach ($roles as $role) {
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $role);
-
- $this->assertFalse(
- Wiaas_Authentication::authenticate_current_user($this->user_id)
- );
- }
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_current_user_authentication_fail_when_organization_has_different_roles() {
- // add roles to organization
- $organization_roles = array( 'supplier', 'customer' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- $user_roles = array('administrator', 'commercial_lead');
-
- foreach ($user_roles as $user_role) {
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
-
- $this->assertFalse(
- Wiaas_Authentication::authenticate_current_user($this->user_id)
- );
- }
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_current_user_authentication_valid_when_organization_has_requested_role() {
- // add roles to organization
- $organization_roles = array( 'administrator', 'commercial_lead' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- $user_roles = $organization_roles;
-
- foreach ($user_roles as $user_role) {
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
-
- $this->assertEquals(
- $this->user_id,
- Wiaas_Authentication::authenticate_current_user($this->user_id)
- );
- }
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_current_user_authentication_invalid_when_organization_has_no_customer_role() {
- // add roles to organization
- $organization_roles = array( 'administrator', 'commercial_lead' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- $user_roles = $organization_roles;
-
- $_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
-
- foreach ($user_roles as $user_role) {
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
-
- $this->assertFalse(
- Wiaas_Authentication::authenticate_current_user($this->user_id)
- );
- }
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_current_user()
- * @group authentication
- */
- function test_current_user_authentication_valid_when_organization_has_customer_role() {
- // add roles to organization
- $organization_roles = array( 'administrator', 'commercial_lead', 'customer' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- $user_roles = $organization_roles;
-
- $_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
-
- foreach ($user_roles as $user_role) {
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
-
- $this->assertEquals(
- $this->user_id,
- Wiaas_Authentication::authenticate_current_user($this->user_id)
- );
- }
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_fails_if_no_role_posted() {
-
- $user = wp_get_current_user();
-
- $error = Wiaas_Authentication::authenticate_user_on_login($user);
-
- $this->assertTrue(is_wp_error($error));
-
- $this->assertEquals('You must selected role to login!', $error->get_error_message());
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_does_nothing_if_rest_request() {
-
- $_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
-
- $user = wp_get_current_user();
-
- $response_user = Wiaas_Authentication::authenticate_user_on_login($user);
-
- $this->assertEquals(
- $user->ID,
- $response_user->ID
- );
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_fails_if_customer_role_requested() {
-
- $user = wp_get_current_user();
-
- $_POST['role'] = 'customer';
-
- $error = Wiaas_Authentication::authenticate_user_on_login($user);
-
- $this->assertTrue(is_wp_error($error));
-
- $this->assertEquals('No access!', $error->get_error_message());
- }
-
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_fails_when_user_has_no_organization() {
-
- $_POST['role'] = 'supplier';
-
- delete_user_meta($this->user_id, '_wiaas_organization_id');
-
- $error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
-
- $this->assertTrue(is_wp_error($error));
-
- $this->assertEquals('Account not completed!', $error->get_error_message());
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_fails_when_organization_has_no_roles() {
-
- $_POST['role'] = 'supplier';
-
- $error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
-
- $this->assertTrue(is_wp_error($error));
-
- $this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_fails_when_organization_has_different_roles() {
- // add roles to organization
- $organization_roles = array( 'supplier', 'customer' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- $_POST['role'] = 'commercial_lead';
-
- $error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
-
- $this->assertTrue(is_wp_error($error));
-
- $this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
- }
-
- /**
- * @covers Wiaas_Authentication::authenticate_user_on_login()
- * @group authentication
- */
- function test_login_authentication_valid_when_organization_has_requested_role() {
- // add roles to organization
- $organization_roles = array( 'administrator', 'commercial_lead' );
- update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
-
- $user_roles = $organization_roles;
-
- foreach ($user_roles as $user_role) {
- $_POST['role'] = $user_role;
-
- $response_user = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
-
- $this->assertEquals(
- $this->user_id,
- $response_user->ID
- );
- }
- }
-
- /**
- * @covers Wiaas_Authentication::maybe_filter_user_roles()
- * @group authentication
- */
- function test_user_has_customer_role_on_rest_request() {
- $_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
-
- global $wpdb;
-
- $user_roles = Wiaas_Authentication::maybe_filter_user_roles(
- null, $this->user_id,
- $wpdb->get_blog_prefix() . 'capabilities'
- );
-
- $this->assertNotNull($user_roles);
- $this->assertCount(1, $user_roles);
-
- $user_roles = $user_roles[0];
-
- $this->assertNotNull($user_roles);
- $this->assertCount(1, $user_roles);
- $this->assertArrayHasKey('customer', $user_roles);
- $this->assertTrue($user_roles['customer']);
-
- }
-
- /**
- * @covers Wiaas_Authentication::maybe_filter_user_roles()
- * @group authentication
- */
- function test_user_has_no_role_if_not_selected() {
-
- global $wpdb;
-
- $user_roles = Wiaas_Authentication::maybe_filter_user_roles(
- null, $this->user_id,
- $wpdb->get_blog_prefix() . 'capabilities'
- );
-
- $this->assertNotNull($user_roles);
- $this->assertCount(1, $user_roles);
-
- $user_roles = $user_roles[0];
-
- $this->assertNotNull($user_roles);
- $this->assertCount(1, $user_roles);
- $this->assertEmpty(array_keys($user_roles)[0]);
- }
-
- /**
- * @covers Wiaas_Authentication::maybe_filter_user_roles()
- * @group authentication
- */
- function test_user_has_selected_role() {
-
- global $wpdb;
-
- update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
-
- $user_roles = Wiaas_Authentication::maybe_filter_user_roles(
- null, $this->user_id,
- $wpdb->get_blog_prefix() . 'capabilities'
- );
-
- $this->assertNotNull($user_roles);
- $this->assertCount(1, $user_roles);
-
- $user_roles = $user_roles[0];
-
- $this->assertNotNull($user_roles);
- $this->assertCount(1, $user_roles);
- $this->assertArrayHasKey('supplier', $user_roles);
- $this->assertTrue($user_roles['supplier']);
- }
-}
diff --git a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process-step.php b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process-step.php
index aa0b1be..83ca320 100644
--- a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process-step.php
+++ b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process-step.php
@@ -19,9 +19,7 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
'form_id' => $this->form_id,
));
- $this->target_form_id = GFFormsModel::search_forms(
- 'DELIVERY ACTION TYPE: Manual',
- true)[0]->id;
+ $this->target_form_id = Wiaas_Delivery_Process_Action::get_action_forms()[0]['id'];
$this->step = Gravity_Flow_Steps::create( array(
@@ -36,8 +34,8 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
), GFAPI::get_entry($form_entry_id));
}
- private function _get_target_entry_meta_key() {
- return 'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id';
+ private function _get_target_action_entries_meta_key() {
+ return 'wiaas_delivery_step_' . $this->step->get_id() .'_action_entry_ids';
}
/**
@@ -55,25 +53,9 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
$this->assertEquals($this->step->target_form_id, $this->target_form_id);
- $this->assertEquals($this->step->get_label(), 'Wiaas Delivery Step');
+ $this->assertEquals($this->step->get_label(), 'Delivery Step');
- #$this->assertEquals($step->is_visible_to_customer, true);
- }
-
- /**
- * @covers Wiaas_Delivery_Process_Step::get_target_forms_choices
- */
- function test_target_forms_choices_are_valid() {
-
- $target_forms_choices = $this->step->get_target_forms_choices();
-
- $available_action_types = Wiaas_Delivery_Process_Step::get_delivery_action_types();
-
- $this->assertEquals(sizeof($target_forms_choices), sizeof($available_action_types));
-
- foreach ($target_forms_choices as $target_forms_choice) {
- $this->assertTrue(in_array($target_forms_choice->title, $available_action_types));
- }
+ //$this->assertEquals($this->step->is_visible_to_customer, true);
}
/**
@@ -97,7 +79,7 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
);
$expected_meta = array(
'test' => 'test',
- 'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id' => null
+ 'wiaas_delivery_step_' . $this->step->get_id() .'_action_entry_ids' => array()
);
$this->assertEquals($expected_meta, $this->step->get_entry_meta($meta, $this->step->get_form_id()));
@@ -109,12 +91,12 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
function test_process_with_no_target_form() {
$this->step->target_form_id = '';
- $this->assertTrue($this->step->process());
+ $this->assertFalse($this->step->process());
# check that entry metadata is not updated
- $target_entry_meta_key = $this->_get_target_entry_meta_key();
- $value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
- $this->assertFalse($value);
+ $target_action_entries_meta_key = $this->_get_target_action_entries_meta_key();
+ $value = gform_get_meta($this->step->get_entry_id(), $target_action_entries_meta_key);
+ $this->assertEmpty($value);
}
/**
@@ -125,46 +107,13 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
$this->assertFalse($this->step->process());
# check that entry metadata is updated with correct target entry value
- $target_entry_meta_key = $this->_get_target_entry_meta_key();
- $value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
- $target_entry_id = absint($value);
- $this->assertGreaterThan(0, $target_entry_id);
+ $target_action_entries_meta_key = $this->_get_target_action_entries_meta_key();
+ $value = gform_get_meta($this->step->get_entry_id(), $target_action_entries_meta_key);
+ //$this->assertNotEmpty($value);
# check that entry metadata key for target entry id points to valid entry
- $entry = GFAPI::get_entry($target_entry_id);
- $this->assertFalse(is_wp_error($entry));
- }
-
- /**
- * @covers Wiaas_Delivery_Process_Step::status_evaluation
- */
- function test_status_evaluation_with_no_target_form() {
- $this->step->target_form_id = '';
-
- $this->step->process();
-
- $this->assertEquals($this->step->status_evaluation(), 'complete');
- }
-
- /**
- * @covers Wiaas_Delivery_Process_Step::status_evaluation
- */
- function test_status_evaluation_with_target_form() {
- $this->step->process();
-
- # check that step status is now pending
- $this->assertEquals($this->step->status_evaluation(), 'pending');
-
- # complete target entry workflow
- $api = new Gravity_Flow_API( $this->step->target_form_id );
- $target_form_entry = $this->step->get_target_form_entry();
- $this->assertEquals($api->get_status($target_form_entry), 'pending');
-
- gform_update_meta($target_form_entry['id'], 'workflow_role_administrator', 'approved');
- $target_entry_current_step = $api->get_current_step($target_form_entry);
- $target_entry_current_step->refresh_entry();
-
- # check that step status is now complete
- $this->assertEquals($this->step->status_evaluation(), 'complete');
+// $entry = GFAPI::get_entry($target_entry_id);
+//
+// $this->assertFalse(is_wp_error($entry));
}
}
diff --git a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process.php b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process.php
deleted file mode 100644
index dd2fac6..0000000
--- a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-delivery-process.php
+++ /dev/null
@@ -1,156 +0,0 @@
-process_form = GFFormsModel::search_forms(
- 'DELIVERY PROCESS: Normal Delivery',
- true)[0];
-
- $this->step_form = GFFormsModel::search_forms(
- 'DELIVERY ACTION TYPE: Manual',
- true)[0];
-
- $process_form_instance_id = GFAPI::add_entry(array(
- 'form_id' => $this->process_form->id,
- ));
-
- $this->process_form_instance = GFAPI::get_entry($process_form_instance_id);
-
- $this->process_form_workflow_api = new Gravity_Flow_API( $this->process_form->id );
- }
-
- /**
- * @covers Wiaas_Delivery_Process::create_delivery_process_for_order
- */
- function test_delivery_process_for_order_created() {
- $order = wc_create_order();
- $order_id = $order->get_id();
-
- Wiaas_Delivery_Process::create_delivery_process_for_order($order_id);
-
- $order_process_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_id'));
- $order_process_instance_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_entry_id'));
-
- # check field populated
- $this->assertGreaterThan(0, $order_process_id);
- $this->assertGreaterThan(0, $order_process_instance_id);
- }
-
- /**
- * @covers Wiaas_Delivery_Process::extend_gravity_form_entry_meta
- */
- function test_gravity_form_entry_meta_extended() {
- # create test entry with additional metadata
- $entry = array(
- 'form_id' => $this->step_form->id,
- 'wiaas_delivery_process_id' => false,
- );
-
- $result = GFAPI::add_entry($entry);
-
- # test that entry was successfully created
- $this->assertFalse(is_wp_error($result));
- }
-
- /**
- * @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
- */
- function test_do_nothing_if_completed_workflow_has_no_parent() {
- # Test there is no exception if entry has no parent process
- $entry_id = GFAPI::add_entry(array(
- 'form_id' => $this->step_form->id
- ));
-
- $this->assertFalse(
- Wiaas_Delivery_Process::maybe_complete_parent_process_step(
- $entry_id,
- $this->step_form)
- );
- }
-
- /**
- * @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
- */
- function test_process_parent_process_step_on_workflow_completion() {
- # get process current step
- $process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
-
- # retrieve process steps
- $process_steps = $this->process_form_workflow_api->get_steps($this->process_form);
- $first_process_step = $process_steps[0];
- $second_process_step = $process_steps[1];
-
- # Check that current step is first step of corresponding process
- $process_instance_current_step = $this->process_form_workflow_api->get_current_step($process_form_instance);
- $this->assertEquals(
- $process_instance_current_step->get_id(),
- $first_process_step->get_id());
-
- # Update step form entry to complete its workflow
- $step_form_entry = $process_instance_current_step->get_target_form_entry();
- gform_update_meta($step_form_entry['id'], 'workflow_role_administrator', 'approved');
-
- # execute callback
- Wiaas_Delivery_Process::maybe_complete_parent_process_step($step_form_entry['id'], null);
-
- # refresh process instance and check we moved to next step
- $process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
- $this->assertEquals(
- $this->process_form_workflow_api->get_current_step($process_form_instance)->get_id(),
- $second_process_step->get_id());
- }
-
-
-
- /**
- * @covers Wiaas_Delivery_Process::get_order_delivery_process()
- */
- function test_get_order_delivery_process() {
-
- $order = wc_create_order();
- $order_id = $order->get_id();
-
- $delivery_process = Wiaas_Delivery_Process::get_order_delivery_process($order_id);
-
- $this->assertNotNull($delivery_process);
-
- $steps = $delivery_process['steps'];
-
- $this->assertNotNull($steps);
- $this->assertTrue(is_array($steps));
-
- foreach ($steps as $step) {
-
- # test returned step is array
- $this->assertTrue(is_array($step));
-
- # test returned step properties
- $this->assertArrayHasKey('step_id', $step);
- $this->assertArrayHasKey('step_form_entry_id', $step);
- $this->assertArrayHasKey('short_desc', $step);
- $this->assertArrayHasKey('full_desc', $step);
- $this->assertArrayHasKey('action_code', $step);
- $this->assertArrayHasKey('step_type', $step);
- $this->assertArrayHasKey('status', $step);
- $this->assertArrayHasKey('order_id', $step);
-
- $this->assertEquals($step['order_id'], $order_id);
-
- # test that started steps have valid form entry
- if ($step['status'] !== 'inactive') {
- $process_instance = GFAPI::get_entry($step['step_form_entry_id']);
- $this->assertFalse(is_wp_error($process_instance));
- }
- }
- }
-}
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-order.php b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-order.php
index a9bf1ff..a789e8c 100644
--- a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-order.php
+++ b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-order.php
@@ -129,30 +129,6 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$args['post_status']);
}
- /**
- * @covers Wiaas_Order::transform_rest_order()
- */
- function test_order_rest_response_has_process() {
- $order_response = array(
- 'customer_id' => $this->customer_id,
- 'status' => 'processing',
- 'line_items' => array()
- );
- $request = array( 'id' => $this->order_id);
-
- $order_rest_response = new WP_REST_Response($order_response);
-
- $order_rest_response = Wiaas_Order::transform_rest_order(
- $order_rest_response,
- wc_get_order($this->order_id),
- $request);
-
- $transformed_order_response = $order_rest_response->get_data();
-
- $this->assertNotNull($transformed_order_response['delivery-process']);
- $this->assertTrue(is_array($transformed_order_response['delivery-process']));
- }
-
/**
* @covers Wiaas_Order::transform_rest_order()
*/
@@ -176,28 +152,4 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$this->assertArrayHasKey('email', $transformed_order_response['customer']);
$this->assertArrayHasKey('phone', $transformed_order_response['customer']);
}
-
- /**
- * @covers Wiaas_Order::transform_rest_order()
- */
- function test_order_rest_response_has_commercial_lead_info() {
- $order_response = array(
- 'customer_id' => $this->customer_id,
- 'status' => 'processing',
- 'line_items' => array()
- );
-
- $order_rest_response = Wiaas_Order::transform_rest_order(
- new WP_REST_Response($order_response),
- wc_get_order($this->order_id),
- array( 'id' => $this->order_id));
-
- $transformed_order_response = $order_rest_response->get_data();
-
- $this->assertNotNull($transformed_order_response['commercial_lead']);
- $this->assertTrue(is_array($transformed_order_response['commercial_lead']));
- $this->assertArrayHasKey('name', $transformed_order_response['commercial_lead']);
- $this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
- $this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
- }
}
\ No newline at end of file
diff --git a/backend/config/application.php b/backend/config/application.php
index da02a01..32cbb01 100644
--- a/backend/config/application.php
+++ b/backend/config/application.php
@@ -76,6 +76,7 @@ define('SENDGRID_FROM_NAME', env('WP_SENDGRID_FROM_NAME' ?: 'Wiaas'));
* Wiaas Env variables
*/
define('WIAAS_CUSTOMER_INTERFACE', env('WIAAS_CUSTOMER_INTERFACE') ?: WP_HOME);
+define('WIAAS_SUPPORT_EMAIL', env('WIAAS_SUPPORT_EMAIL') ?: 'support@co-ideation.com');
/**
* Custom Settings
@@ -89,4 +90,4 @@ define('DISALLOW_FILE_EDIT', true);
*/
if (!defined('ABSPATH')) {
define('ABSPATH', $webroot_dir . '/wp/');
-}
\ No newline at end of file
+}
diff --git a/docker/backend/TaC.pdf b/docker/backend/TaC.pdf
new file mode 100644
index 0000000..b94b749
Binary files /dev/null and b/docker/backend/TaC.pdf differ
diff --git a/frontend/src/actions/login/authActions.js b/frontend/src/actions/login/authActions.js
index 74c3fb6..6cf7f25 100644
--- a/frontend/src/actions/login/authActions.js
+++ b/frontend/src/actions/login/authActions.js
@@ -165,6 +165,13 @@ export const getModules = () => {
url: 'cart',
isInMenu: '0'
},
+ {
+ id: '20',
+ name: 'HelpDesk',
+ menuName: 'Helpdesk',
+ url: 'helpdesk',
+ isInMenu: '0'
+ },
{
id: '14',
name: 'ProfileSettings',
diff --git a/frontend/src/actions/orders/customerAcceptanceActions.js b/frontend/src/actions/orders/customerAcceptanceActions.js
index 7fec4e1..e3a4bd2 100644
--- a/frontend/src/actions/orders/customerAcceptanceActions.js
+++ b/frontend/src/actions/orders/customerAcceptanceActions.js
@@ -12,6 +12,7 @@ import {
updateMessages
} from '../notification/notificationActions';
import HtmlClient from '../../helpers/HtmlClient';
+import { fromWiaasCustomerAcceptance } from '../../helpers/ProcessHelper';
const htmlClient = new HtmlClient();
@@ -32,7 +33,11 @@ export const fetchCustomerAcceptance = (idOrder) => {
})
.then(response => {
if (response.data) {
- dispatch(recieveCustomerAcceptance(response.data));
+ dispatch(
+ recieveCustomerAcceptance(
+ fromWiaasCustomerAcceptance(response.data)
+ )
+ );
}
})
.catch(error => {
diff --git a/frontend/src/actions/orders/customerQuestionnairesActions.js b/frontend/src/actions/orders/customerQuestionnairesActions.js
index 5a86e86..6631ddd 100644
--- a/frontend/src/actions/orders/customerQuestionnairesActions.js
+++ b/frontend/src/actions/orders/customerQuestionnairesActions.js
@@ -1,6 +1,8 @@
import {
API_SERVER
} from '../../config';
+import { fromWiaasCustomerQuestionnaire } from '../../helpers/ProcessHelper';
+
import {
UPLOAD_CUSTOMER_QUESTIONNAIRE,
@@ -41,7 +43,8 @@ export const fetchCustomerQuestionnaires = (idOrder) => {
})
.then(response => {
if (typeof response.data !== 'undefined') {
- dispatch(receiveCustomerQuestionnaires(response.data));
+ const questionnairesData = response.data.map(cData => fromWiaasCustomerQuestionnaire(cData));
+ dispatch(receiveCustomerQuestionnaires(questionnairesData));
}
})
.catch(error => {
diff --git a/frontend/src/actions/orders/processActions.js b/frontend/src/actions/orders/processActions.js
index 87bef48..03b9117 100644
--- a/frontend/src/actions/orders/processActions.js
+++ b/frontend/src/actions/orders/processActions.js
@@ -325,12 +325,13 @@ export const setSupportMessage = (message) => ({
supportText: message
});
-export const sendSupportMail = (orderInfo, orderPackages, supportText) => {
+export const sendSupportMail = (orderInfo, orderPackages, support_text) => {
+ let id = orderInfo.id;
return dispatch => {
return htmlClient.fetch({
- url: `${API_SERVER}/orders/api/sendSupportMail`,
+ url: `${API_SERVER}/wp-json/wiaas/support/send-support-email`,
method: 'post',
- data: {orderInfo, orderPackages, supportText}
+ data: {id, support_text}
})
.then(response => {
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
diff --git a/frontend/src/constants/appContainers.js b/frontend/src/constants/appContainers.js
index 22e9f42..9d94010 100644
--- a/frontend/src/constants/appContainers.js
+++ b/frontend/src/constants/appContainers.js
@@ -4,6 +4,7 @@ import CoMarketContainer from '../containers/coMarket/CoMarketContainer.jsx';
import CartContainer from '../containers/cart/CartContainer.jsx';
import TermsContainer from '../containers/terms/TermsContainer.jsx';
import ProfileSettingsContainer from '../containers/profileSettings/ProfileSettingsContainer.jsx';
+import HelpDeskContainer from '../containers/HelpDesk/HelpDeskContainer.jsx';
export const MainContainers = {
Dashboards: {
@@ -22,6 +23,10 @@ export const MainContainers = {
container: CartContainer,
params: []
},
+ HelpDesk:{
+ container: HelpDeskContainer,
+ params: []
+ },
Terms: {
container: TermsContainer,
params: []
diff --git a/frontend/src/containers/HelpDesk/HelpDeskContainer.jsx b/frontend/src/containers/HelpDesk/HelpDeskContainer.jsx
new file mode 100644
index 0000000..9ef8a68
--- /dev/null
+++ b/frontend/src/containers/HelpDesk/HelpDeskContainer.jsx
@@ -0,0 +1,11 @@
+import React, {Component} from 'react';
+import './style/HelpDesk.css';
+
+class HelpDeskContainer extends Component {
+ render() {
+
+ return ();
+ }
+}
+
+export default HelpDeskContainer;
\ No newline at end of file
diff --git a/frontend/src/containers/HelpDesk/style/HelpDesk.scss b/frontend/src/containers/HelpDesk/style/HelpDesk.scss
new file mode 100644
index 0000000..7f2adf3
--- /dev/null
+++ b/frontend/src/containers/HelpDesk/style/HelpDesk.scss
@@ -0,0 +1,6 @@
+iframe {
+ display: block;
+ border: none;
+ width: 100%;
+ height: 100vh;
+}
diff --git a/frontend/src/containers/cart/components/CartUploadDocument.jsx b/frontend/src/containers/cart/components/CartUploadDocument.jsx
index 7d87618..67b71e7 100644
--- a/frontend/src/containers/cart/components/CartUploadDocument.jsx
+++ b/frontend/src/containers/cart/components/CartUploadDocument.jsx
@@ -70,10 +70,10 @@ class CartUploadDocument extends Component {
- {uploadedDocument.name}
-
- Drag and drop or click to replace file
-
+
+ Drag and drop or click to replace {uploadedDocument.name}.{uploadedDocument.extension}
+
+ To upload multiple files, please pack the files to one zip-file and upload the zip-file
)
: (
@@ -81,9 +81,10 @@ class CartUploadDocument extends Component {
-
+
Drag and drop or click to upload file
-
+
+
To upload multiple files, please pack the files to one zip-file and upload the zip-file
)
}
diff --git a/frontend/src/containers/coMarket/components/CoMarketCatalogSelect.jsx b/frontend/src/containers/coMarket/components/CoMarketCatalogSelect.jsx
index 4f519cf..19c63fc 100644
--- a/frontend/src/containers/coMarket/components/CoMarketCatalogSelect.jsx
+++ b/frontend/src/containers/coMarket/components/CoMarketCatalogSelect.jsx
@@ -25,10 +25,10 @@ class CoMarketCatalogSelect extends Component {
}
componentWillReceiveProps(nextProps){
- // if(nextProps.activeModule==='cart' && nextProps.shops && nextProps.cartItems && nextProps.cartItems.length > 0){
- // const cartShop = this.props.shops.find( shop => { return shop.id === this.props.cartItems[0].idCommercialLead });
- // nextProps.dispatch(selectShop(cartShop));
- // }
+ if(nextProps.activeModule==='cart' && nextProps.shops && nextProps.cartItems && nextProps.cartItems.length > 0){
+ const cartShop = nextProps.shops.find( shop => { return shop.id === nextProps.cartItems[0].idCommercialLead });
+ nextProps.dispatch(selectShop(cartShop));
+ }
if(nextProps.shops && nextProps.idCommercialLead && nextProps.activeModule === 'co-market'){
const shop = nextProps.shops.find( shop => {return shop.id === nextProps.idCommercialLead });
diff --git a/frontend/src/containers/orders/components/OrderDocuments.jsx b/frontend/src/containers/orders/components/OrderDocuments.jsx
index b7139ec..13478f1 100644
--- a/frontend/src/containers/orders/components/OrderDocuments.jsx
+++ b/frontend/src/containers/orders/components/OrderDocuments.jsx
@@ -3,8 +3,18 @@ import {connect} from 'react-redux';
import OrderDocumentsGroup from './OrderDocumentsGroup.jsx';
import {orderTexts} from '../../../constants/ordersConstants';
import WiaasBox from "../../../mainComponents/box/WiaasBox";
+import {API_SERVER} from "../../../config";
+import FileDownloader from "../../../helpers/FileDownloader";
+
+const fileHandler = new FileDownloader();
class OrderDocuments extends Component {
+
+ downloadDocument(orderId, document){
+ const fileUrl = `${API_SERVER}/wp-json/wiaas/order/${orderId}/document/${document.key}`;
+ fileHandler.download(fileUrl, `${document.name}.${document.extension}`);
+ }
+
render() {
const {orderInfo} = this.props;
@@ -23,14 +33,13 @@ class OrderDocuments extends Component {
{
orderInfo.documents.map((document, index) => (
-
-
-
+
+ {this.downloadDocument(orderInfo.id, document)}} className="document-link-big">
+
{document.name}
-
-
+
))
}
diff --git a/frontend/src/containers/orders/components/OrderDocumentsGroup.jsx b/frontend/src/containers/orders/components/OrderDocumentsGroup.jsx
index 1876b37..d423ed6 100644
--- a/frontend/src/containers/orders/components/OrderDocumentsGroup.jsx
+++ b/frontend/src/containers/orders/components/OrderDocumentsGroup.jsx
@@ -13,7 +13,7 @@ class OrderDocumentsGroup extends Component {
}
downloadDocument(orderId, itemId, document){
- const fileUrl = `${API_SERVER}/wp-json/wiaas/documents/order/${orderId}/${document.type}?item_id=${itemId}&document_key=${document.key}`;
+ const fileUrl = `${API_SERVER}/wp-json/wiaas/order/${orderId}/item/${itemId}/document/${document.key}`;
fileHandler.download(fileUrl, `${document.name}.${document.extension}`);
}
@@ -28,20 +28,6 @@ class OrderDocumentsGroup extends Component {
{
documentsGroup.documents.map((document, index) => {
- if (document.url) {
-
- return (
-
-
-
-
- {document.name}
-
-
-
- );
- }
-
return (
{this.downloadDocument(orderId, documentsGroup.orderItemId, document)}} className="document-link-big">
diff --git a/frontend/src/containers/orders/components/OrderInfo.jsx b/frontend/src/containers/orders/components/OrderInfo.jsx
index 5865735..e75ca4d 100644
--- a/frontend/src/containers/orders/components/OrderInfo.jsx
+++ b/frontend/src/containers/orders/components/OrderInfo.jsx
@@ -80,7 +80,7 @@ class OrderInfo extends Component {
{orderTexts.labels.REFERENCE}:
-
{orderInfo.reference || '-'}
+
{orderInfo.reference || '-'}
{orderTexts.labels.BID}:
@@ -139,7 +139,7 @@ class OrderInfo extends Component {
{orderTexts.labels.PROJECT}:
-
{orderInfo.projectName || '-'}
+
{orderInfo.projectName || '-'}
diff --git a/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx b/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx
index 0d2c570..98defb4 100644
--- a/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx
+++ b/frontend/src/containers/orders/components/process/CustomerAcceptance.jsx
@@ -139,6 +139,7 @@ class CustomerAcceptance extends Component {
activeClassName="upload-file-accept"
onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(step.idOrder, acceptedFiles, rejectedFiles)}}>
{orderTexts.labels.UPLOAD_ACCEPTANCE_LABEL}
+
To upload multiple files, please pack the files to one zip-file and upload the zip-file
@@ -148,7 +149,7 @@ class CustomerAcceptance extends Component {
{
customerAcceptance.documents.map((document, index) =>
- {document.name}
+ {document.name}
{document.validation}
diff --git a/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx b/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx
index 63324b2..0da558e 100644
--- a/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx
+++ b/frontend/src/containers/orders/components/process/ValidateQuestionnaire.jsx
@@ -27,8 +27,8 @@ class ValidateQuestionnaire extends Component {
customerQuestionnaires.map((customerQuestionnaryAction) =>
orderPackage.orderItemId === customerQuestionnaryAction.item_id)}
+ key={'validate-questionnaire-' + customerQuestionnaryAction.actionId}
+ orderPackage={orderPackages.find( orderPackage => orderPackage.orderItemId === customerQuestionnaryAction.orderItemId)}
/>
)
}
diff --git a/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx b/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx
index 1b2dec7..ca51461 100644
--- a/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx
+++ b/frontend/src/containers/orders/components/process/ValidateQuestionnaireItem.jsx
@@ -19,7 +19,7 @@ class ValidateQuestionnaireItem extends Component {
uploadFile(action,acceptedFiles, rejectedFiles) {
if(acceptedFiles && acceptedFiles.length){
const file = acceptedFiles[0];
- this.props.dispatch(uploadCustomerQuestionnaire(action.order_id, action.action_id, file));
+ this.props.dispatch(uploadCustomerQuestionnaire(action.orderId, action.actionId, file));
}
// if(rejectedFiles && rejectedFiles.length) {
@@ -48,7 +48,7 @@ class ValidateQuestionnaireItem extends Component {
- {document.name}
+ {document.name}
@@ -59,7 +59,8 @@ class ValidateQuestionnaireItem extends Component {
(action.comments && action.comments.length > 0) &&
{action.comments.map((comment, key) =>
-
{comment}
+
{comment.header}
+
{comment.value}
)}
}
@@ -71,6 +72,7 @@ class ValidateQuestionnaireItem extends Component {
activeClassName="upload-file-accept"
onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(action, acceptedFiles, rejectedFiles)}}>
{orderTexts.labels.SELECT_OR_DROP}
+ To upload multiple files, please pack the files to one zip-file and upload the zip-file
@@ -79,12 +81,21 @@ class ValidateQuestionnaireItem extends Component {
- {document.name}
+ {document.name}
{action.status.replace(/-/g,' ')}
+ {
+ (action.comments && action.comments.length > 0) &&
+
+ {action.comments.map((comment, key) =>
+
{comment.header}
+
{comment.value}
+
)}
+
+ }
diff --git a/frontend/src/containers/orders/style/ProcessContainer.scss b/frontend/src/containers/orders/style/ProcessContainer.scss
index 3e4d82e..8b70054 100644
--- a/frontend/src/containers/orders/style/ProcessContainer.scss
+++ b/frontend/src/containers/orders/style/ProcessContainer.scss
@@ -7,6 +7,14 @@ $link-line-height: 1.5rem;
margin-top: 0.5rem;
}
+ .reference{
+ word-break: break-all;
+ }
+
+ .project-name{
+ word-break: break-all;
+ }
+
.info-color {
margin-top: 0.2rem;
padding-left: 0.2rem;
@@ -181,7 +189,7 @@ $link-line-height: 1.5rem;
.upload-file-drop-zone {
width: 100%;
border: 3px dashed $borderColor;
- height: 10rem;
+ padding: 2rem;
cursor: pointer;
border-radius: 4px;
}
@@ -206,7 +214,6 @@ $link-line-height: 1.5rem;
.drop-zone-text {
text-align: center;
- padding: 4rem 0;
}
.document-link {
@@ -357,7 +364,6 @@ $link-line-height: 1.5rem;
.drop-zone-text {
text-align: center;
- padding: 4rem 0;
font-size: 1rem;
}
diff --git a/frontend/src/containers/terms/TermsContainer.jsx b/frontend/src/containers/terms/TermsContainer.jsx
index 8bb4999..4ef50be 100644
--- a/frontend/src/containers/terms/TermsContainer.jsx
+++ b/frontend/src/containers/terms/TermsContainer.jsx
@@ -8,7 +8,7 @@ class TermsContainer extends Component {
render() {
return (
);
diff --git a/frontend/src/helpers/DocumentHelper.js b/frontend/src/helpers/DocumentHelper.js
index 3ab1f2c..8f38f5d 100644
--- a/frontend/src/helpers/DocumentHelper.js
+++ b/frontend/src/helpers/DocumentHelper.js
@@ -9,7 +9,8 @@ const iconTypes = {
xls: 'file-excel-o',
xlsx: 'file-excel-o',
ppt: 'file-powerpoint-o',
- pptx: 'file-powerpoint-o'
+ pptx: 'file-powerpoint-o',
+ zip: 'file-zip-o'
};
export const getDocumentIcon = extension => {
diff --git a/frontend/src/helpers/ProcessHelper.js b/frontend/src/helpers/ProcessHelper.js
index 4a068bb..98a750b 100644
--- a/frontend/src/helpers/ProcessHelper.js
+++ b/frontend/src/helpers/ProcessHelper.js
@@ -1,4 +1,5 @@
import moment from "moment";
+import {getDocumentIcon} from "./DocumentHelper";
export const fromWiaasProcessStep = (step) => {
return {
@@ -13,4 +14,31 @@ export const fromWiaasProcessStep = (step) => {
shortDesc: step.short_desc,
status: step.status,
}
+};
+
+export const fromWiaasCustomerAcceptance = cData => {
+
+ return {
+ actionId: cData['action_id'],
+ expiration: cData.expiration,
+ declineReason: cData['decline_reason'],
+ status: cData.status,
+ documents: cData.documents ? cData.documents.map(document => {
+ document.icon = getDocumentIcon(document.extension);
+ return document;
+ }) : []
+ };
+};
+
+export const fromWiaasCustomerQuestionnaire = cData => {
+ const document = cData.document;
+ document.icon = getDocumentIcon(document.extension);
+ return {
+ actionId: cData['action_id'],
+ orderItemId: cData['item_id'],
+ document,
+ status: cData.status,
+ orderId: cData['order_id'],
+ comments: cData.comments
+ };
};
\ No newline at end of file
diff --git a/frontend/src/mainComponents/menu/Menu.jsx b/frontend/src/mainComponents/menu/Menu.jsx
index 4e18523..16428e9 100644
--- a/frontend/src/mainComponents/menu/Menu.jsx
+++ b/frontend/src/mainComponents/menu/Menu.jsx
@@ -84,6 +84,13 @@ class Menu extends Component {
)
}
+