diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php
index 006fa24..e103884 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php
@@ -118,6 +118,8 @@ class Wiaas_Order {
$data = self::_append_order_process($data, $order, $request);
$data = self::_append_order_comments($data, $order, $request);
+
+ $data = self::_append_documents($data, $order, $request);
}
$response->set_data($data);
@@ -351,6 +353,45 @@ class Wiaas_Order {
}
}
+ return $data;
+ }
+
+ /** Append downloadable documents from order products if single order is requested
+ * @param $data
+ * @param $order
+ * @param $request
+ */
+ private static function _append_documents($data, $order, $request) {
+ if (isset($request['id'])) {
+ $data['documents'] = array();
+
+ //This requires _append_packages to be called before this method
+
+ foreach($data['line_items'] as $item){
+ $product = wc_get_product($item['product_id']);
+
+ $product_documents = array();
+ foreach ( $product->get_downloads() as $file_id => $file ) {
+ $product_documents[] = array(
+ 'id' => $file_id,
+ 'name' => $file->get_name(),
+ 'extension' => $file->get_file_extension()
+ );
+ }
+
+ if (count($product_documents)){
+ $data['documents'][] = array(
+ 'package' => array(
+ 'id' => $product->get_id(),
+ 'name' => $product->get_name()
+ ),
+ 'documents' => $product_documents
+ );
+ }
+ }
+
+ }
+
return $data;
}
}
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 b330dfb..6d78633 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
@@ -198,4 +198,28 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
}
+
+ /**
+ * @covers Wiaas_Order::transform_rest_order()
+ */
+ function test_order_rest_response_has_empty_documents_when_package_has_no_documents() {
+ $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['documents']);
+ $this->assertTrue(is_array($transformed_order_response['documents']));
+ }
}
\ No newline at end of file
diff --git a/frontend/src/containers/orders/ProcessContainer.jsx b/frontend/src/containers/orders/ProcessContainer.jsx
index 4c04de0..7ae0345 100644
--- a/frontend/src/containers/orders/ProcessContainer.jsx
+++ b/frontend/src/containers/orders/ProcessContainer.jsx
@@ -140,9 +140,6 @@ class ProcessContainer extends Component {
}
onViewChange(activeView){
- if(activeView === 'documents'){
- this.props.dispatch(fetchOrderInfo(this.props.idOrder));
- }
this.setState({activeView});
}
@@ -232,7 +229,7 @@ class ProcessContainer extends Component {
{
this.state.activeView === 'documents' &&
-