Merge branch 'frontend-show-order-docuemnts' into 'master'
Display order documents in order details page See merge request saburly/wiaas/new-wiaas!27
This commit was merged in pull request #27.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']));
|
||||
}
|
||||
}
|
||||
@@ -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' &&
|
||||
<OrderDocuments idOrder={orderInfo.id} />
|
||||
<OrderDocuments orderDocumentsBundle={orderInfo.documents} />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -5,16 +5,14 @@ import {orderTexts} from '../../../constants/ordersConstants';
|
||||
|
||||
class OrderDocuments extends Component {
|
||||
render() {
|
||||
const {orderInfo} = this.props;
|
||||
const {orderDocumentsBundle} = this.props;
|
||||
|
||||
return (
|
||||
<div id="order-documents" className="order-documents">
|
||||
{
|
||||
orderInfo.packages.map(orderPackage => <OrderDocumentsGroup key={'order-package-' + orderPackage.id} documentsGroup={orderPackage} />)
|
||||
}
|
||||
{
|
||||
orderInfo.orderDocuments && <OrderDocumentsGroup key={'order-package-0'} documentsGroup={{documents: orderInfo.documents, packageName: orderTexts.labels.OTHER_DOCS}} />
|
||||
orderDocumentsBundle.map(bundle => <OrderDocumentsGroup key={'order-package-' + bundle.package.name} packageName={bundle.package.name} packageID={bundle.package.id} documents={bundle.documents} />)
|
||||
}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -40,39 +40,39 @@ class OrderDocumentsGroup extends Component {
|
||||
}
|
||||
|
||||
getDocumentText(document) {
|
||||
const name = document.documentName + '.' + document.extension;
|
||||
const name = document.name + '.' + document.extension;
|
||||
|
||||
return name.length > 9 ? name.substring(0, 10) + '...' : name;
|
||||
}
|
||||
|
||||
downloadDocument(document){
|
||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}&fileType=${document.documentTypeName}`
|
||||
const fileName = document.documentName + '.' + document.extension;
|
||||
downloadDocument(document, packageID){
|
||||
const fileUrl = `${API_SERVER}/wp-json/wiaas/download-package-file?document_id=${document.id}&package_id=${packageID}`
|
||||
const fileName = document.name + '.' + document.extension;
|
||||
fileHandler.download(fileUrl, fileName);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {documentsGroup} = this.props;
|
||||
const {documents, packageName, packageID} = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{
|
||||
documentsGroup.documents &&
|
||||
documentsGroup.documents.length > 0 &&
|
||||
<WiaasBox mainTitle={documentsGroup.packageName}>
|
||||
documents &&
|
||||
documents.length > 0 &&
|
||||
<WiaasBox mainTitle={packageName}>
|
||||
{
|
||||
documentsGroup.documents.map(document => <a id={'document-' + document.idDocument} key={'order-document-' + document.idDocument}>
|
||||
<div onClick={() => {this.downloadDocument(document)}} className="document-link-big">
|
||||
documents.map(document => <a id={'document-' + document.id} key={'order-document-' + document.id}>
|
||||
<div onClick={() => {this.downloadDocument(document, packageID)}} className="document-link-big">
|
||||
<i className={'fa fa-4x fa-' + this.getDocumentIcon(document.extension)} aria-hidden="true"></i>
|
||||
<div>
|
||||
{this.getDocumentText(document)}
|
||||
<Tooltip placement="bottom"
|
||||
delay={{ show: 0, hide: 0}}
|
||||
container="order-documents"
|
||||
isOpen={this.state[document.idDocument]}
|
||||
target={'document-' + document.idDocument}
|
||||
toggle={()=>this.toggle(document.idDocument)}>
|
||||
{document.documentName} ({document.extension})
|
||||
isOpen={this.state[document.id]}
|
||||
target={'document-' + document.id}
|
||||
toggle={()=>this.toggle(document.id)}>
|
||||
{document.name} ({document.extension})
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div></a>)
|
||||
|
||||
@@ -22,12 +22,6 @@ class PackageInfo extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
downloadDocument(document){
|
||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}&fileType=${document.documentTypeName}`
|
||||
const fileName = document.documentName + '.' + document.extension;
|
||||
fileHandler.download(fileUrl, fileName);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {orderPackage, currency, onViewChange} = this.props;
|
||||
const shouldShowPriceInfo = orderPackage.recurringPrice > 0 || orderPackage.servicePrice > 0;
|
||||
@@ -122,17 +116,6 @@ class PackageInfo extends Component {
|
||||
}
|
||||
</Col>
|
||||
}
|
||||
{
|
||||
orderPackage.documents &&
|
||||
<Col xl="2">
|
||||
<div className="subtitle"><h6>{orderTexts.labels.DOCUMENTS}:</h6></div>
|
||||
{
|
||||
orderPackage.documents.length > 0 ?
|
||||
<div className="link-to-docs" onClick={()=>onViewChange('documents')}>{orderTexts.buttons.SEE_DOCUMENTS}</div>:
|
||||
<span>{orderTexts.labels.NO_DOCUMENTS}</span>
|
||||
}
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
|
||||
@@ -37,6 +37,7 @@ export const fromWCOrder = (WCOrder) => {
|
||||
email: WCOrder.billing.email,
|
||||
address: formatAddress(WCOrder.billing)
|
||||
},
|
||||
documents: WCOrder.documents,
|
||||
packages: WCOrder['line_items'].map(packageLine => {
|
||||
return {
|
||||
id: packageLine['product_id'],
|
||||
|
||||
Reference in New Issue
Block a user