delivery step actions
This commit is contained in:
@@ -12,6 +12,35 @@ class Wiaas_Document_Download {
|
||||
if ( isset($_GET['wiaasdoc']) ) {
|
||||
add_action( 'init', array( __CLASS__, 'admin_download' ) );
|
||||
}
|
||||
|
||||
if (isset($_GET['gf-wiaas-order-doc'])) {
|
||||
|
||||
add_action( 'init', array( __CLASS__, 'admin_gf_order_document_download' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle download for order documents by gravity flow steps
|
||||
*/
|
||||
public static function admin_gf_order_document_download() {
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// relative file path from upload dir for document
|
||||
$version = urldecode($_GET['gf-wiaas-order-doc']);
|
||||
|
||||
$file_path = wiaas_get_document_version_path($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 )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -187,4 +187,44 @@ function wiaas_get_standard_package_order_item_documents($order, $package_item_i
|
||||
|
||||
return $doc;
|
||||
}, $order_documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve documents for order item
|
||||
*
|
||||
* @param $order_item
|
||||
* @param string|null $doc_type
|
||||
*
|
||||
* @return array {
|
||||
* $param string key Unique key used for frontend downloand
|
||||
* $param string name Document name visible in download link
|
||||
* $param string version Relative path from upload directory to physical document file
|
||||
* $param string type Document type
|
||||
*
|
||||
* @reference Wiaas_Document
|
||||
* }
|
||||
*/
|
||||
function wiaas_get_order_item_documents($order_item, $doc_type = null) {
|
||||
|
||||
$documents = empty($order_item['wiaas_documents']) ? array() : $order_item['wiaas_documents'];
|
||||
|
||||
if (empty($doc_type)) {
|
||||
return $documents;
|
||||
}
|
||||
|
||||
$filtered_documents = array();
|
||||
|
||||
foreach ($documents as $document) {
|
||||
|
||||
if ($document['type'] === $doc_type) {
|
||||
$filtered_documents[] = $document;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered_documents;
|
||||
}
|
||||
|
||||
function wiaas_get_order_item_document_admin_download_link($order_id, $item_id, $version) {
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user