add documents property to order
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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