Handle wiaas documents
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Admin_Documents {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
require_once dirname( __FILE__ ) . '/documents/class-wiaas-admin-product-documents.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/documents/class-wiaas-admin-document-editor.php';
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/documents/wiaas-admin-document-ajax.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Admin_Documents::init();
|
||||||
@@ -16,6 +16,8 @@ class Wiaas_Admin_Package {
|
|||||||
public static function enqueue_scripts() {
|
public static function enqueue_scripts() {
|
||||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||||
|
|
||||||
|
wp_enqueue_script( 'plupload-all' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Editor for wiaas document post screen
|
||||||
|
*
|
||||||
|
* Class Wiaas_Admin_Document_Editor
|
||||||
|
*/
|
||||||
|
class Wiaas_Admin_Document_Editor {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
||||||
|
|
||||||
|
add_action( 'save_post', array( __CLASS__, 'save' ), 1, 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add wiaas document editor metaboxes
|
||||||
|
*/
|
||||||
|
public static function add_meta_boxes() {
|
||||||
|
|
||||||
|
add_meta_box( 'wiaas_document_details', __( 'Details', 'wiaas' ), array(
|
||||||
|
__CLASS__,
|
||||||
|
'document_info'
|
||||||
|
), 'wiaas_doc', 'normal', 'low');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save wiaas document informations
|
||||||
|
* @param $post_id
|
||||||
|
* @param $post
|
||||||
|
*/
|
||||||
|
public static function save ($post_id, $post) {
|
||||||
|
if ( empty( $post_id ) || empty( $post ) || empty( $_POST ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( is_int( wp_is_post_revision( $post ) ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( is_int( wp_is_post_autosave( $post ) ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( empty( $_POST['wiaas_doc_nonce'] ) || ! wp_verify_nonce( $_POST['wiaas_doc_nonce'], 'save_wiaas_doc' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $post->post_type != 'wiaas_doc' ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// unset nonce because it's only valid of 1 post
|
||||||
|
unset( $_POST['wiaas_doc_nonce'] );
|
||||||
|
|
||||||
|
if (isset($_POST['wiaas_doc_version']) && $_POST['wiaas_doc_version'] !== '') {
|
||||||
|
$version = sanitize_text_field($_POST['wiaas_doc_version']);
|
||||||
|
|
||||||
|
if(wiaas_document_version_exists($version)) {
|
||||||
|
Wiaas_Document::add_document_version($post_id, $version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['wiaas_doc_type'])) {
|
||||||
|
Wiaas_Document::set_doc_type($post_id, sanitize_key($_POST['wiaas_doc_type']));
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Document::set_is_doc_visible($post_id, $_POST['wiaas_doc_visible'] === 'on');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render wiaas document info metabox
|
||||||
|
*/
|
||||||
|
public static function document_info() {
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$parent_post_type = $post->post_type;
|
||||||
|
$document_id = $post->ID;
|
||||||
|
|
||||||
|
$ajax_action = 'wiaas_upload_file';
|
||||||
|
|
||||||
|
require 'views/html-document-info.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Admin_Document_Editor::init();
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Admin_Product_Documents {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'add_linked_documents_tab' ) );
|
||||||
|
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'linked_documents_tab' ) );
|
||||||
|
|
||||||
|
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
||||||
|
|
||||||
|
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add upload and link document metabox to product screen
|
||||||
|
*/
|
||||||
|
public static function add_meta_boxes() {
|
||||||
|
add_meta_box( 'wiaas_upload_and_link_document', __( 'Upload and link document', 'wiaas' ), array(
|
||||||
|
__CLASS__,
|
||||||
|
'upload_and_link_document'
|
||||||
|
), 'product', 'side');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render upload and link document metabox to product screen
|
||||||
|
*/
|
||||||
|
public static function upload_and_link_document() {
|
||||||
|
|
||||||
|
$ajax_action = 'wiaas_quick_add_document';
|
||||||
|
|
||||||
|
require 'views/html-document-form.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add linked documents tabs for product screen
|
||||||
|
*
|
||||||
|
* @param array $tabs
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function add_linked_documents_tab($tabs) {
|
||||||
|
$tabs['wiaas_documents'] = array(
|
||||||
|
'label' => __( 'Linked Documents', 'wiaas' ),
|
||||||
|
'target' => 'wiaas_documents',
|
||||||
|
'class' => array('show_if_bundle', 'show_if_simple'),
|
||||||
|
'priority' => 20,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render linked documents tab content for product screen
|
||||||
|
*/
|
||||||
|
public static function linked_documents_tab() {
|
||||||
|
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$documents_ids = wiaas_get_object_attached_documents($post->ID);
|
||||||
|
|
||||||
|
include 'views/html-product-documents.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save linked document for product
|
||||||
|
*
|
||||||
|
* @param int $package_id
|
||||||
|
*/
|
||||||
|
public static function process_meta_box($package_id) {
|
||||||
|
$documents = isset($_POST['wiaas_attached_documents']) && is_array($_POST['wiaas_attached_documents']) ?
|
||||||
|
$_POST['wiaas_attached_documents'] : array();
|
||||||
|
|
||||||
|
wiaas_attach_documents_to_object($package_id, $documents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Admin_Product_Documents::init();
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* int $id ID of the attached document
|
||||||
|
*/
|
||||||
|
|
||||||
|
$doc_info = Wiaas_Document::get_doc_info($id);
|
||||||
|
$type = isset($doc_info['type']) && is_array($doc_info['type']) ? $doc_info['type']['name'] : ' - ';
|
||||||
|
|
||||||
|
$visible = Wiaas_Document::is_doc_visible($id);
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr id="wiaas_attached_document_<?php echo esc_attr($id); ?>">
|
||||||
|
<td width="1%">
|
||||||
|
<?php
|
||||||
|
if ($visible) {
|
||||||
|
echo '<span class="dashicons dashicons-visibility"></span>';
|
||||||
|
} else {
|
||||||
|
echo '<span class="dashicons dashicons-hidden"></span>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div>
|
||||||
|
<input type="hidden" name="wiaas_attached_documents[]" value="<?php echo esc_attr($id); ?>" />
|
||||||
|
<b>
|
||||||
|
<?php esc_html_e($doc_info['name'], 'wiaas'); ?>
|
||||||
|
</b>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span>
|
||||||
|
<?php esc_html_e($type, 'wiaas'); ?>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td width="1%"><a href="<?php echo esc_attr($doc_info['url']) ?>" download>
|
||||||
|
<span class="dashicons dashicons-download"></span>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td width="1%">
|
||||||
|
<button
|
||||||
|
data-id="<?php echo esc_attr($id); ?>"
|
||||||
|
class="button wiaas-remove-attached-document">
|
||||||
|
<small><?php esc_html_e('Remove', 'wiaas'); ?></small>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
@@ -0,0 +1,258 @@
|
|||||||
|
<?php
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
$is_update = isset($document_id);
|
||||||
|
|
||||||
|
global $post;
|
||||||
|
|
||||||
|
$insert_new_document = $post->post_type !== 'wiaas_doc';
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#wiaas_document_form .form-group {
|
||||||
|
margin-bottom:15px;
|
||||||
|
min-height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_form .form-control {
|
||||||
|
width: 100%;
|
||||||
|
height: 34px;
|
||||||
|
padding:6px 12px;
|
||||||
|
border: 1px solid #d5d5d5;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_form #plupload-browse-button {
|
||||||
|
color: #444 !important;
|
||||||
|
background-color: #FFFFFF !important;
|
||||||
|
border-color: #CCCCCC !important;
|
||||||
|
text-transform: uppercase !important;
|
||||||
|
letter-spacing: 1px !important;
|
||||||
|
border-radius: 2px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_form #plupload-upload-ui {
|
||||||
|
height: 230px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_form #drag-drop-area {
|
||||||
|
max-height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_form .drag-drop .drag-drop-inside {
|
||||||
|
margin: 50px auto 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
<?php
|
||||||
|
|
||||||
|
if ($insert_new_document) {
|
||||||
|
$nonce = wp_create_nonce('wiaas_quick_add_document');
|
||||||
|
$action = 'wiaas_quick_add_document';
|
||||||
|
} else {
|
||||||
|
$nonce = wp_create_nonce('wiaas_upload_file');
|
||||||
|
$action = 'wiaas_upload_file';
|
||||||
|
}
|
||||||
|
|
||||||
|
$plupload_init = array(
|
||||||
|
'runtimes' => 'html5,silverlight,flash,html4',
|
||||||
|
'browse_button' => 'plupload-browse-button',
|
||||||
|
'container' => 'plupload-upload-ui',
|
||||||
|
'drop_element' => 'drag-drop-area',
|
||||||
|
'file_data_name' => 'wiaas_file',
|
||||||
|
'multiple_queues' => false,
|
||||||
|
'url' => admin_url('admin-ajax.php'),
|
||||||
|
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
|
||||||
|
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
|
||||||
|
'filters' => array(array(
|
||||||
|
'title' => __('Allowed Files'),
|
||||||
|
'extensions' => join(',', Wiaas_Document_Upload::allowed_extensions()))
|
||||||
|
),
|
||||||
|
'multipart' => true,
|
||||||
|
'urlstream_upload' => true,
|
||||||
|
// additional post data to send to our ajax hook
|
||||||
|
'multipart_params' => array(
|
||||||
|
'_ajax_nonce' => $nonce,
|
||||||
|
'action' => $action,
|
||||||
|
'type' => 'wiaas_doc'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if(get_option('__wpdm_chunk_upload',0) == 1){
|
||||||
|
$plupload_init['chunk_size'] = get_option('__wpdm_chunk_size', 1024).'kb';
|
||||||
|
$plupload_init['max_retries'] = 3;
|
||||||
|
} else
|
||||||
|
$plupload_init['max_file_size'] = wp_max_upload_size().'b';
|
||||||
|
?>
|
||||||
|
|
||||||
|
// create the uploader and pass the config from above
|
||||||
|
var uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
|
||||||
|
|
||||||
|
// checks if browser supports drag and drop upload, makes some css adjustments if necessary
|
||||||
|
uploader.bind('Init', function(up){
|
||||||
|
var uploaddiv = jQuery('#plupload-upload-ui');
|
||||||
|
|
||||||
|
if(up.features.dragdrop){
|
||||||
|
uploaddiv.addClass('drag-drop');
|
||||||
|
jQuery('#drag-drop-area')
|
||||||
|
.bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
|
||||||
|
.bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
|
||||||
|
|
||||||
|
}else{
|
||||||
|
uploaddiv.removeClass('drag-drop');
|
||||||
|
jQuery('#drag-drop-area').unbind('.wp-uploader');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
uploader.init();
|
||||||
|
|
||||||
|
// a file was added in the queue
|
||||||
|
uploader.bind('FilesAdded', function(up, files){
|
||||||
|
//var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($insert_new_document) {
|
||||||
|
?>
|
||||||
|
var params = uploader.getOption('multipart_params');
|
||||||
|
params['doc_title'] = $('#wiaas_new_doc_title').val();
|
||||||
|
params['doc_type'] = $('#wiaas_new_doc_type').val();
|
||||||
|
params['doc_visible'] = $('#wiaas_new_doc_visible').is(':checked');
|
||||||
|
|
||||||
|
uploader.setOption('multipart_params', params);
|
||||||
|
|
||||||
|
plupload.each(files, function(file){
|
||||||
|
jQuery('#wiaas_selected_file').val(file.name);
|
||||||
|
});
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
uploader.refresh();
|
||||||
|
uploader.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#wiaas_document_add_version").click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
uploader.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
// a file was uploaded
|
||||||
|
uploader.bind('FileUploaded', function(up, file, response) {
|
||||||
|
|
||||||
|
response = response.response;
|
||||||
|
|
||||||
|
if (response.substring(0, 6) === 'ERROR:') {
|
||||||
|
jQuery('#wiaas_upload_errors').html('<span class="text-danger">' +
|
||||||
|
'<i class="fa fa-exclamation-triangle"></i>' +
|
||||||
|
' ' + response.substring(6, response.length) +
|
||||||
|
'</span>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($insert_new_document) {
|
||||||
|
?>
|
||||||
|
$('#wiaas_attached_documents').find('tbody').append(response);
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
?>
|
||||||
|
$('#wiaas_uploaded_file').val(response);
|
||||||
|
jQuery('#publish').click();
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="wiaas_document_form">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ($insert_new_document) {
|
||||||
|
?>
|
||||||
|
<p class="form-group">
|
||||||
|
<input
|
||||||
|
id="wiaas_new_doc_title"
|
||||||
|
type="text"
|
||||||
|
placeholder="Title"
|
||||||
|
class="form-control input-lg" />
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<p class="form-group">
|
||||||
|
<select
|
||||||
|
id="wiaas_new_doc_type"
|
||||||
|
name="wiaas_doc_type"
|
||||||
|
class="form-control input-lg">
|
||||||
|
<?php
|
||||||
|
$all_doc_types = Wiaas_Document::get_available_doc_types();
|
||||||
|
|
||||||
|
if (!$insert_new_document) {
|
||||||
|
$selected_doc_type = Wiaas_Document::get_doc_type($post->ID);
|
||||||
|
$selected_doc_type = is_array($selected_doc_type) ? $selected_doc_type['id'] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($all_doc_types as $doc_type) {
|
||||||
|
if (!$doc_type['is_special_type']) {
|
||||||
|
?>
|
||||||
|
<option
|
||||||
|
value="<?php echo $doc_type['id'] ?>"
|
||||||
|
<?php selected($doc_type['id'], $selected_doc_type, true)?>
|
||||||
|
>
|
||||||
|
<?php esc_html_e($doc_type['name'], 'wiaas') ?>
|
||||||
|
</option>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="form-group">
|
||||||
|
<input
|
||||||
|
id="wiaas_new_doc_visible"
|
||||||
|
name="wiaas_doc_visible"
|
||||||
|
<?php if (!$insert_new_document)
|
||||||
|
checked(Wiaas_Document::is_doc_visible($post->ID), true, true) ?>
|
||||||
|
type="checkbox"
|
||||||
|
/>
|
||||||
|
<label><?php echo __( 'Visible to customer?', 'wiaas' ); ?></label>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<input id="wiaas_uploaded_file" name="wiaas_doc_version" type="hidden">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div id="plupload-upload-ui" class="hide-if-no-js">
|
||||||
|
<div id="drag-drop-area" style="height:240px">
|
||||||
|
<div class="drag-drop-inside">
|
||||||
|
<p class="drag-drop-info"><?php _e( 'Drop file here', 'wiaas' ); ?></p>
|
||||||
|
|
||||||
|
<p><?php echo _x( 'or', 'Drop file here *or* select file', 'wiaas' ); ?></p>
|
||||||
|
|
||||||
|
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button"
|
||||||
|
value="<?php esc_attr_e( 'Select File', 'wiaas' ); ?>"
|
||||||
|
class="button"/></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="wiaas_upload_errors" style="color: darkred;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* int $document_id ID of the document
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
#wiaas_document_info table {
|
||||||
|
margin-top: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_info table > thead {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_info table b {
|
||||||
|
color: #72777c;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tagsdiv-wiaas_doc_type {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#wiaas_document_new_version {
|
||||||
|
max-width: 320px;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div id="wiaas_document_info">
|
||||||
|
|
||||||
|
<?php echo wp_nonce_field('save_wiaas_doc', 'wiaas_doc_nonce') ?>
|
||||||
|
|
||||||
|
<div id="wiaas_document_new_version">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require 'html-document-form.php';
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<table class="widefat">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td><b>Versions</b></td>
|
||||||
|
<td></td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="wiaas_doc_versions">
|
||||||
|
<?php
|
||||||
|
$versions = Wiaas_Document::get_document_versions($document_id);
|
||||||
|
|
||||||
|
foreach ($versions as $index => $version) {
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php esc_html_e('#' . ($index + 1), 'wiaas') ?></td>
|
||||||
|
<td><?php
|
||||||
|
esc_html_e(
|
||||||
|
wiaas_get_doc_version_filename($version).'.'.wiaas_get_doc_version_extension($version),
|
||||||
|
'wiaas')
|
||||||
|
?></td>
|
||||||
|
<td>
|
||||||
|
<a
|
||||||
|
href="<?php echo esc_attr(Wiaas_Document::get_doc_download_link($document_id, $index)) ?>"
|
||||||
|
download>
|
||||||
|
<span class="dashicons dashicons-download"></span>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Wiaas Linked Packages Editor
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
|
||||||
|
$( '.wiaas-search-documents' ).each(function() {
|
||||||
|
var element = $( this );
|
||||||
|
var searchTarget = $('#' + element.data('target'));
|
||||||
|
|
||||||
|
element.autocomplete({
|
||||||
|
source: function(request, response) {
|
||||||
|
$.get( window.ajaxurl, {
|
||||||
|
action: 'wiaas_json_search_documents',
|
||||||
|
query: request.term,
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce('wiaas_json_search_documents') ?>'
|
||||||
|
} ).done( function( documents ) {
|
||||||
|
response( documents || []);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
select: function(event, ui) {
|
||||||
|
if (!searchTarget || $('#wiaas_attached_document_' + ui.item.id).length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.get(window.ajaxurl, {
|
||||||
|
action: 'wiaas_link_document',
|
||||||
|
_ajax_nonce: '<?php echo wp_create_nonce('wiaas_link_document') ?>',
|
||||||
|
id: ui.item.id
|
||||||
|
}).done( function (document) {
|
||||||
|
searchTarget.find('tbody').append(document);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.autocomplete( 'instance' )._renderItem = function( ul, item ) {
|
||||||
|
return $( '<li role="option" id="wiaas-document-autocomplete-' + item.id + '">' )
|
||||||
|
.text( item.name )
|
||||||
|
.appendTo( ul );
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#wiaas_attached_documents').delegate('.wiaas-remove-attached-document', 'click', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var id = $(this).data('id');
|
||||||
|
|
||||||
|
$('#wiaas_attached_document_' + id).remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div id="wiaas_documents" class="panel woocommerce_options_panel">
|
||||||
|
<div class="options_group">
|
||||||
|
<p class="form-field">
|
||||||
|
<label style="font-weight: bold;" for="wiaas_addon_packages"><?php esc_html_e( 'Search documents:', 'wiaas' ); ?></label>
|
||||||
|
<input type="text" data-target="wiaas_attached_documents" class="wiaas-search-documents"/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="options_group">
|
||||||
|
<div class="form-field">
|
||||||
|
<div style="margin:20px">
|
||||||
|
<table id="wiaas_attached_documents" class="widefat wp-list-table">
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
foreach ($documents_ids as $id) {
|
||||||
|
require 'html-attached-document.php';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
add_action( 'wp_ajax_wiaas_upload_file', 'wiaas_ajax_upload_document_version' );
|
||||||
|
add_action( 'wp_ajax_wiaas_quick_add_document', 'wiaas_ajax_quick_add_document' );
|
||||||
|
add_action( 'wp_ajax_wiaas_link_document', 'wiaas_ajax_link_document' );
|
||||||
|
|
||||||
|
add_action( 'wp_ajax_wiaas_json_search_documents','wiaas_ajax_json_search_documents' );
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload document version file with ajax
|
||||||
|
*/
|
||||||
|
function wiaas_ajax_upload_document_version() {
|
||||||
|
check_ajax_referer('wiaas_upload_file');
|
||||||
|
|
||||||
|
if (!isset($_FILES['wiaas_file']) || empty($_FILES['wiaas_file'])) {
|
||||||
|
echo "ERROR: No file present!";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = Wiaas_Document_Upload::upload_document_version('wiaas_file');
|
||||||
|
|
||||||
|
if (is_wp_error($version)) {
|
||||||
|
echo 'ERROR:' . $version->get_error_message();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $version;
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick add new document and return attachment view for it
|
||||||
|
*/
|
||||||
|
function wiaas_ajax_quick_add_document() {
|
||||||
|
check_ajax_referer('wiaas_quick_add_document');
|
||||||
|
|
||||||
|
//validate file
|
||||||
|
if (!isset($_FILES['wiaas_file']) || empty($_FILES['wiaas_file'])) {
|
||||||
|
echo "ERROR: No file present!";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload document version file
|
||||||
|
$version = Wiaas_Document_Upload::upload_document_version('wiaas_file');
|
||||||
|
|
||||||
|
// Upload failed so return the error
|
||||||
|
if (is_wp_error($version)) {
|
||||||
|
echo 'ERROR:' . $version->get_error_message();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get document title
|
||||||
|
$title = isset($_POST['doc_title']) && $_POST['doc_title'] !== '' ?
|
||||||
|
sanitize_text_field($_POST['doc_title']) :
|
||||||
|
pathinfo( $version, PATHINFO_FILENAME );
|
||||||
|
|
||||||
|
// Try to create new document
|
||||||
|
$id = Wiaas_Document::add_document(
|
||||||
|
$title,
|
||||||
|
$version,
|
||||||
|
$_POST['doc_visible'] === 'true');
|
||||||
|
|
||||||
|
// Document creation failed so return the error
|
||||||
|
if (!$id) {
|
||||||
|
echo "ERROR: Document could not be created!";
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If document type is sent then assign new document to it
|
||||||
|
if (isset($_POST['doc_type'])) {
|
||||||
|
Wiaas_Document::set_doc_type( $id, sanitize_key($_POST['doc_type']) );
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'views/html-attached-document.php';
|
||||||
|
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render attacment view for linked document
|
||||||
|
*/
|
||||||
|
function wiaas_ajax_link_document() {
|
||||||
|
check_ajax_referer('wiaas_link_document');
|
||||||
|
|
||||||
|
$id = absint($_GET['id']);
|
||||||
|
|
||||||
|
require 'views/html-attached-document.php';
|
||||||
|
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*Search wiaas documents by name
|
||||||
|
*/
|
||||||
|
function wiaas_ajax_json_search_documents() {
|
||||||
|
check_ajax_referer('wiaas_json_search_documents');
|
||||||
|
|
||||||
|
$q = ( ! empty( $_GET['query'] ) ? sanitize_text_field($_GET['query']) : '' );
|
||||||
|
|
||||||
|
$result = Wiaas_Document::search($q);
|
||||||
|
|
||||||
|
wp_send_json( $result );
|
||||||
|
}
|
||||||
@@ -28,20 +28,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showDownloadableFiles() {
|
|
||||||
$('#general_product_data').find('.show_if_downloadable').each(function() {
|
|
||||||
$(this).show();
|
|
||||||
$(this).removeClass('hidden');
|
|
||||||
$(this).removeClass('show_if_downloadable');
|
|
||||||
$(this).addClass('show_if_simple');
|
|
||||||
$(this).addClass('show_if_bundle');
|
|
||||||
|
|
||||||
$(this).find('._download_limit_field, ._download_expiry_field').hide();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
showDownloadableFiles();
|
|
||||||
|
|
||||||
handlePackageTypeToolsVisiblity();
|
handlePackageTypeToolsVisiblity();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -6,12 +6,24 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
$("#general_product_data").find('.pricing').addClass('hide_if_bundle');
|
if ($('#product-type').val() === 'simple') {
|
||||||
$("#general_product_data").find('.pricing').removeClass('show_if_bundle');
|
$('#general_product_data').find('.pricing').show();
|
||||||
|
} else {
|
||||||
if ($('#product-type').val() === 'bundle') {
|
$('#general_product_data').find('.pricing').hide();
|
||||||
$("#general_product_data .pricing").hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#general_product_data').find('.pricing').attr('class','wiaas_show_if_simple');
|
||||||
|
|
||||||
|
$('body').on('woocommerce-product-type-change', function (event, select_val) {
|
||||||
|
|
||||||
|
if ('simple' === select_val) {
|
||||||
|
$('.wiaas_show_if_simple').show();
|
||||||
|
} else {
|
||||||
|
$('.wiaas_show_if_simple').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -21,7 +33,7 @@ woocommerce_wp_checkbox(
|
|||||||
'id' => '_wiaas_recurring_price',
|
'id' => '_wiaas_recurring_price',
|
||||||
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
|
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
|
||||||
'data_type' => 'price',
|
'data_type' => 'price',
|
||||||
'label' => __( $product->get_category_ids()[0], 'wiaas' ),
|
'label' => __( 'Is recurring?', 'wiaas' ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -32,14 +32,12 @@ class Wiaas_Cart_API {
|
|||||||
'description' => __( 'Wiaas package ID.', 'wiaas' ),
|
'description' => __( 'Wiaas package ID.', 'wiaas' ),
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'sanitize_callback' => 'absint',
|
'sanitize_callback' => 'absint',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
),
|
),
|
||||||
'price_id' => array(
|
'price_id' => array(
|
||||||
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
|
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
|
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
|
||||||
'sanitize_callback' => 'sanitize_key',
|
'sanitize_callback' => 'sanitize_key',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
),
|
),
|
||||||
'options_ids' => array(
|
'options_ids' => array(
|
||||||
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
|
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
|
||||||
@@ -47,7 +45,6 @@ class Wiaas_Cart_API {
|
|||||||
'items' => array(
|
'items' => array(
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'sanitize_callback' => 'absint',
|
'sanitize_callback' => 'absint',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'addons_ids' => array(
|
'addons_ids' => array(
|
||||||
@@ -56,7 +53,6 @@ class Wiaas_Cart_API {
|
|||||||
'items' => array(
|
'items' => array(
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'sanitize_callback' => 'absint',
|
'sanitize_callback' => 'absint',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -69,7 +65,6 @@ class Wiaas_Cart_API {
|
|||||||
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'sanitize_callback' => 'sanitize_key',
|
'sanitize_callback' => 'sanitize_key',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
@@ -86,12 +81,69 @@ class Wiaas_Cart_API {
|
|||||||
'description' => __( 'New quantity cart package item.', 'wiaas' ),
|
'description' => __( 'New quantity cart package item.', 'wiaas' ),
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'sanitize_callback' => 'absint',
|
'sanitize_callback' => 'absint',
|
||||||
'validate_callback' => 'rest_validate_request_arg',
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
register_rest_route(self::$namespace, '/' . self::$rest_base . '/documents', array(
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => array(__CLASS__, 'get_cart_documents'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array(__CLASS__, 'upload_cart_document'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(
|
||||||
|
'doc_type' => array(
|
||||||
|
'description' => __( 'Category of uploaded document.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'package_key' => array(
|
||||||
|
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
'type' => array(
|
||||||
|
'default' => 'wiaas_doc'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
register_rest_route(self::$namespace, '/' . self::$rest_base . '/items/(?P<key>[\w-]+)/documents/(?P<type>[\w-]+)', array(
|
||||||
|
'args' => array(
|
||||||
|
'key' => array(
|
||||||
|
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
),
|
||||||
|
'type' => array(
|
||||||
|
'description' => __( 'Cart document Type.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => array(__CLASS__, 'download_cart_document'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(
|
||||||
|
'document_key' => array(
|
||||||
|
'description' => __( 'Unique key identifier for cart document.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/checkout', array(
|
register_rest_route( self::$namespace, '/' . self::$rest_base . '/checkout', array(
|
||||||
'methods' => WP_REST_Server::CREATABLE,
|
'methods' => WP_REST_Server::CREATABLE,
|
||||||
'callback' => array(__CLASS__, 'checkout'),
|
'callback' => array(__CLASS__, 'checkout'),
|
||||||
@@ -158,6 +210,7 @@ class Wiaas_Cart_API {
|
|||||||
public static function get_cart_items() {
|
public static function get_cart_items() {
|
||||||
return rest_ensure_response(array(
|
return rest_ensure_response(array(
|
||||||
'items' => Wiaas_Cart::get_cart_packages(),
|
'items' => Wiaas_Cart::get_cart_packages(),
|
||||||
|
'raw' => WC()->cart->get_cart_contents(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +267,54 @@ class Wiaas_Cart_API {
|
|||||||
return wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
return wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrive cart documents info
|
||||||
|
*
|
||||||
|
* @return mixed|WP_REST_Response
|
||||||
|
*/
|
||||||
|
public static function get_cart_documents() {
|
||||||
|
return rest_ensure_response( Wiaas_Cart::get_cart_documents());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload document to cart
|
||||||
|
* @param WP_REST_Request $request
|
||||||
|
*
|
||||||
|
* @return mixed|WP_REST_Response
|
||||||
|
*/
|
||||||
|
public static function upload_cart_document($request) {
|
||||||
|
$result = Wiaas_Cart::upload_cart_document($request['doc_type'], $request['package_key']);
|
||||||
|
|
||||||
|
if (is_wp_error($result)) {
|
||||||
|
$error_code = $result->get_error_code();
|
||||||
|
|
||||||
|
if ($error_code === 'wiaas_upload_missing_file') {
|
||||||
|
return wiaas_api_generate_error('NO_FILE');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error_code === 'wiaas_upload_error') {
|
||||||
|
return wiaas_api_generate_error('UPLOAD_ERROR');
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_generate_error('NOT_LINKED_TO_CART');
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('FILE_UPLOADED', 'success', array(
|
||||||
|
'id_document' => $result,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download cart document
|
||||||
|
* @param WP_REST_Request $request
|
||||||
|
*/
|
||||||
|
public static function download_cart_document($request) {
|
||||||
|
Wiaas_Document_Download::download_cart_document(
|
||||||
|
$request['key'],
|
||||||
|
$request['type'],
|
||||||
|
$request['document_key']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param WP_REST_Request $request Request data.
|
* @param WP_REST_Request $request Request data.
|
||||||
|
|||||||
@@ -17,26 +17,73 @@ class Wiaas_Document_API {
|
|||||||
private static $namespace = 'wiaas';
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
register_rest_route( self::$namespace, 'download-package-file', array(
|
register_rest_route( self::$namespace, 'documents', array(
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
'permission_callback' => 'is_user_logged_in',
|
'permission_callback' => 'is_user_logged_in',
|
||||||
'callback' => array(__CLASS__, 'download_package_file'),
|
'callback' => array(__CLASS__, 'download_package_file'),
|
||||||
|
'args' => array(
|
||||||
|
'document_id' => array(
|
||||||
|
'description' => __( 'Document ID.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'documents/order/(?P<id>\d+)/(?P<type>[\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'),
|
||||||
|
'args' => array(
|
||||||
|
'item_id' => array(
|
||||||
|
'description' => __( 'Package Order Item ID.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
),
|
||||||
|
'document_key' => array(
|
||||||
|
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
'required' => true
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download package document
|
* Download package document
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request
|
||||||
*/
|
*/
|
||||||
public static function download_package_file() {
|
public static function download_package_file($request) {
|
||||||
$document_id = $_GET['document_id'];
|
$document_id = $request['document_id'];
|
||||||
$package_id = $_GET['package_id'];
|
|
||||||
|
|
||||||
$package = wc_get_product($package_id);
|
Wiaas_Document_Download::download_document($document_id);
|
||||||
|
}
|
||||||
|
|
||||||
$file = $package->get_file($document_id);
|
/**
|
||||||
|
* Download order document
|
||||||
if ($file) {
|
* @param WP_REST_Request $request
|
||||||
WC_Download_Handler::download_file_force($package->get_file_download_path($document_id), $file->get_name());
|
*/
|
||||||
}
|
public static function download_order_document($request) {
|
||||||
|
Wiaas_Document_Download::download_order_item_document(
|
||||||
|
$request['id'],
|
||||||
|
$request['item_id'],
|
||||||
|
$request['type'],
|
||||||
|
$request['document_key']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Cart_Documents {
|
||||||
|
|
||||||
|
private static $document_types = array(
|
||||||
|
'template_questionaire' => 'template_agreement',
|
||||||
|
'order_questionaire' => 'order_agreement'
|
||||||
|
);
|
||||||
|
|
||||||
|
public static function get_cart_documents() {
|
||||||
|
$packages_data = Wiaas_Cart::get_cart_packages();
|
||||||
|
|
||||||
|
$templates = array();
|
||||||
|
|
||||||
|
foreach ($packages_data as $package_data) {
|
||||||
|
$package = wc_get_product($packages_data['package_id']);
|
||||||
|
|
||||||
|
$documents = $package->get_downloads();
|
||||||
|
}
|
||||||
|
|
||||||
|
get_terms(array(
|
||||||
|
'taxonomy' => 'wiaas_document_types',
|
||||||
|
'include' => 'template_questionaire, order_questionaire'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function _get_packages_templates($packages) {
|
||||||
|
$documents_ids = array_map(function($package) {
|
||||||
|
return array_keys($package->get_downloads());
|
||||||
|
}, $packages);
|
||||||
|
|
||||||
|
wp_get_object_terms($documents_ids, 'wiaas_document_types', array(
|
||||||
|
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@ class Wiaas_Admin {
|
|||||||
|
|
||||||
// Admin order projects interface
|
// Admin order projects interface
|
||||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-projects.php';
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-projects.php';
|
||||||
|
// Admin documents
|
||||||
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
*/
|
*/
|
||||||
class Wiaas_Cart {
|
class Wiaas_Cart {
|
||||||
|
|
||||||
|
private static $cart_doc_types = array(
|
||||||
|
'template_questionaire' => 'order_questionaire',
|
||||||
|
'template_agreement' => 'order_agreement'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||||
@@ -24,6 +29,76 @@ class Wiaas_Cart {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve cart documents (templates and uploded documents)
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_cart_documents() {
|
||||||
|
$templates = self::_get_cart_templates();
|
||||||
|
$uploaded_documents = self::_get_cart_uploaded_documents();
|
||||||
|
|
||||||
|
$has_pending_uploads = false;
|
||||||
|
|
||||||
|
foreach ($templates as $type => $package_documents) {
|
||||||
|
$uploaded_type = self::$cart_doc_types[$type];
|
||||||
|
|
||||||
|
if (!isset($uploaded_documents[$uploaded_type])) {
|
||||||
|
$has_pending_uploads = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$uploaded_package_documents = $uploaded_documents[$uploaded_type];
|
||||||
|
|
||||||
|
foreach ($package_documents as $package_id => $package_document) {
|
||||||
|
if (!isset($uploaded_package_documents[$package_id])) {
|
||||||
|
$has_pending_uploads = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'templates' => $templates,
|
||||||
|
'uploaded' => $uploaded_documents,
|
||||||
|
'pending' => $has_pending_uploads
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Uploaded document for cart
|
||||||
|
*
|
||||||
|
* @param $doc_type
|
||||||
|
* @param $package_item_key
|
||||||
|
*
|
||||||
|
* @return string | WP_Error
|
||||||
|
*/
|
||||||
|
public static function upload_cart_document($doc_type, $package_item_key) {
|
||||||
|
try {
|
||||||
|
$version = Wiaas_Document_Upload::upload_document_version();
|
||||||
|
|
||||||
|
if (is_wp_error($version)) {
|
||||||
|
return $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_document = array(
|
||||||
|
'version' => $version,
|
||||||
|
'key' => wp_generate_uuid4(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// persist uploaded cart document in cart
|
||||||
|
WC()->cart->cart_contents[ $package_item_key ]['_wiaas_documents'][$doc_type] = $cart_document;
|
||||||
|
|
||||||
|
// persist changes to cart session
|
||||||
|
// Note: TODO Refactor this logic of persisting updates made to cart
|
||||||
|
$s = new WC_Cart_Session(WC()->cart);
|
||||||
|
$s->set_session();
|
||||||
|
|
||||||
|
return $cart_document['key'];
|
||||||
|
|
||||||
|
} catch( Exception $e) {
|
||||||
|
return new WP_Error('wiass_cart_upload_error', 'Error while uploading cart file!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles adding standard wiaas package to cart along with selected addons and options
|
* Handles adding standard wiaas package to cart along with selected addons and options
|
||||||
*
|
*
|
||||||
@@ -61,7 +136,8 @@ class Wiaas_Cart {
|
|||||||
'_wiaas_addon_items' => array(),
|
'_wiaas_addon_items' => array(),
|
||||||
'_wiaas_option_items' => array(),
|
'_wiaas_option_items' => array(),
|
||||||
'_wiaas_currency' => isset($country) ? $country['currency'] : get_woocommerce_currency(),
|
'_wiaas_currency' => isset($country) ? $country['currency'] : get_woocommerce_currency(),
|
||||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null
|
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||||
|
'_wiaas_documents' => array()
|
||||||
);
|
);
|
||||||
|
|
||||||
$cart_item_key = WC()->cart->add_to_cart($package_id, 1, 0, array(), $wiaas_cart_item_data);
|
$cart_item_key = WC()->cart->add_to_cart($package_id, 1, 0, array(), $wiaas_cart_item_data);
|
||||||
@@ -79,8 +155,6 @@ class Wiaas_Cart {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch( Exception $e) {
|
} catch( Exception $e) {
|
||||||
|
|
||||||
error_log($e->getMessage());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +255,7 @@ class Wiaas_Cart {
|
|||||||
* @param $cart_item
|
* @param $cart_item
|
||||||
* @param $order
|
* @param $order
|
||||||
*
|
*
|
||||||
* @return array
|
* @return WC_Order_Item
|
||||||
*/
|
*/
|
||||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
|
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
|
||||||
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
|
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
|
||||||
@@ -224,6 +298,40 @@ class Wiaas_Cart {
|
|||||||
if (isset($cart_item['_wiaas_addon_for'])) {
|
if (isset($cart_item['_wiaas_addon_for'])) {
|
||||||
$order_item->add_meta_data( '_wiaas_addon_for', $cart_item['_wiaas_addon_for'], true );
|
$order_item->add_meta_data( '_wiaas_addon_for', $cart_item['_wiaas_addon_for'], true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add documents associated with the item
|
||||||
|
$cart_documents = isset($cart_item['_wiaas_documents']) ? $cart_item['_wiaas_documents'] : array();
|
||||||
|
$attachment_document_ids = wiaas_get_object_attached_documents($cart_item['product_id']);
|
||||||
|
$item_documents = array();
|
||||||
|
|
||||||
|
foreach ($cart_documents as $type => $cart_document) {
|
||||||
|
$item_documents[] = array(
|
||||||
|
'key' => $cart_document['key'],
|
||||||
|
'version' => $cart_document['version'],
|
||||||
|
'type' => $type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($attachment_document_ids as $attachment_document_id) {
|
||||||
|
$doc_info = Wiaas_Document::get_doc_info($attachment_document_id);
|
||||||
|
|
||||||
|
// add customer visible attachment documents to order
|
||||||
|
if ($doc_info['visible'] || !$doc_info['type']) {
|
||||||
|
$item_documents[] = array(
|
||||||
|
'key' => wp_generate_uuid4(),
|
||||||
|
'name' => $doc_info['name'],
|
||||||
|
'version' => $doc_info['version'],
|
||||||
|
'type' => $doc_info['type']['id'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($item_documents) > 0) {
|
||||||
|
$order_item->add_meta_data( '_wiaas_documents', $item_documents, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $order_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -249,6 +357,7 @@ class Wiaas_Cart {
|
|||||||
'_wiaas_option_group_name',
|
'_wiaas_option_group_name',
|
||||||
'_wiaas_standard_package',
|
'_wiaas_standard_package',
|
||||||
'_wiaas_currency',
|
'_wiaas_currency',
|
||||||
|
'_wiaas_documents'
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,6 +510,103 @@ class Wiaas_Cart {
|
|||||||
|
|
||||||
//PRIVATE
|
//PRIVATE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve cart templates
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function _get_cart_templates() {
|
||||||
|
$items = WC()->cart->get_cart_contents();
|
||||||
|
|
||||||
|
$documents_ids = array();
|
||||||
|
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
if (!isset($item['_wiaas_standard_package'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$package_documents_ids = get_post_meta(
|
||||||
|
$item['product_id'],
|
||||||
|
'_wiaas_attached_documents',
|
||||||
|
true);
|
||||||
|
|
||||||
|
foreach ($package_documents_ids as $package_document_id) {
|
||||||
|
$package_document_id = absint($package_document_id);
|
||||||
|
$documents_ids[$package_document_id] ?: array();
|
||||||
|
$documents_ids[$package_document_id][] = $item['product_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$q = new WP_Query();
|
||||||
|
$retrieved_items = $q->query(array(
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'post_type' => 'wiaas_doc',
|
||||||
|
'post__in' => array_keys($documents_ids),
|
||||||
|
'tax_query' => array(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'wiaas_doc_type',
|
||||||
|
'field' => 'slug',
|
||||||
|
'terms' => array_keys(self::$cart_doc_types),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$cart_documents = array();
|
||||||
|
|
||||||
|
foreach ($retrieved_items as $retrieved_item) {
|
||||||
|
|
||||||
|
$doc_info = Wiaas_Document::get_doc_info($retrieved_item->ID);
|
||||||
|
$type = $doc_info['type']['id'];
|
||||||
|
|
||||||
|
$cart_documents[$type] ?: array();
|
||||||
|
|
||||||
|
$package_ids = $documents_ids[$doc_info['id']] ?: array();
|
||||||
|
foreach ($package_ids as $package_id) {
|
||||||
|
$cart_documents[$type][$package_id] = array(
|
||||||
|
'id' => $doc_info['id'],
|
||||||
|
'name' => $doc_info['name'],
|
||||||
|
'type' => $type,
|
||||||
|
'extension' => $doc_info['extension']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cart_documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve cart uploaded documents
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function _get_cart_uploaded_documents() {
|
||||||
|
$items = WC()->cart->get_cart_contents();
|
||||||
|
|
||||||
|
$cart_documents = array();
|
||||||
|
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
if (!isset($item['_wiaas_standard_package'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$package_id = $item['product_id'];
|
||||||
|
|
||||||
|
$documents = isset($item['_wiaas_documents']) ? $item['_wiaas_documents'] : array();
|
||||||
|
|
||||||
|
foreach ($documents as $type => $document) {
|
||||||
|
$cart_documents[$type] ?: array();
|
||||||
|
$cart_documents[$type][$package_id] = array(
|
||||||
|
'key' => $document['key'],
|
||||||
|
'name' => wiaas_get_doc_version_filename($document['version']),
|
||||||
|
'type' => $type,
|
||||||
|
'extension' => wiaas_get_doc_version_extension($document['version'])
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cart_documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add selected package options and addons after parent standard package is added to cart
|
* Add selected package options and addons after parent standard package is added to cart
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ class Wiaas_DB_Update {
|
|||||||
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
|
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
|
||||||
'20180801222206' => 'wiaas_db_update_setup_gravity',
|
'20180801222206' => 'wiaas_db_update_setup_gravity',
|
||||||
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
|
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
|
||||||
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
|
|
||||||
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
|
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
|
||||||
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
|
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
|
||||||
'20180826153509' => 'wiaas_create_broker_access_group',
|
'20180826153509' => 'wiaas_create_broker_access_group',
|
||||||
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
|
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
|
||||||
'20180912101010' => 'wiaas_db_setup_default_cl'
|
'20180912101010' => 'wiaas_db_setup_default_cl',
|
||||||
|
'20181003164100' => 'wiaas_db_setup_customer_capabilities'
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function execute() {
|
public static function execute() {
|
||||||
|
|||||||
@@ -5,98 +5,21 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements Wiaas Document types
|
* Implements Wiaas Documents
|
||||||
*
|
*
|
||||||
* Class Wiaas_Documents
|
* Class Wiaas_Documents
|
||||||
*/
|
*/
|
||||||
class Wiaas_Documents {
|
class Wiaas_Documents {
|
||||||
|
|
||||||
/**
|
|
||||||
* Default available document types for wiaas
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $available_doc_types = array(
|
|
||||||
'template_questionaire' => array(
|
|
||||||
'name' => 'Template Questionaire',
|
|
||||||
'is_special_type' => false,
|
|
||||||
),
|
|
||||||
'order_questionaire' => array(
|
|
||||||
'name' => 'Order Questionaire',
|
|
||||||
'is_special_type' => true,
|
|
||||||
),
|
|
||||||
'configuration' => array(
|
|
||||||
'name' => 'Configuration',
|
|
||||||
'is_special_type' => true,
|
|
||||||
),
|
|
||||||
'install_guide' => array(
|
|
||||||
'name' => 'Install guide',
|
|
||||||
'is_special_type' => false,
|
|
||||||
),
|
|
||||||
'customer_acceptance' => array(
|
|
||||||
'name' => 'Customer acceptance',
|
|
||||||
'is_special_type' => true,
|
|
||||||
),
|
|
||||||
'template_agreement' => array(
|
|
||||||
'name' => 'Template Agreement',
|
|
||||||
'is_special_type' => false,
|
|
||||||
),
|
|
||||||
'order_agreement' => array(
|
|
||||||
'name' => 'Order Agreement',
|
|
||||||
'is_special_type' => true,
|
|
||||||
),
|
|
||||||
'installation_protocol' => array(
|
|
||||||
'name' => 'Installation protocol',
|
|
||||||
'is_special_type' => true,
|
|
||||||
),
|
|
||||||
'statements' => array(
|
|
||||||
'name' => 'Statements',
|
|
||||||
'is_special_type' => false,
|
|
||||||
),
|
|
||||||
'customer_acceptance_template' => array(
|
|
||||||
'name' => 'Customer acceptance template',
|
|
||||||
'is_special_type' => false,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
add_action( 'init', array( __CLASS__, 'register_wiaas_document_types' ));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
require_once dirname( __FILE__ ) . '/document/class-wiaas-document.php';
|
||||||
* Registers taxonomy and default values for wiaas document types
|
|
||||||
*/
|
|
||||||
public static function register_wiaas_document_types() {
|
|
||||||
$labels = array(
|
|
||||||
'name' => _x( 'Document type', 'taxonomy general name', 'wiaas' ),
|
|
||||||
'singular_name' => _x( 'Document type', 'taxonomy singular name', 'wiaas' ),
|
|
||||||
'menu_name' => _x( 'Document types', 'Admin menu name', 'wiaas' ),
|
|
||||||
'search_items' => __( 'Search Document types', 'wiaas' ),
|
|
||||||
'all_items' => __( 'All Document types', 'wiaas' ),
|
|
||||||
'parent_item' => __( 'Parent Document type', 'wiaas' ),
|
|
||||||
'parent_item_colon' => __( 'Parent Document type:', 'wiaas' ),
|
|
||||||
'edit_item' => __( 'Edit Document type', 'wiaas' ),
|
|
||||||
'update_item' => __( 'Update Document type', 'wiaas' ),
|
|
||||||
'add_new_item' => __( 'Add New Document type', 'wiaas' ),
|
|
||||||
'new_item_name' => __( 'New Document type Name', 'wiaas' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$args = array(
|
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-upload.php';
|
||||||
'hierarchical' => false,
|
|
||||||
'label' => __( 'Document types', 'wiaas' ),
|
|
||||||
'labels' => $labels,
|
|
||||||
'show_ui' => true,
|
|
||||||
'show_admin_column' => true,
|
|
||||||
'query_var' => true,
|
|
||||||
'rewrite' => array( 'slug' => 'wiaas_document_types' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
register_taxonomy( 'wiaas_document_types', array( 'attachment' ), $args );
|
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-download.php';
|
||||||
|
|
||||||
foreach (self::$available_doc_types as $key => $available_doc_type) {
|
require_once dirname( __FILE__ ) . '/document/wiaas-document-functions.php';
|
||||||
wp_insert_term($available_doc_type['name'], 'wiaas_document_types', array(
|
|
||||||
'slug' => $key
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,6 +243,9 @@ class Wiaas_Order {
|
|||||||
// add only product lines that represent product bundles
|
// add only product lines that represent product bundles
|
||||||
if (isset($item['wiaas_standard_package'])) {
|
if (isset($item['wiaas_standard_package'])) {
|
||||||
|
|
||||||
|
// get documents
|
||||||
|
$product_line['documents'] = wiaas_get_package_order_item_documents($order, $product_line['id']);
|
||||||
|
|
||||||
# get payment type info
|
# get payment type info
|
||||||
$product_line['payment_type'] = $item['wiaas_payment_type'];
|
$product_line['payment_type'] = $item['wiaas_payment_type'];
|
||||||
$product_line['service_price'] = floatval($item['wiaas_services_extra']);
|
$product_line['service_price'] = floatval($item['wiaas_services_extra']);
|
||||||
|
|||||||
@@ -54,15 +54,11 @@ class Wiaas_Package {
|
|||||||
*/
|
*/
|
||||||
private static function _append_documents_info($data, $package, $request) {
|
private static function _append_documents_info($data, $package, $request) {
|
||||||
|
|
||||||
unset($data['downloads']);
|
$data['documents'] = array_map(function($doc) {
|
||||||
|
unset($doc['url']);
|
||||||
$data['documents'] = array_map(function($download) {
|
unset($doc['version']);
|
||||||
return array(
|
return $doc;
|
||||||
'id' => $download->get_id(),
|
}, wiaas_get_all_package_documents($package, true));
|
||||||
'name' => $download->get_name(),
|
|
||||||
'extension' => $download->get_file_extension(),
|
|
||||||
);
|
|
||||||
}, array_values($package->get_downloads()));
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,16 +78,6 @@ function wiaas_db_update_add_delivery_process_forms() {
|
|||||||
do_action('gform_forms_post_import', $created_forms);
|
do_action('gform_forms_post_import', $created_forms);
|
||||||
}
|
}
|
||||||
|
|
||||||
function wiaas_db_update_setup_customer_capabilities() {
|
|
||||||
$customer_role = get_role('customer');
|
|
||||||
|
|
||||||
$customer_role->add_cap('read_private_shop_orders');
|
|
||||||
$customer_role->add_cap('read_private_products');
|
|
||||||
$customer_role->add_cap('read_shop_order');
|
|
||||||
$customer_role->add_cap('publish_shop_orders');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function wiaas_db_update_enable_orders_access_management() {
|
function wiaas_db_update_enable_orders_access_management() {
|
||||||
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
||||||
|
|
||||||
@@ -125,4 +115,18 @@ function wiaas_db_setup_exclusive_taxonomies() {
|
|||||||
|
|
||||||
function wiaas_db_setup_default_cl() {
|
function wiaas_db_setup_default_cl() {
|
||||||
wp_insert_term(Wiaas_Pricing::COMMERCIAL_LEAD_NAME, Wiaas_User_Organization::TAXONOMY_NAME);
|
wp_insert_term(Wiaas_Pricing::COMMERCIAL_LEAD_NAME, Wiaas_User_Organization::TAXONOMY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_db_setup_customer_capabilities() {
|
||||||
|
$customer_role = get_role('customer');
|
||||||
|
|
||||||
|
$customer_role->add_cap('read_private_shop_orders');
|
||||||
|
$customer_role->add_cap('read_private_products');
|
||||||
|
$customer_role->add_cap('read_shop_order');
|
||||||
|
$customer_role->add_cap('publish_shop_orders');
|
||||||
|
|
||||||
|
// user
|
||||||
|
$customer_role->add_cap('list_users');
|
||||||
|
$customer_role->add_cap('edit_users');
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle download requests for wiaas documents
|
||||||
|
*
|
||||||
|
* Class Wiaas_Document_Download
|
||||||
|
*/
|
||||||
|
class Wiaas_Document_Download {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
// register download trigger for downloads from admin panel
|
||||||
|
if ( is_admin() && isset($_GET['wiaasdoc']) ) {
|
||||||
|
add_action( 'init', array( __CLASS__, 'admin_download' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download document from admin panel
|
||||||
|
*/
|
||||||
|
public static function admin_download() {
|
||||||
|
|
||||||
|
if (!is_user_logged_in()) {
|
||||||
|
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$document_id = (int)$_GET['wiaasdoc'];
|
||||||
|
if ($document_id <= 0) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = isset($_GET['v']) ? (int)$_GET['v'] : null;
|
||||||
|
|
||||||
|
self::download_document($document_id, $version);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download latest or specific document version
|
||||||
|
* @param $document_id
|
||||||
|
* @param null $version_id
|
||||||
|
*/
|
||||||
|
public static function download_document($document_id, $version_id = null) {
|
||||||
|
$version = Wiaas_Document::get_doc_version($document_id, $version_id);
|
||||||
|
|
||||||
|
$file_path = wiaas_get_document_version_path($version);
|
||||||
|
|
||||||
|
if (!file_exists($file_path)) {
|
||||||
|
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
WC_Download_Handler::download_file_force(
|
||||||
|
$file_path,
|
||||||
|
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download document related to order item
|
||||||
|
*
|
||||||
|
* @param $order_id
|
||||||
|
* @param $item_id
|
||||||
|
* @param $type
|
||||||
|
* @param $document_key
|
||||||
|
*/
|
||||||
|
public static function download_order_item_document($order_id, $item_id, $type, $document_key) {
|
||||||
|
$order = wc_get_order($order_id);
|
||||||
|
if (!$order) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = $order->get_item($item_id);
|
||||||
|
if (!$item) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$item_documents = $item['wiaas_documents'];
|
||||||
|
|
||||||
|
$order_document = null;
|
||||||
|
foreach ($item_documents as $item_document) {
|
||||||
|
if ($item_document['key'] === $document_key && $item_document['type'] === $type) {
|
||||||
|
$order_document = $item_document;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($order_document)) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_path = wiaas_get_document_version_path($order_document['version']);
|
||||||
|
|
||||||
|
if (!file_exists($file_path)) {
|
||||||
|
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
WC_Download_Handler::download_file_force(
|
||||||
|
$file_path,
|
||||||
|
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download cart document
|
||||||
|
*
|
||||||
|
* @param $item_key
|
||||||
|
* @param $type
|
||||||
|
* @param $document_key
|
||||||
|
*/
|
||||||
|
public static function download_cart_document($item_key, $type, $document_key) {
|
||||||
|
$item = WC()->cart->get_cart_item($item_key);
|
||||||
|
if (!isset($item)) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$item_documents = $item['_wiaas_documents'];
|
||||||
|
if (!isset($item_documents) ||
|
||||||
|
empty($item_documents) ||
|
||||||
|
!array_key_exists($type, $item_documents)) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$cart_document = $item_documents[$type];
|
||||||
|
if ($cart_document['key'] !== $document_key) {
|
||||||
|
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_path = wiaas_get_document_version_path($cart_document['version']);
|
||||||
|
|
||||||
|
if (!file_exists($file_path)) {
|
||||||
|
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
WC_Download_Handler::download_file_force(
|
||||||
|
$file_path,
|
||||||
|
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Document_Download::init();
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Document_Upload {
|
||||||
|
|
||||||
|
private static $allowed_extensions = array(
|
||||||
|
'pdf','docx','doc','xlsx','xls','odt','ods', 'zip'
|
||||||
|
);
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
add_filter( 'upload_dir', array( __CLASS__, 'upload_dir' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allowed extensions for wiaas documents uploads
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function allowed_extensions() {
|
||||||
|
return self::$allowed_extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle wiaas document upload
|
||||||
|
*
|
||||||
|
* @param string $file_id
|
||||||
|
*
|
||||||
|
* @return int|WP_Error
|
||||||
|
*/
|
||||||
|
public static function upload_document_version($file_id = 'file') {
|
||||||
|
|
||||||
|
wc_maybe_define_constant( 'WIAAS_DOCUMENT_UPLOAD', true );
|
||||||
|
|
||||||
|
// validate file
|
||||||
|
|
||||||
|
if (!isset($_FILES[$file_id])) {
|
||||||
|
return new WP_Error( 'wiaas_upload_missing_file', 'No file!' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_name = $_FILES[$file_id]['name'];
|
||||||
|
$name = esc_attr($file_name);
|
||||||
|
|
||||||
|
$ext = explode('.', $name);
|
||||||
|
$ext = end($ext);
|
||||||
|
$ext = strtolower($ext);
|
||||||
|
|
||||||
|
if(!in_array($ext, self::$allowed_extensions)) {
|
||||||
|
return new WP_Error( 'wiaas_upload_error', 'Invalid file extension!' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = wp_handle_upload(
|
||||||
|
$_FILES[$file_id],
|
||||||
|
array( 'test_form' => false ),
|
||||||
|
current_time('mysql'));
|
||||||
|
|
||||||
|
if ( isset($file['error']) )
|
||||||
|
return new WP_Error( 'wiaas_upload_error', $file['error'] );
|
||||||
|
|
||||||
|
return wiaas_get_doc_version_from_path($file['file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates wordpress upload dir so that wiaas documents are uploaded to wiaas specific upload dir
|
||||||
|
* @param $pathdata
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function upload_dir( $pathdata ) {
|
||||||
|
|
||||||
|
if (defined('WIAAS_DOCUMENT_UPLOAD') ) {
|
||||||
|
if ( empty( $pathdata['subdir'] ) ) {
|
||||||
|
$pathdata['path'] = $pathdata['path'] . wiaas_documents_base_dir();
|
||||||
|
$pathdata['url'] = $pathdata['url'] . wiaas_documents_base_dir();
|
||||||
|
$pathdata['subdir'] = wiaas_documents_base_dir();
|
||||||
|
} else {
|
||||||
|
$new_subdir = wiaas_documents_base_dir() . $pathdata['subdir'];
|
||||||
|
|
||||||
|
$pathdata['path'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['path'] );
|
||||||
|
$pathdata['url'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['url'] );
|
||||||
|
$pathdata['subdir'] = str_replace( $pathdata['subdir'], $new_subdir, $pathdata['subdir'] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pathdata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Document_Upload::init();
|
||||||
@@ -0,0 +1,406 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_Document
|
||||||
|
*/
|
||||||
|
class Wiaas_Document {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default available document types for wiaas
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $available_doc_types = array(
|
||||||
|
'template_questionaire' => array(
|
||||||
|
'name' => 'Template Questionaire',
|
||||||
|
'is_special_type' => false,
|
||||||
|
),
|
||||||
|
'order_questionaire' => array(
|
||||||
|
'name' => 'Order Questionaire',
|
||||||
|
'is_special_type' => true,
|
||||||
|
),
|
||||||
|
'configuration' => array(
|
||||||
|
'name' => 'Configuration',
|
||||||
|
'is_special_type' => true,
|
||||||
|
),
|
||||||
|
'install_guide' => array(
|
||||||
|
'name' => 'Install guide',
|
||||||
|
'is_special_type' => false,
|
||||||
|
),
|
||||||
|
'customer_acceptance' => array(
|
||||||
|
'name' => 'Customer acceptance',
|
||||||
|
'is_special_type' => true,
|
||||||
|
),
|
||||||
|
'template_agreement' => array(
|
||||||
|
'name' => 'Template Agreement',
|
||||||
|
'is_special_type' => false,
|
||||||
|
),
|
||||||
|
'order_agreement' => array(
|
||||||
|
'name' => 'Order Agreement',
|
||||||
|
'is_special_type' => true,
|
||||||
|
),
|
||||||
|
'installation_protocol' => array(
|
||||||
|
'name' => 'Installation protocol',
|
||||||
|
'is_special_type' => true,
|
||||||
|
),
|
||||||
|
'statements' => array(
|
||||||
|
'name' => 'Statements',
|
||||||
|
'is_special_type' => false,
|
||||||
|
),
|
||||||
|
'customer_acceptance_template' => array(
|
||||||
|
'name' => 'Customer acceptance template',
|
||||||
|
'is_special_type' => false,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
private static $special_doc_types= array(
|
||||||
|
'order_questionaire', 'configuration', 'customer_acceptance', 'order_agreement', 'installation_protocol'
|
||||||
|
);
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
|
||||||
|
add_action('registered_taxonomy', array( __CLASS__, 'register_wiaas_doc_categories' ));
|
||||||
|
|
||||||
|
add_action('init', array(__CLASS__, 'register_wiaas_document'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve available categories for wiaas documents
|
||||||
|
*
|
||||||
|
* @return array Array of available document categories
|
||||||
|
*/
|
||||||
|
public static function get_available_doc_types() {
|
||||||
|
|
||||||
|
$terms = get_terms(array(
|
||||||
|
'taxonomy' => 'wiaas_doc_type',
|
||||||
|
'hide_empty' => false,
|
||||||
|
));
|
||||||
|
|
||||||
|
return array_map(function($term) {
|
||||||
|
$is_special = array_key_exists($term->slug, self::$available_doc_types) ?
|
||||||
|
self::$available_doc_types[$term->slug]['is_special_type'] :
|
||||||
|
false;
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'id' => $term->slug,
|
||||||
|
'name' => $term->name,
|
||||||
|
'is_special_type' => $is_special,
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
}, $terms);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new document
|
||||||
|
* @param $name
|
||||||
|
* @param $path
|
||||||
|
* @param bool $visible
|
||||||
|
*
|
||||||
|
* @return bool|int|WP_Error
|
||||||
|
*/
|
||||||
|
public static function add_document($name, $path, $visible = false) {
|
||||||
|
// create
|
||||||
|
$id = wp_insert_post( array(
|
||||||
|
'post_title' => $name,
|
||||||
|
'post_author' => wp_get_current_user()->ID,
|
||||||
|
'post_type' => 'wiaas_doc',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
) );
|
||||||
|
|
||||||
|
if ( is_wp_error( $id ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log(gettype($visible));
|
||||||
|
|
||||||
|
update_post_meta($id, '_wiaas_doc_versions', array( $path ));
|
||||||
|
|
||||||
|
self::set_is_doc_visible($id, $visible);
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new version for document
|
||||||
|
* @param $doc_id
|
||||||
|
* @param $url
|
||||||
|
*/
|
||||||
|
public static function add_document_version($doc_id, $url) {
|
||||||
|
$versions = get_post_meta($doc_id, '_wiaas_doc_versions', true);
|
||||||
|
|
||||||
|
$versions[] = $url;
|
||||||
|
|
||||||
|
update_post_meta($doc_id, '_wiaas_doc_versions', $versions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign type to document
|
||||||
|
* @param $id
|
||||||
|
* @param $type
|
||||||
|
*/
|
||||||
|
public static function set_doc_type($id, $type) {
|
||||||
|
wp_set_object_terms($id, $type, 'wiaas_doc_type');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set if document visible to customer
|
||||||
|
* @param $id
|
||||||
|
* @param $is_visible
|
||||||
|
*/
|
||||||
|
public static function set_is_doc_visible($id, $is_visible) {
|
||||||
|
|
||||||
|
update_post_meta($id, '_wiaas_doc_visible', $is_visible ? 'yes' : 'no');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve document type
|
||||||
|
* @param $id
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public static function get_doc_type($id) {
|
||||||
|
$terms = wp_get_object_terms($id, 'wiaas_doc_type');
|
||||||
|
|
||||||
|
if (is_wp_error($terms) || count($terms) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$term = $terms[0];
|
||||||
|
return array(
|
||||||
|
'id' => $term->slug,
|
||||||
|
'name' => $term->name,
|
||||||
|
'is_special_type' => in_array($term->slug, self::$special_doc_types),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve if document visible to customer
|
||||||
|
* @param $id
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function is_doc_visible($id) {
|
||||||
|
return get_post_meta($id, '_wiaas_doc_visible', true) === 'yes';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all versions for document
|
||||||
|
* @param $doc_id
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function get_document_versions($doc_id) {
|
||||||
|
return get_post_meta($doc_id, '_wiaas_doc_versions', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get latest or specific document version
|
||||||
|
* @param $id
|
||||||
|
* @param null $version_id
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public static function get_doc_version($id, $version_id = null) {
|
||||||
|
$versions = self::get_document_versions($id);
|
||||||
|
|
||||||
|
if (count($versions) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isset($versions[$version_id]) ?
|
||||||
|
$versions[$version_id] : $versions[count($versions) - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get document download link for latest or specified version
|
||||||
|
* @param $id
|
||||||
|
* @param null $version
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_doc_download_link($id, $version = null) {
|
||||||
|
$permalink = get_permalink($id);
|
||||||
|
$sap = strpos($permalink, '?')?'&':'?';
|
||||||
|
|
||||||
|
$ver = isset($version) ? "&v={$version}" : '';
|
||||||
|
return $permalink.$sap."wiaasdoc={$id}{$ver}";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve document informations
|
||||||
|
* @param $id
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public static function get_doc_info($id) {
|
||||||
|
$post = get_post($id, ARRAY_A);
|
||||||
|
|
||||||
|
if (!$post) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = self::get_doc_version($id);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'id' => $id,
|
||||||
|
'name' => $post['post_title'],
|
||||||
|
'url' => self::get_doc_download_link($id),
|
||||||
|
'type' => self::get_doc_type($id),
|
||||||
|
'version' => $version,
|
||||||
|
'visible' => self::is_doc_visible($id),
|
||||||
|
'extension' => wiaas_get_doc_version_extension($version),
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search document by name
|
||||||
|
* @param $name
|
||||||
|
* @param int $limit
|
||||||
|
* @param bool $include_special
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function search($name, $limit = 10, $include_special = false) {
|
||||||
|
$query = new WP_Query();
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'post_type' => 'wiaas_doc',
|
||||||
|
'posts_per_page' => $limit,
|
||||||
|
's' => $name
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$include_special) {
|
||||||
|
$args['tax_query'] = array(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'wiaas_doc_type',
|
||||||
|
'field' => 'slug',
|
||||||
|
'operator' => 'NOT IN',
|
||||||
|
'terms' => self::$special_doc_types,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$items = $query->query($args);
|
||||||
|
|
||||||
|
return array_map(function($item) {
|
||||||
|
$id = $item->ID;
|
||||||
|
return array(
|
||||||
|
'id' => $id,
|
||||||
|
'name' => $item->post_title,
|
||||||
|
);
|
||||||
|
}, $items);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers taxonomy and default values for wiaas document types
|
||||||
|
*/
|
||||||
|
public static function register_wiaas_doc_categories($taxonomy) {
|
||||||
|
|
||||||
|
if ($taxonomy !== 'wpdmcategory') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::$available_doc_types as $key => $available_doc_type) {
|
||||||
|
wp_insert_term($available_doc_type['name'], 'wpdmcategory', array(
|
||||||
|
'slug' => $key
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function register_wiaas_document() {
|
||||||
|
// Register document object
|
||||||
|
self::_register_document();
|
||||||
|
// Register document types taxonomy
|
||||||
|
self::_register_doc_types();
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRIVATE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register wiaas_doc post type
|
||||||
|
*/
|
||||||
|
private static function _register_document() {
|
||||||
|
$labels = array(
|
||||||
|
'name' => __('Documents','wiaas'),
|
||||||
|
'singular_name' => __('Document','wiaas'),
|
||||||
|
'add_new' => __('Add New','wiaas'),
|
||||||
|
'add_new_item' => __('Add New Document','wiaas'),
|
||||||
|
'edit_item' => __('Edit Document','wiaas'),
|
||||||
|
'new_item' => __('New Document','wiaas'),
|
||||||
|
'all_items' => __('All Documents','wiaas'),
|
||||||
|
'view_item' => __('View Document','wiaas'),
|
||||||
|
'search_items' => __('Search Documents','wiaas'),
|
||||||
|
'not_found' => __('No Document Found','wiaas'),
|
||||||
|
'not_found_in_trash' => __('No Documents found in Trash','wiaas'),
|
||||||
|
'parent_item_colon' => '',
|
||||||
|
'menu_name' => __('Documents','wiaas')
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'labels' => $labels,
|
||||||
|
'public' => true,
|
||||||
|
'publicly_queryable' => false,
|
||||||
|
'show_ui' => true,
|
||||||
|
'show_in_menu' => true,
|
||||||
|
'show_in_nav_menus' => true,
|
||||||
|
'query_var' => true,
|
||||||
|
'rewrite' => array('slug' => 'wiaas_doc', 'with_front' => false),
|
||||||
|
'capability_type' => 'post',
|
||||||
|
'has_archive' => false,
|
||||||
|
'hierarchical' => false,
|
||||||
|
'taxonomies' => array(),
|
||||||
|
'menu_icon' => 'dashicons-media-document',
|
||||||
|
'exclude_from_search' => false,
|
||||||
|
'supports' => array('title')
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
register_post_type('wiaas_doc', $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register wiaas_doc_type taxonomy for wiaas_doc post type
|
||||||
|
*/
|
||||||
|
private static function _register_doc_types() {
|
||||||
|
$labels = array(
|
||||||
|
'name' => _x( 'Document type', 'taxonomy general name', 'wiaas' ),
|
||||||
|
'singular_name' => _x( 'Document type', 'taxonomy singular name', 'wiaas' ),
|
||||||
|
'menu_name' => _x( 'Document types', 'Admin menu name', 'wiaas' ),
|
||||||
|
'search_items' => __( 'Search Document types', 'wiaas' ),
|
||||||
|
'all_items' => __( 'All Document types', 'wiaas' ),
|
||||||
|
'parent_item' => __( 'Parent Document type', 'wiaas' ),
|
||||||
|
'parent_item_colon' => __( 'Parent Document type:', 'wiaas' ),
|
||||||
|
'edit_item' => __( 'Edit Document type', 'wiaas' ),
|
||||||
|
'update_item' => __( 'Update Document type', 'wiaas' ),
|
||||||
|
'add_new_item' => __( 'Add New Document type', 'wiaas' ),
|
||||||
|
'new_item_name' => __( 'New Document type Name', 'wiaas' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'hierarchical' => false,
|
||||||
|
'label' => __( 'Document type', 'wiaas' ),
|
||||||
|
'labels' => $labels,
|
||||||
|
'show_ui' => true,
|
||||||
|
'show_admin_column' => true,
|
||||||
|
'query_var' => true,
|
||||||
|
'rewrite' => array( 'slug' => 'wiaas_doc_type' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
register_taxonomy( 'wiaas_doc_type', array( 'wiaas_doc' ), $args );
|
||||||
|
|
||||||
|
foreach (self::$available_doc_types as $key => $available_doc_type) {
|
||||||
|
wp_insert_term($available_doc_type['name'], 'wiaas_doc_type', array(
|
||||||
|
'slug' => $key
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Document::init();
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base directory for wiaas document uploads
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function wiaas_documents_base_dir() {
|
||||||
|
return '/woocommerce_uploads';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload directory for wiaas document uploads
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function wiaas_documents_upload_dir() {
|
||||||
|
$wp_uploads = wp_upload_dir();
|
||||||
|
$wp_uploads_dir = $wp_uploads['basedir'];
|
||||||
|
|
||||||
|
return $wp_uploads_dir . wiaas_documents_base_dir();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve upload path for wiaas document version
|
||||||
|
* @param string $version
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function wiaas_get_document_version_path($version) {
|
||||||
|
return wiaas_documents_upload_dir() . '/' . $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve if wiaas document version exists
|
||||||
|
* @param string $version
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function wiaas_document_version_exists($version) {
|
||||||
|
return file_exists(wiaas_get_document_version_path($version));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve wiaas document version from file path
|
||||||
|
* (that is relative path from wiaas document upload dir)
|
||||||
|
* @param string $path
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function wiaas_get_doc_version_from_path($path) {
|
||||||
|
return str_replace(wiaas_documents_upload_dir() . '/', '', $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve filename for wiaas document version
|
||||||
|
* @param string $version
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function wiaas_get_doc_version_filename($version) {
|
||||||
|
return pathinfo( $version, PATHINFO_FILENAME );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve extension for wiaas document version
|
||||||
|
* @param string $version
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function wiaas_get_doc_version_extension($version) {
|
||||||
|
return pathinfo( $version, PATHINFO_EXTENSION );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach wiaas document to post object
|
||||||
|
* @param int $object_id
|
||||||
|
* @param array $document_ids
|
||||||
|
*/
|
||||||
|
function wiaas_attach_documents_to_object($object_id, $document_ids) {
|
||||||
|
update_post_meta($object_id, '_wiaas_attached_documents', $document_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve wiaas documents ids for post object
|
||||||
|
* @param int $object_id
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function wiaas_get_object_attached_documents($object_id) {
|
||||||
|
$document_ids = get_post_meta($object_id, '_wiaas_attached_documents', true);
|
||||||
|
return isset($document_ids) && !empty($document_ids) ? $document_ids : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all documents for single wiaas package
|
||||||
|
*
|
||||||
|
* this includes:
|
||||||
|
* - package linked documents
|
||||||
|
* - addons linked documents
|
||||||
|
* - options linked documents
|
||||||
|
* - all documents attacked to bundled products of package, addons and options
|
||||||
|
*
|
||||||
|
* @param int $package
|
||||||
|
* @param bool $only_visible
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function wiaas_get_all_package_documents($package, $only_visible = false) {
|
||||||
|
// retrieve addons and option packages ids
|
||||||
|
$all_package_ids = array_merge(
|
||||||
|
Wiaas_Package_Addon::get_package_addons_ids($package),
|
||||||
|
Wiaas_Package_Option_Groups::get_package_option_ids($package),
|
||||||
|
array($package->get_id())
|
||||||
|
);
|
||||||
|
|
||||||
|
// retrieve all bundled products from all relevant packages
|
||||||
|
$all_product_ids = array_values(
|
||||||
|
WC_PB_DB::query_bundled_items(array(
|
||||||
|
'return' => 'id=>product_id',
|
||||||
|
'bundle_id' => $all_package_ids
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
$all_object_ids = array_unique(array_merge($all_package_ids, $all_product_ids));
|
||||||
|
|
||||||
|
// retrieve document ids from all packages and products
|
||||||
|
$document_ids = array();
|
||||||
|
foreach ($all_object_ids as $object_id) {
|
||||||
|
$document_ids = array_merge(
|
||||||
|
$document_ids,
|
||||||
|
wiaas_get_object_attached_documents($object_id));
|
||||||
|
}
|
||||||
|
$document_ids = array_unique($document_ids);
|
||||||
|
|
||||||
|
// filter only visible if needed and retrieve documents info
|
||||||
|
$documents = array();
|
||||||
|
foreach ($document_ids as $document_id) {
|
||||||
|
if ($only_visible && Wiaas_Document::is_doc_visible($document_id) || !$only_visible) {
|
||||||
|
$documents[] = Wiaas_Document::get_doc_info($document_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $documents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all documents for single order package item
|
||||||
|
*
|
||||||
|
* @param WC_Order $order
|
||||||
|
* @param int $package_item_id
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function wiaas_get_package_order_item_documents($order, $package_item_id) {
|
||||||
|
|
||||||
|
$order_items = $order->get_items( 'line_item' );
|
||||||
|
$package_order_item = $order->get_item($package_item_id);
|
||||||
|
|
||||||
|
// retrieve package order item addons and options
|
||||||
|
$all_package_order_items = array_merge(
|
||||||
|
wiaas_get_order_item_addons($order_items, $package_order_item),
|
||||||
|
wiaas_get_order_item_options($order_items, $package_order_item),
|
||||||
|
array( $package_order_item )
|
||||||
|
);
|
||||||
|
$all_order_items = $all_package_order_items;
|
||||||
|
|
||||||
|
// retrieve bundled product items for each package
|
||||||
|
foreach ($all_package_order_items as $item) {
|
||||||
|
$all_order_items = array_merge(
|
||||||
|
$all_order_items,
|
||||||
|
wc_pb_get_bundled_order_items($item, $order)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$order_documents = array();
|
||||||
|
foreach ($all_order_items as $order_item) {
|
||||||
|
$order_documents = array_merge(
|
||||||
|
$order_documents,
|
||||||
|
isset($order_item['wiaas_documents']) ? $order_item['wiaas_documents'] : array()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_map(function($doc) {
|
||||||
|
// append document extension and name information
|
||||||
|
$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;
|
||||||
|
}, $order_documents);
|
||||||
|
}
|
||||||
@@ -62,6 +62,8 @@ class Wiaas_Order_Project {
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$available_terms = array();
|
||||||
|
|
||||||
foreach ($all_terms as $term) {
|
foreach ($all_terms as $term) {
|
||||||
if (self::is_order_project_available($term->term_id)) {
|
if (self::is_order_project_available($term->term_id)) {
|
||||||
$available_terms[] = array(
|
$available_terms[] = array(
|
||||||
|
|||||||
@@ -49,6 +49,16 @@ class Wiaas_Package_Addon {
|
|||||||
return $addons;
|
return $addons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve ids of package addons
|
||||||
|
* @param int $package
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_package_addons_ids($package) {
|
||||||
|
return $package->get_meta( '__wiaas_package_addons' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets addons for provided wiaas standard package type
|
* Sets addons for provided wiaas standard package type
|
||||||
* @param $package
|
* @param $package
|
||||||
|
|||||||
@@ -81,6 +81,24 @@ class Wiaas_Package_Option_Groups {
|
|||||||
return $option_groups;
|
return $option_groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve ids of all package options
|
||||||
|
* @param int $package
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_package_option_ids($package) {
|
||||||
|
$groups_data = $package->get_meta( '_wiaas_package_option_groups' );
|
||||||
|
|
||||||
|
$options_ids = array();
|
||||||
|
|
||||||
|
foreach ($groups_data as $group_data) {
|
||||||
|
$options_ids = array_merge($options_ids, $group_data['options']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_unique($options_ids);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set groups of optional packages for provided package
|
* Set groups of optional packages for provided package
|
||||||
* @param $package
|
* @param $package
|
||||||
|
|||||||
@@ -225,15 +225,15 @@ export const previousStep = (params) => ({type: GO_TO_PREVIOUS_STEP, params});
|
|||||||
|
|
||||||
export const uploadDocumnet = () => ({type: UPLOAD_DOCUMENT});
|
export const uploadDocumnet = () => ({type: UPLOAD_DOCUMENT});
|
||||||
|
|
||||||
export const uploadOrderDocument = (idPackage, idDocumentType, file, packages) => {
|
export const uploadOrderDocument = (packageCartKey, idDocumentType, file, packages) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(uploadDocumnet());
|
dispatch(uploadDocumnet());
|
||||||
|
|
||||||
return client.uploadFile(file, {
|
return client.uploadFile(file, {
|
||||||
url: `${API_SERVER}/cart/api/uploadOrderDocument`,
|
url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||||
data: {
|
data: {
|
||||||
idDocumentType,
|
'doc_type': idDocumentType,
|
||||||
idPackage
|
'package_key': packageCartKey
|
||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||||
@@ -266,30 +266,21 @@ export const fetchCartDocuments = (packages, isForSteps = false) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestCartDocuments());
|
dispatch(requestCartDocuments());
|
||||||
|
|
||||||
dispatch(receiveCartDocuments({
|
return client.fetch({
|
||||||
areFilesUploaded: true,
|
url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||||
templates: [],
|
method: 'get',
|
||||||
uploaded: []
|
data: {packages}
|
||||||
}));
|
}).then(response => {
|
||||||
if(isForSteps) {
|
if (response.data) {
|
||||||
dispatch(loadSteps(true));
|
dispatch(receiveCartDocuments(response.data));
|
||||||
}
|
if(isForSteps) {
|
||||||
|
const whitoutUploadDoc = response.data.templates.length === 0;
|
||||||
// return client.fetch({
|
dispatch(loadSteps(whitoutUploadDoc));
|
||||||
// url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
}
|
||||||
// method: 'get',
|
}
|
||||||
// data: {packages}
|
}).catch(error => {
|
||||||
// }).then(response => {
|
client.onError(error, dispatch);
|
||||||
// if (response.data) {
|
});
|
||||||
// dispatch(receiveCartDocuments(response.data));
|
|
||||||
// if(isForSteps) {
|
|
||||||
// const whitoutUploadDoc = response.data.templates.length === 0;
|
|
||||||
// dispatch(loadSteps(whitoutUploadDoc));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }).catch(error => {
|
|
||||||
// client.onError(error, dispatch);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,9 +147,9 @@ export const cartTexts = {
|
|||||||
DOC_NOT_REQUIRED: 'Document not required',
|
DOC_NOT_REQUIRED: 'Document not required',
|
||||||
FILE_UPLOADED_TEXT: 'File uploaded! Select or drop to replace ',
|
FILE_UPLOADED_TEXT: 'File uploaded! Select or drop to replace ',
|
||||||
FILE: 'file',
|
FILE: 'file',
|
||||||
NO_FILE_UPLOAD_TEXT_1: 'Click here to select',
|
NO_FILE_UPLOAD_TEXT_1: 'Drag and drop',
|
||||||
NO_FILE_UPLOAD_TEXT_2: 'or drag and drop file here',
|
NO_FILE_UPLOAD_TEXT_2: 'click to upload',
|
||||||
TEMPLATES: 'Templates',
|
TEMPLATE: 'Template',
|
||||||
UPLOADED: 'Uploaded dcuments',
|
UPLOADED: 'Uploaded dcuments',
|
||||||
PACKAGE_UNAVAILABLE: 'This package is no longer available. Remove it from the cart to place the order successfully',
|
PACKAGE_UNAVAILABLE: 'This package is no longer available. Remove it from the cart to place the order successfully',
|
||||||
BID_AVAILABLE: 'Bids available!',
|
BID_AVAILABLE: 'Bids available!',
|
||||||
@@ -167,7 +167,7 @@ export const cartTexts = {
|
|||||||
buttons: {
|
buttons: {
|
||||||
YES: 'Yes',
|
YES: 'Yes',
|
||||||
CANCEL: 'Cancel',
|
CANCEL: 'Cancel',
|
||||||
PREVIOUS: 'Previous',
|
BACK: 'Back',
|
||||||
NEXT: 'Next',
|
NEXT: 'Next',
|
||||||
ADD_ADDRESS: 'Add address',
|
ADD_ADDRESS: 'Add address',
|
||||||
USE: 'Use',
|
USE: 'Use',
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class CartStepsContainer extends Component {
|
|||||||
{(cartSteps && cartSteps[currentStep] && cartSteps[currentStep].previous && !isLoading) &&
|
{(cartSteps && cartSteps[currentStep] && cartSteps[currentStep].previous && !isLoading) &&
|
||||||
<span onClick={()=>{this.handleStepChange('previous')}} className="prev-btn">
|
<span onClick={()=>{this.handleStepChange('previous')}} className="prev-btn">
|
||||||
<Col sm="12" xs="12">
|
<Col sm="12" xs="12">
|
||||||
{cartTexts.buttons.PREVIOUS}
|
{cartTexts.buttons.BACK}
|
||||||
</Col>
|
</Col>
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import {updateMessages} from '../../actions/notification/notificationActions';
|
|||||||
import {nextStep, setNextActionFct} from '../../actions/cart/cartActions';
|
import {nextStep, setNextActionFct} from '../../actions/cart/cartActions';
|
||||||
|
|
||||||
const DOCUMENT_TYPES = {
|
const DOCUMENT_TYPES = {
|
||||||
TEMPLATE_QUESTINNAIRE: 1,
|
TEMPLATE_QUESTINNAIRE: 'template_questionaire',
|
||||||
QUESTIONNAIRE: 2,
|
QUESTIONNAIRE: 'order_questionaire',
|
||||||
TEMPLATE_AGREEMENT: 6,
|
TEMPLATE_AGREEMENT: 'template_agreement',
|
||||||
AGREEMENT: 7
|
AGREEMENT: 'order_agreement'
|
||||||
};
|
};
|
||||||
|
|
||||||
class CartCustomerQuestionnaireContainer extends Component {
|
class CartCustomerQuestionnaireContainer extends Component {
|
||||||
@@ -34,7 +34,7 @@ class CartCustomerQuestionnaireContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleStepChange() {
|
handleStepChange() {
|
||||||
if(this.props.cartDocuments && this.props.cartDocuments.areFilesUploaded) {
|
if(this.props.cartDocuments && !this.props.cartDocuments.pending) {
|
||||||
this.props.dispatch(nextStep());
|
this.props.dispatch(nextStep());
|
||||||
} else {
|
} else {
|
||||||
this.props.dispatch(updateMessages([{code:'warning', message: 'DOCS_MISSING'}], cartMessages));
|
this.props.dispatch(updateMessages([{code:'warning', message: 'DOCS_MISSING'}], cartMessages));
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import Dropzone from 'react-dropzone';
|
|||||||
import {API_SERVER} from '../../../config';
|
import {API_SERVER} from '../../../config';
|
||||||
import FileDownloader from '../../../helpers/FileDownloader';
|
import FileDownloader from '../../../helpers/FileDownloader';
|
||||||
import {cartTexts} from '../../../constants/cartConstants';
|
import {cartTexts} from '../../../constants/cartConstants';
|
||||||
|
import {getDocumentIcon} from '../../../helpers/DocumentHelper';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
const fileHandler = new FileDownloader();
|
const fileHandler = new FileDownloader();
|
||||||
const documentTypes = {
|
const documentTypes = {
|
||||||
2 : 'Customer Questionnaire',
|
'order_questionaire' : 'Customer Questionnaire',
|
||||||
7 : 'Customer Agreement'
|
'order_agreement' : 'Customer Agreement'
|
||||||
};
|
};
|
||||||
|
|
||||||
class CartUploadDocument extends Component {
|
class CartUploadDocument extends Component {
|
||||||
@@ -20,11 +22,11 @@ class CartUploadDocument extends Component {
|
|||||||
this.uploadFile = this.uploadFile.bind(this);
|
this.uploadFile = this.uploadFile.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadFile(idPackage, idDocumentType,acceptedFiles, rejectedFiles, packages){
|
uploadFile(packageCartKey, idDocumentType,acceptedFiles, rejectedFiles, packages){
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
acceptedFiles.forEach(file => {
|
acceptedFiles.forEach(file => {
|
||||||
self.props.dispatch(uploadOrderDocument(idPackage, idDocumentType, file, packages));
|
self.props.dispatch(uploadOrderDocument(packageCartKey, idDocumentType, file, packages));
|
||||||
});
|
});
|
||||||
|
|
||||||
if(rejectedFiles && rejectedFiles.length) {
|
if(rejectedFiles && rejectedFiles.length) {
|
||||||
@@ -33,9 +35,15 @@ class CartUploadDocument extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
downloadDocument(document){
|
downloadDocument(document){
|
||||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}`
|
fileHandler.download(
|
||||||
const fileName = document.documentName + '.' + document.extension;
|
`${API_SERVER}/wp-json/wiaas/cart/items/${this.props.cartItem.key}/documents/${this.props.idDocumentType}?document_key=${document.key}`,
|
||||||
fileHandler.download(fileUrl, fileName);
|
document.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadTemplate(document) {
|
||||||
|
fileHandler.download(
|
||||||
|
`${API_SERVER}/wp-json/wiaas/documents?document_id=${document.id}`,
|
||||||
|
document.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -45,30 +53,51 @@ class CartUploadDocument extends Component {
|
|||||||
{
|
{
|
||||||
templateDocument &&
|
templateDocument &&
|
||||||
<div>
|
<div>
|
||||||
<Dropzone className="upload-file-drop-zone"
|
<div className="cart-template">
|
||||||
|
<p className="cart-subtitle">{documentTypes[idDocumentType]} {cartTexts.labels.TEMPLATE}:</p>
|
||||||
|
<p className="document-link" onClick={() => {this.downloadTemplate(templateDocument)}}>
|
||||||
|
<i className={`fa fa-${getDocumentIcon(templateDocument.extension)}`} aria-hidden="true"></i> {templateDocument.name}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Dropzone className={classnames('upload-file-drop-zone', { 'pending-upload': !uploadedDocument })}
|
||||||
accept=".pdf,.docx,.doc,.xlsx,.xls,.odt,.ods"
|
accept=".pdf,.docx,.doc,.xlsx,.xls,.odt,.ods"
|
||||||
onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(cartItem.idPackage, idDocumentType, acceptedFiles, rejectedFiles, packages)}}>
|
onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(cartItem.key, idDocumentType, acceptedFiles, rejectedFiles, packages)}}>
|
||||||
{
|
{
|
||||||
uploadedDocument
|
uploadedDocument
|
||||||
? <h6 className="drop-zone-text uploaded">{cartTexts.labels.FILE_UPLOADED_TEXT} {documentTypes[idDocumentType]} {cartTexts.labels.FILE}</h6>
|
? (
|
||||||
: <h6 className="drop-zone-text">{cartTexts.labels.NO_FILE_UPLOAD_TEXT_1} {documentTypes[idDocumentType]} {cartTexts.labels.NO_FILE_UPLOAD_TEXT_2}</h6>
|
<div>
|
||||||
|
<h1 className="drop-zone-icon">
|
||||||
|
<i className="fa fa-upload"></i>
|
||||||
|
</h1>
|
||||||
|
<h6 className="drop-zone-text">{uploadedDocument.name}</h6>
|
||||||
|
<span className="drop-zone-text">
|
||||||
|
Drag and drop or click to replace file
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
: (
|
||||||
|
<div>
|
||||||
|
<h1 className="drop-zone-icon pending-upload">
|
||||||
|
<i className="fa fa-upload"></i>
|
||||||
|
</h1>
|
||||||
|
<span className="drop-zone-text">
|
||||||
|
Drag and drop or click to upload file
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
</Dropzone>
|
</Dropzone>
|
||||||
{
|
{
|
||||||
uploadedDocument &&
|
uploadedDocument &&
|
||||||
<div>
|
<div>
|
||||||
<div className="cart-subtitle">{cartTexts.labels.UPLOADED}:</div>
|
<span className="document-link" onClick={() => {this.downloadDocument(uploadedDocument)}}>
|
||||||
<div className="document-link" onClick={() => {this.downloadDocument(uploadedDocument)}}>
|
<strong>
|
||||||
<i className="fa fa-file" aria-hidden="true"></i>
|
<i className={`fa fa-${getDocumentIcon(uploadedDocument.extension)}`} aria-hidden="true"></i> {uploadedDocument.name}
|
||||||
{' ' + uploadedDocument.documentName + ' (' + uploadedDocument.extension + ')'}
|
</strong>
|
||||||
</div>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<div className="cart-subtitle">{cartTexts.labels.TEMPLATES}:</div>
|
|
||||||
<div className="document-link" onClick={() => {this.downloadDocument(templateDocument)}}>
|
|
||||||
<i className="fa fa-file" aria-hidden="true"></i>
|
|
||||||
{' ' + templateDocument.documentName + ' (' + templateDocument.extension + ')'}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,19 +6,37 @@
|
|||||||
|
|
||||||
.upload-file-drop-zone {
|
.upload-file-drop-zone {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: 3px dashed $borderColor;
|
border: 1px dashed $borderColor;
|
||||||
margin-top: 1rem;
|
margin: 1rem 0;
|
||||||
height: 5rem;
|
padding: 1rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
&:hover {
|
||||||
|
background-color: $lightHoverColor;
|
||||||
|
}
|
||||||
|
color: $font-light-color;
|
||||||
|
&.pending-upload {
|
||||||
|
border: 1px dashed $accentColor;
|
||||||
|
|
||||||
|
.drop-zone-icon, .drop-zone-text {
|
||||||
|
color: $accentColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.drop-zone-text {
|
.drop-zone-text {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 1.3rem 0.5rem;
|
color: $font-light-color;
|
||||||
|
padding: 0;
|
||||||
|
font-size: $font-size-small;
|
||||||
}
|
}
|
||||||
|
|
||||||
.uploaded {
|
.drop-zone-icon {
|
||||||
color: #155724;
|
color: #b3b3b3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.next-btn {
|
.next-btn {
|
||||||
@@ -28,18 +46,33 @@
|
|||||||
color: $darkGreyColor;
|
color: $darkGreyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cart-template {
|
||||||
|
margin: 1rem 0;
|
||||||
|
.cart-subtitle {
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.cart-subtitle {
|
.cart-subtitle {
|
||||||
font-weight: $font-weight;
|
font-weight: $font-weight;
|
||||||
|
color: $font-light-color;
|
||||||
|
font-size: $font-size-small;
|
||||||
padding-top: 0.3rem;
|
padding-top: 0.3rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.upload-layer{
|
.upload-layer{
|
||||||
background: $whiteColor;
|
background: $whiteColor;
|
||||||
padding-bottom: 1rem;
|
padding: 1rem;
|
||||||
|
color: $title-color;
|
||||||
|
|
||||||
|
.upload-layer {
|
||||||
|
color: $title-color;
|
||||||
|
}
|
||||||
|
|
||||||
.document-link{
|
.document-link{
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
color: #2b6279;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ const fileHandler = new FileDownloader();
|
|||||||
|
|
||||||
class PackageInfo extends Component {
|
class PackageInfo extends Component {
|
||||||
downloadDocument(document){
|
downloadDocument(document){
|
||||||
const fileUrl = `${API_SERVER}/wp-json/wiaas/download-package-file?document_id=${document.idDocument}&package_id=${document.idPackage}`
|
fileHandler.download(
|
||||||
const fileName = document.documentName + '.' + document.extension;
|
`${API_SERVER}/wp-json/wiaas/documents?document_id=${document.id}`,
|
||||||
fileHandler.download(fileUrl, fileName);
|
document.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -41,9 +41,9 @@ class PackageInfo extends Component {
|
|||||||
<div className="shop-package-label">{coMarketTexts.labels.DOCUMENTS}:</div>
|
<div className="shop-package-label">{coMarketTexts.labels.DOCUMENTS}:</div>
|
||||||
{
|
{
|
||||||
documents.map((document) =>
|
documents.map((document) =>
|
||||||
<span key={document.idDocument} className="document-link"
|
<span key={document.id} className="document-link"
|
||||||
onClick={() => {this.downloadDocument(document)}}>
|
onClick={() => {this.downloadDocument(document)}}>
|
||||||
<i className="fa fa-file" aria-hidden="true"></i> {document.documentName} ({document.extension})
|
<i className={`fa fa-${document.icon}`} aria-hidden="true"></i> {document.name}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,12 @@ class OrderDocuments extends Component {
|
|||||||
return (
|
return (
|
||||||
<div id="order-documents" className="order-documents">
|
<div id="order-documents" className="order-documents">
|
||||||
{
|
{
|
||||||
orderInfo.packages.map(orderPackage => <OrderDocumentsGroup key={'order-package-' + orderPackage.id} documentsGroup={orderPackage} />)
|
orderInfo.packages.map(orderPackage => (
|
||||||
|
<OrderDocumentsGroup
|
||||||
|
key={'order-package-' + orderPackage.id}
|
||||||
|
orderId={orderInfo.id}
|
||||||
|
documentsGroup={orderPackage}
|
||||||
|
/>))
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
orderInfo.orderDocuments && <OrderDocumentsGroup key={'order-package-0'} documentsGroup={{documents: orderInfo.documents, packageName: orderTexts.labels.OTHER_DOCS}} />
|
orderInfo.orderDocuments && <OrderDocumentsGroup key={'order-package-0'} documentsGroup={{documents: orderInfo.documents, packageName: orderTexts.labels.OTHER_DOCS}} />
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {Tooltip} from 'reactstrap';
|
|
||||||
import WiaasBox from '../../../mainComponents/box/WiaasBox.jsx';
|
import WiaasBox from '../../../mainComponents/box/WiaasBox.jsx';
|
||||||
import {API_SERVER} from '../../../config';
|
import {API_SERVER} from '../../../config';
|
||||||
import FileDownloader from '../../../helpers/FileDownloader';
|
import FileDownloader from '../../../helpers/FileDownloader';
|
||||||
@@ -18,62 +17,39 @@ const iconTypes = {
|
|||||||
xlsx: 'file-excel-o',
|
xlsx: 'file-excel-o',
|
||||||
ppt: 'file-powerpoint-o',
|
ppt: 'file-powerpoint-o',
|
||||||
pptx: 'file-powerpoint-o'
|
pptx: 'file-powerpoint-o'
|
||||||
}
|
};
|
||||||
|
|
||||||
class OrderDocumentsGroup extends Component {
|
class OrderDocumentsGroup extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.toggle = this.toggle.bind(this);
|
|
||||||
this.state = {};
|
this.state = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle(idDocument) {
|
|
||||||
const obj = {}
|
|
||||||
obj[idDocument] = !this.state[idDocument];
|
|
||||||
|
|
||||||
this.setState(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
getDocumentIcon(documentType) {
|
getDocumentIcon(documentType) {
|
||||||
return iconTypes[documentType] || 'file';
|
return iconTypes[documentType] || 'file';
|
||||||
}
|
}
|
||||||
|
|
||||||
getDocumentText(document) {
|
downloadDocument(orderId, itemId, document){
|
||||||
const name = document.documentName + '.' + document.extension;
|
const fileUrl = `${API_SERVER}/wp-json/wiaas/documents/order/${orderId}/${document.type}?item_id=${itemId}&document_key=${document.key}`;
|
||||||
|
fileHandler.download(fileUrl, document.name);
|
||||||
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;
|
|
||||||
fileHandler.download(fileUrl, fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {documentsGroup} = this.props;
|
const {documentsGroup, orderId} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
documentsGroup.documents &&
|
documentsGroup.documents &&
|
||||||
documentsGroup.documents.length > 0 &&
|
documentsGroup.documents.length > 0 &&
|
||||||
<WiaasBox mainTitle={documentsGroup.packageName}>
|
<WiaasBox mainTitle={documentsGroup.name}>
|
||||||
{
|
{
|
||||||
documentsGroup.documents.map(document => <a id={'document-' + document.idDocument} key={'order-document-' + document.idDocument}>
|
documentsGroup.documents.map(document => <a id={'document-' + document.key} key={'order-document-' + document.key}>
|
||||||
<div onClick={() => {this.downloadDocument(document)}} className="document-link-big">
|
<div onClick={() => {this.downloadDocument(orderId, documentsGroup.orderItemId, document)}} className="document-link-big">
|
||||||
<i className={'fa fa-4x fa-' + this.getDocumentIcon(document.extension)} aria-hidden="true"></i>
|
<i className={'fa fa-4x fa-' + this.getDocumentIcon(document.extension)} aria-hidden="true"></i>
|
||||||
<div>
|
<div>
|
||||||
{this.getDocumentText(document)}
|
{document.name}
|
||||||
<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})
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
</div>
|
||||||
</div></a>)
|
</div></a>)
|
||||||
}
|
}
|
||||||
|
|||||||
17
frontend/src/helpers/DocumentHelper.js
Normal file
17
frontend/src/helpers/DocumentHelper.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const iconTypes = {
|
||||||
|
doc: 'file-word-o',
|
||||||
|
docx: 'file-word-o',
|
||||||
|
odt: 'file-word-o',
|
||||||
|
ods: 'file-excel-o',
|
||||||
|
pdf: 'file-pdf-o',
|
||||||
|
png: 'file-image-o',
|
||||||
|
jpg: 'file-image-o',
|
||||||
|
xls: 'file-excel-o',
|
||||||
|
xlsx: 'file-excel-o',
|
||||||
|
ppt: 'file-powerpoint-o',
|
||||||
|
pptx: 'file-powerpoint-o'
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDocumentIcon = extension => {
|
||||||
|
return iconTypes[extension] || 'file';
|
||||||
|
};
|
||||||
@@ -7,6 +7,7 @@ class FileDownloader {
|
|||||||
download(fileUrl, fileName){
|
download(fileUrl, fileName){
|
||||||
htmlClient.fetch({
|
htmlClient.fetch({
|
||||||
url: fileUrl,
|
url: fileUrl,
|
||||||
|
method: 'get',
|
||||||
responseType: 'arraybuffer'
|
responseType: 'arraybuffer'
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|||||||
@@ -45,14 +45,14 @@ class HtmlClient {
|
|||||||
uploadFile(file, configParams = null) {
|
uploadFile(file, configParams = null) {
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append('file', file, file.name);
|
formData.append('file', file, file.name);
|
||||||
/*
|
|
||||||
if(configParams) {
|
if(configParams) {
|
||||||
|
|
||||||
Object.keys(configParams.data).forEach((paramKey) => {
|
Object.keys(configParams.data).forEach((paramKey) => {
|
||||||
formData.append(paramKey, configParams.data[paramKey]);
|
formData.append(paramKey, configParams.data[paramKey]);
|
||||||
});
|
});
|
||||||
|
|
||||||
}*/
|
}
|
||||||
configParams.data = formData;
|
configParams.data = formData;
|
||||||
const params = Object.assign({}, uploadParams(), configParams);
|
const params = Object.assign({}, uploadParams(), configParams);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {fromWiaasProcessStep} from './ProcessHelper';
|
import {fromWiaasProcessStep} from './ProcessHelper';
|
||||||
|
import { getDocumentIcon } from './DocumentHelper';
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
return date ? moment(date).format("Do MMM, YYYY") : undefined;
|
return date ? moment(date).format("Do MMM, YYYY") : undefined;
|
||||||
@@ -40,6 +41,7 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
packages: WCOrder['line_items'].map(packageLine => {
|
packages: WCOrder['line_items'].map(packageLine => {
|
||||||
return {
|
return {
|
||||||
id: packageLine['product_id'],
|
id: packageLine['product_id'],
|
||||||
|
orderItemId: packageLine['id'],
|
||||||
name: packageLine.name,
|
name: packageLine.name,
|
||||||
quantity: packageLine.quantity,
|
quantity: packageLine.quantity,
|
||||||
price: packageLine.price,
|
price: packageLine.price,
|
||||||
@@ -62,6 +64,10 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
packageName: packageOption.name,
|
packageName: packageOption.name,
|
||||||
groupName: packageOption['group_name'] || '',
|
groupName: packageOption['group_name'] || '',
|
||||||
})) : [],
|
})) : [],
|
||||||
|
documents: packageLine.documents.map(document => {
|
||||||
|
document['icon'] = getDocumentIcon(document.extension);
|
||||||
|
return document;
|
||||||
|
}) || []
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
process: processInfo,
|
process: processInfo,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getDocumentIcon } from './DocumentHelper';
|
||||||
|
|
||||||
const DEFAULT_PACKAGE_IMG = 'static/img/no-photo-package.jpg';
|
const DEFAULT_PACKAGE_IMG = 'static/img/no-photo-package.jpg';
|
||||||
|
|
||||||
@@ -49,12 +50,10 @@ export const fromWCPackage = wcPackage => {
|
|||||||
country: wcPackage.country,
|
country: wcPackage.country,
|
||||||
countryCode: wcPackage['country_code'],
|
countryCode: wcPackage['country_code'],
|
||||||
currency: wcPackage.currency,
|
currency: wcPackage.currency,
|
||||||
documents: wcPackage.documents ? wcPackage.documents.map(document => ({
|
documents: wcPackage.documents ? wcPackage.documents.map(document => {
|
||||||
idDocument: document.id,
|
document.icon = getDocumentIcon(document.extension);
|
||||||
documentName: document.name,
|
return document;
|
||||||
extension: document.extension,
|
}) : [],
|
||||||
idPackage: wcPackage.id,
|
|
||||||
})) : [],
|
|
||||||
shortDescription: wcPackage.description,
|
shortDescription: wcPackage.description,
|
||||||
prices: extractPrices(wcPackage.id, wcPackage.prices || []),
|
prices: extractPrices(wcPackage.id, wcPackage.prices || []),
|
||||||
groups: extractGroups(wcPackage.groups || {}),
|
groups: extractGroups(wcPackage.groups || {}),
|
||||||
|
|||||||
Reference in New Issue
Block a user