Compare commits
58 Commits
backoffice
...
commercial
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddf7d4452c | ||
|
|
554dc37a2d | ||
|
|
dc1a1c64d2 | ||
|
|
2d7b6c55e6 | ||
|
|
d7103df6dc | ||
|
|
b7ac53d195 | ||
|
|
f14d35b1aa | ||
|
|
e810dd086a | ||
|
|
8789eb1426 | ||
|
|
bd724d12c2 | ||
|
|
803e62ea69 | ||
|
|
a5168d3487 | ||
|
|
d7c34c3b0b | ||
|
|
55dc87e174 | ||
|
|
9f3fe44bb1 | ||
|
|
ba2629ca22 | ||
|
|
14eda981b7 | ||
|
|
8df4ec3dc7 | ||
|
|
17acc9d96a | ||
|
|
4bdad78ed8 | ||
|
|
f3d911e5b1 | ||
|
|
e4a7b28301 | ||
|
|
84ba574bcb | ||
|
|
4f31cc94e8 | ||
|
|
bc74b504db | ||
|
|
8d2b1e52b4 | ||
|
|
63c1ee945f | ||
|
|
1e9f959b16 | ||
|
|
afe4ac1676 | ||
|
|
c7e8a526e0 | ||
|
|
ac9c89e8eb | ||
|
|
ea63870704 | ||
|
|
accc359cbe | ||
|
|
57d61918b9 | ||
|
|
a830a47d31 | ||
|
|
61109e9bf0 | ||
|
|
c6a1f9837d | ||
|
|
089bea5ce4 | ||
|
|
b53fbe5402 | ||
|
|
84cd11f9c9 | ||
|
|
a2656173c2 | ||
|
|
9a8e05e341 | ||
|
|
246788207b | ||
|
|
360b24c6ec | ||
|
|
d11860223f | ||
|
|
c537557daf | ||
|
|
c102b6a5ad | ||
|
|
f41252ea23 | ||
|
|
c5c07cbfae | ||
|
|
7ceac97fed | ||
|
|
ab9ee2cb0d | ||
|
|
b028fb3f04 | ||
|
|
3ad210f883 | ||
|
|
4c760b12c3 | ||
|
|
f1c99c28ae | ||
|
|
6f6fb1115a | ||
|
|
93d03a96ee | ||
|
|
21d96a0e55 |
@@ -2,6 +2,8 @@ FROM php:7.0-apache
|
||||
|
||||
ARG API_URL
|
||||
|
||||
ARG WIAAS_CUSTOMER_INTERFACE
|
||||
|
||||
ARG MYSQL_DATABASE
|
||||
ARG MYSQL_USER
|
||||
ARG MYSQL_PASSWORD
|
||||
@@ -35,6 +37,8 @@ ENV WP_LOGGED_IN_SALT ${WP_LOGGED_IN_SALT}
|
||||
ENV WP_NONCE_SALT ${WP_NONCE_SALT}
|
||||
ENV WP_JWT_AUTH_SECRET_KEY ${WP_JWT_AUTH_SECRET_KEY}
|
||||
|
||||
ENV WIAAS_CUSTOMER_INTERFACE ${WIAAS_CUSTOMER_INTERFACE}
|
||||
|
||||
RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo
|
||||
|
||||
COPY docker/php/composer.phar /usr/local/bin/composer
|
||||
|
||||
17
backend/app/plugins/wiaas/assets/css/menu.css
Normal file
17
backend/app/plugins/wiaas/assets/css/menu.css
Normal file
@@ -0,0 +1,17 @@
|
||||
#wpadminbar #wp-admin-bar-wiaas-view-as .ab-icon {
|
||||
float: none;
|
||||
margin-left: 10px;
|
||||
color: rgba(240,245,250,0.7) !important;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-wiaas-view-as .ab-label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
#wpadminbar #wp-admin-bar-wiaas-view-as a:not(:hover) .ab-icon:before {
|
||||
color: rgba(240,245,250,0.7) !important;
|
||||
}
|
||||
|
||||
#createuser .acf-taxonomy-field, #your-profile .acf-taxonomy-field {
|
||||
width: 25em;
|
||||
}
|
||||
@@ -120,4 +120,17 @@
|
||||
|
||||
#wiaas_package_option_groups_list .wiaas_option_group h3 {
|
||||
background-color:#F9F9F9;
|
||||
}
|
||||
|
||||
#createuser label[for="role"], #createuser label[for="url"], #createuser #role, #createuser #url{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#your-profile label[for="role"], #your-profile label[for="url"],#your-profile #role, #your-profile #url{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#adminmenu #toplevel_page_wiaas-cl-packages div.wp-menu-image::before {
|
||||
font-family: WooCommerce!important;
|
||||
content: '\e006';
|
||||
}
|
||||
7
backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css
Normal file
7
backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css
Normal file
@@ -0,0 +1,7 @@
|
||||
#posts-filter .tablenav .actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#menu-posts-product .wp-submenu li:last-child {
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
|
||||
$('#tabs').each(function() {
|
||||
var disabled = $( this ).data('disabled') || '';
|
||||
|
||||
$( this ).tabs({
|
||||
disabled: [ disabled ]
|
||||
});
|
||||
});
|
||||
|
||||
$('#wiaas_add_cl_customer_extras').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var customer_id = $('#wiaas_cl_customers').val();
|
||||
|
||||
if (!customer_id || customer_id === '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(window.ajaxurl, {
|
||||
action: 'wiaas_create_cl_customer_extras',
|
||||
_ajax_nonce: $('#wiaas_create_cl_customer_extras_nonce').val(),
|
||||
customer_id: customer_id,
|
||||
package_id: $('#wiaas_cl_package_id').val()
|
||||
}).done( function (result) {
|
||||
$('#tabs-2').append(result);
|
||||
|
||||
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', true );
|
||||
});
|
||||
|
||||
$('#wiaas_cl_customers').val('0');
|
||||
});
|
||||
|
||||
$('#wiaas_package_extras').delegate('.wiaas_remove_cl_extras', 'click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var customer_id = $( this ).data('customer_id');
|
||||
|
||||
$('#extras_customer_' + customer_id).remove();
|
||||
|
||||
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', false );
|
||||
|
||||
$('#wiaas_cl_customers').val('0');
|
||||
});
|
||||
|
||||
$('#wiaas_package_extras').delegate('.wiaas-cl-extra-input', 'change', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var val = parseFloat($( this ).val());
|
||||
var target = '#' + $( this).data('target');
|
||||
|
||||
if (isNaN(val)) {
|
||||
|
||||
$(target).val('Invalid!');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var type = $( this).data('type');
|
||||
|
||||
if (type === 'fixed') {
|
||||
$(target).text( $(target).data('base') + val);
|
||||
}
|
||||
|
||||
if (type === 'recurrent' || type === 'services') {
|
||||
$(target).data(type, val);
|
||||
|
||||
$(target).text( $(target).data('base') + $(target).data('recurrent') + $(target).data('services'));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,76 +1,23 @@
|
||||
jQuery(function ($) {
|
||||
|
||||
var $edit_in_cart = $('.bundle_edit_in_cart'),
|
||||
$group_mode_select = $('select#_wc_pb_group_mode'),
|
||||
$bundled_products_panel = $('#bundled_product_data'),
|
||||
$bundled_products_toolbar = $bundled_products_panel.find('.toolbar'),
|
||||
$template_products_container_hardware = $('.wiaas-template-items_hardware'),
|
||||
$template_products_container_software = $('.wiaas-template-items_software'),
|
||||
$template_products_container_services = $('.wiaas-template-items_services'),
|
||||
$template_products_container_isntallation = $('.wiaas-template-items_installation'),
|
||||
var $template_categories_container_hardware = $('.wiaas-template-items_hardware'),
|
||||
$template_categories_container_software = $('.wiaas-template-items_software'),
|
||||
$template_categories_container_services = $('.wiaas-template-items_services'),
|
||||
$template_categories_container_isntallation = $('.wiaas-template-items_installation'),
|
||||
|
||||
$template_products = $('.wc-bundled-item',
|
||||
$template_products_container_services,
|
||||
$template_products_container_software,
|
||||
$template_products_container_hardware,
|
||||
$template_products_container_isntallation),
|
||||
$template_categories = $('.wc-bundled-item',
|
||||
$template_categories_container_services,
|
||||
$template_categories_container_software,
|
||||
$template_categories_container_hardware,
|
||||
$template_categories_container_isntallation),
|
||||
|
||||
$template_search_hardware = $('#wiaastemplate_products_hardware'),
|
||||
$template_search_software = $('#wiaastemplate_products_software'),
|
||||
$template_search_services = $('#wiaastemplate_products_services'),
|
||||
$template_search_installation = $('#wiaastemplate_products_installation'),
|
||||
bundled_product_objects = {},
|
||||
bundled_products_add_count = $template_products.length,
|
||||
block_params = {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
};
|
||||
template_category_objects = {},
|
||||
template_category_add_count = $template_categories.length;
|
||||
|
||||
$.fn.wc_bundles_select2 = function () {
|
||||
$(document.body).trigger('wc-enhanced-select-init');
|
||||
};
|
||||
|
||||
// Bundle type move stock msg up.
|
||||
$('.bundle_stock_msg').appendTo('._manage_stock_field .description');
|
||||
|
||||
// Simple type options are valid for bundles.
|
||||
$('.show_if_simple:not(.hide_if_bundle)').addClass('show_if_bundle');
|
||||
|
||||
$('body').on('woocommerce-product-type-change', function (event, select_val) {
|
||||
|
||||
if ('bundle' === select_val) {
|
||||
|
||||
$('.show_if_external').hide();
|
||||
$('.show_if_bundle').show();
|
||||
|
||||
$('input#_manage_stock').change();
|
||||
|
||||
$('#_nyp').change();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$group_mode_select.change(function () {
|
||||
if ($.inArray($group_mode_select.val(), wc_bundles_admin_params.group_modes_with_parent) === -1) {
|
||||
$edit_in_cart.hide();
|
||||
} else {
|
||||
$edit_in_cart.show();
|
||||
}
|
||||
});
|
||||
|
||||
// Downloadable support.
|
||||
$('input#_downloadable').change(function () {
|
||||
$('select#product-type').change();
|
||||
});
|
||||
|
||||
// Trigger product type change.
|
||||
$('select#product-type').change();
|
||||
|
||||
// Trigger group mode change.
|
||||
$group_mode_select.change();
|
||||
|
||||
|
||||
init_event_handlers();
|
||||
@@ -81,52 +28,50 @@ jQuery(function ($) {
|
||||
$template_search_hardware
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('hardware', $template_search_hardware, $template_products_container_hardware)
|
||||
addSearchedTemplateCategory('hardware', $template_search_hardware, $template_categories_container_hardware)
|
||||
});
|
||||
|
||||
$template_search_software
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('software', $template_search_software, $template_products_container_software)
|
||||
addSearchedTemplateCategory('software', $template_search_software, $template_categories_container_software)
|
||||
});
|
||||
|
||||
|
||||
$template_search_installation
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('services', $template_search_installation, $template_products_container_isntallation)
|
||||
addSearchedTemplateCategory('installation', $template_search_installation, $template_categories_container_isntallation)
|
||||
});
|
||||
|
||||
|
||||
$template_search_services
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('installation', $template_search_services, $template_products_container_services)
|
||||
addSearchedTemplateCategory('services', $template_search_services, $template_categories_container_services)
|
||||
});
|
||||
|
||||
|
||||
function addSearchedProduct(options, search, container) {
|
||||
var bundled_product_ids = search.val(),
|
||||
bundled_product_id = bundled_product_ids && bundled_product_ids.length > 0 ? bundled_product_ids.shift() : false;
|
||||
function addSearchedTemplateCategory(options, search, container) {
|
||||
var template_category_ids = search.val(),
|
||||
template_category_id = template_category_ids && template_category_ids.length > 0 ? template_category_ids.shift() : false;
|
||||
|
||||
var template_category_title =search.text();
|
||||
|
||||
if (!bundled_product_id) {
|
||||
if (!template_category_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
search.val([]).change();
|
||||
|
||||
$bundled_products_panel.block(block_params);
|
||||
|
||||
bundled_products_add_count++;
|
||||
template_category_add_count++;
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_add_template_product',
|
||||
post_id: woocommerce_admin_meta_boxes.post_id,
|
||||
id: bundled_products_add_count,
|
||||
id: template_category_add_count,
|
||||
title: template_category_title,
|
||||
product_id: bundled_product_id,
|
||||
template_category_id: template_category_id,
|
||||
security: wc_bundles_admin_params.add_bundled_product_nonce,
|
||||
options: options,
|
||||
};
|
||||
@@ -140,13 +85,11 @@ jQuery(function ($) {
|
||||
container.append(response.markup);
|
||||
|
||||
var $added = $('.wiaas-template-item', container).last(),
|
||||
added_id = 'bundled_item_' + bundled_products_add_count;
|
||||
added_id = 'bundled_item_' + template_category_add_count;
|
||||
|
||||
$added.data('bundled_item_id', added_id);
|
||||
$added.wc_bundles_select2();
|
||||
|
||||
$bundled_products_panel.trigger('wc-bundles-added-bundled-product');
|
||||
|
||||
} else if (response.message !== '') {
|
||||
window.alert(response.message);
|
||||
}
|
||||
@@ -161,8 +104,6 @@ jQuery(function ($) {
|
||||
}
|
||||
search.text('');
|
||||
|
||||
$bundled_products_panel.unblock();
|
||||
|
||||
});
|
||||
|
||||
}, 250);
|
||||
@@ -170,7 +111,7 @@ jQuery(function ($) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$template_products_container_isntallation
|
||||
$template_categories_container_isntallation
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -181,15 +122,13 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_products_container_hardware
|
||||
$template_categories_container_hardware
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -200,15 +139,13 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_products_container_software
|
||||
$template_categories_container_software
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -219,15 +156,13 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_products_container_services
|
||||
$template_categories_container_services
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -238,9 +173,7 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_CM_Packages
|
||||
*
|
||||
*/
|
||||
class Wiaas_Admin_CL_Packages {
|
||||
|
||||
/**
|
||||
* Handles output of Commercial Lead packages page in admin panel.
|
||||
*
|
||||
* Shows list of packages available for sale and packages sold by current commercial lead.
|
||||
* Enables adding package to commercial lead catalogue and setting package specific prices
|
||||
* for current commercial lead.
|
||||
*
|
||||
*/
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
|
||||
|
||||
add_action( 'admin_head', array( __CLASS__, 'menu_highlight' ) );
|
||||
|
||||
add_filter( 'manage_product_posts_columns', array( __CLASS__, 'define_list_table_products_columns' ), 999 );
|
||||
|
||||
add_filter( 'bulk_actions-edit-product', array( __CLASS__, 'define_list_table_products_bulk_actions' ), 999 );
|
||||
|
||||
add_filter( 'views_edit-product', array( __CLASS__, 'define_list_table_products_views' ), 999 );
|
||||
|
||||
add_filter( 'post_row_actions', array( __CLASS__, 'define_list_table_products_row_actions' ), 999, 2 );
|
||||
|
||||
add_filter( 'list_table_primary_column', array( __CLASS__, 'define_list_table_products_primary_column' ), 999, 2 );
|
||||
|
||||
add_action( 'manage_product_posts_custom_column', array( __CLASS__, 'render_list_table_products_columns' ), 10, 2 );
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
|
||||
}
|
||||
|
||||
public static function add_cl_packages_menu() {
|
||||
add_submenu_page(
|
||||
'edit.php?post_type=product',
|
||||
__( 'Products', 'wiaas' ),
|
||||
null,
|
||||
'manage_wiaas_cl_products',
|
||||
'wiaas-cl-package',
|
||||
array(__CLASS__, 'output_package')
|
||||
);
|
||||
}
|
||||
|
||||
public static function menu_highlight() {
|
||||
global $parent_file;
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ($screen->id === 'admin_page_wiaas-cl-product') {
|
||||
|
||||
error_log('set parent');
|
||||
|
||||
$parent_file = 'edit.php?post_type=product';
|
||||
}
|
||||
}
|
||||
|
||||
public static function output_package() {
|
||||
wp_enqueue_script( 'jquery-ui-tabs' );
|
||||
|
||||
$package_id = absint( $_GET['cl_package_id'] );
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
if (!$package) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($_POST['wiaas_save_cl_extras_nonce']) && ! empty($_POST['cl_extras'])) {
|
||||
if (wp_verify_nonce($_POST['wiaas_save_cl_extras_nonce'], 'wiaas_save_cl_extras')) {
|
||||
self::_handle_cl_extras_update($package_id);
|
||||
}
|
||||
}
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
|
||||
$bundled_items_per_category = array();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$category = Wiaas_Product_Category::get_category($bundled_item->product);
|
||||
if (isset($category)) {
|
||||
if ($category ==='hardware' || $category === 'software') {
|
||||
$category = 'products';
|
||||
}
|
||||
$bundled_items_per_category[$category] ?: array();
|
||||
$bundled_items_per_category[$category][] = $bundled_item;
|
||||
}
|
||||
}
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$cl_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$cl_extras = Wiaas_Package_CL_Pricing::get_extras($cl_id, $package_id);
|
||||
|
||||
$has_default_cl_extras = ! empty($cl_extras);
|
||||
|
||||
// default values for catalogue package
|
||||
if (! $has_default_cl_extras) {
|
||||
$cl_extras = array();
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
$cl_extras[$type.'_default'] = array(
|
||||
'visible' => true,
|
||||
'fixed' => 0,
|
||||
'services' => 0,
|
||||
'recurrent' => 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$package_cl_extra_types = array_keys($cl_extras);
|
||||
|
||||
$customer_ids_with_extras = array();
|
||||
foreach ($package_cl_extra_types as $package_cl_extra_type) {
|
||||
$customer_id_with_extras = explode('_customer_', $package_cl_extra_type)[1];
|
||||
|
||||
if (isset($customer_id_with_extras) && ($customer_id_with_extras = absint($customer_id_with_extras)) > 0) {
|
||||
$customer_ids_with_extras[] = $customer_id_with_extras;
|
||||
}
|
||||
}
|
||||
$customer_ids_with_extras = array_unique($customer_ids_with_extras);
|
||||
|
||||
require 'views/html-cl-package-details.php';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @section Customize display of list table products for commercial lead
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define columns for commercial lead view
|
||||
* @param array $columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_columns($columns) {
|
||||
$cl_columns = array();
|
||||
|
||||
$cl_columns['thumb'] = $columns['thumb'];
|
||||
$cl_columns['wiaas_cl_name'] = $columns['name'];
|
||||
$cl_columns['taxonomy-package_type'] = __('Type', 'wiaas');
|
||||
$cl_columns['taxonomy-package_status'] = __('Status', 'wiaas');
|
||||
$cl_columns['taxonomy-product_country'] = $columns['taxonomy-product_country'];
|
||||
$cl_columns['date'] = $columns['date'];
|
||||
|
||||
return $cl_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide list table products bulk actions for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_bulk_actions() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide list table products views for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_views() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show only ID in table products views for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_row_actions($actions, $post) {
|
||||
if ($post->post_type === 'product') {
|
||||
return array( 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $post->ID ) );
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define custom primary column in list table products for commercial lead view
|
||||
*
|
||||
* @param $default
|
||||
* @param $screen_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function define_list_table_products_primary_column($default, $screen_id) {
|
||||
if ( 'edit-product' === $screen_id ) {
|
||||
return 'wiaas_cl_name';
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public static function render_list_table_products_columns($column, $post_id) {
|
||||
if ($column === 'wiaas_cl_name') {
|
||||
|
||||
$package = wc_get_product($post_id);
|
||||
|
||||
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-cl-package&cl_package_id=' . absint( $package->get_id() ) );
|
||||
|
||||
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) . '">' . esc_html( $package->get_title() ) . '</a></strong>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// PRIVATE HANDLERS
|
||||
|
||||
private static function _handle_cl_extras_update($package_id) {
|
||||
$cl_extras = wp_unslash($_POST['cl_extras']);
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
$posted_cl_extras = array();
|
||||
|
||||
foreach ($cl_extras as $cl_extra) {
|
||||
|
||||
$customer_id = isset($cl_extra['customer']) ? absint($cl_extra['customer']) : 0;
|
||||
$type = sanitize_key($cl_extra['type']);
|
||||
|
||||
$fixed_extra = isset($cl_extra['fixed']) ? floatval($cl_extra['fixed']) : 0;
|
||||
$services_extra = isset($cl_extra['services']) ? floatval($cl_extra['services']) : 0;
|
||||
$recurrent_extra = isset($cl_extra['recurrent']) ? floatval($cl_extra['recurrent']) : 0;
|
||||
|
||||
$extra_type = $customer_id > 0 ? $type.'_customer_'.$customer_id : $type.'_default';
|
||||
|
||||
if (in_array($type, $pay_types)) {
|
||||
$posted_cl_extras[$extra_type] = array(
|
||||
'type' => $type,
|
||||
'visible' => $cl_extra['visible'] === 'on',
|
||||
'fixed' => $fixed_extra,
|
||||
'services' => $services_extra,
|
||||
'recurrent' => $recurrent_extra,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_CL_Pricing::set_extras(
|
||||
wiaas_get_current_user_organization_id(),
|
||||
$package_id,
|
||||
$posted_cl_extras
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL_Packages::init();
|
||||
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
#tabs-navigation {
|
||||
height: 30px;
|
||||
}
|
||||
#tabs-navigation > li {
|
||||
float: left;
|
||||
line-height: 30px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#tabs-navigation > li.ui-state-active > a {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#tabs-navigation > li.ui-state-disabled > a {
|
||||
color: #ccc;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#tabs-navigation > li > a {
|
||||
text-decoration: none;
|
||||
padding: .5em;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead {
|
||||
background: #f2f2f2;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead td {
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead i {
|
||||
position: absolute;
|
||||
vertical-align: top;
|
||||
right: -8px;
|
||||
top: -8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td:first-child {
|
||||
max-width: 100px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td:nth-child(2) label {
|
||||
float: left;;
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices input[type='text'] {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#managed_36 > td:nth-child(2) > div:last-child {
|
||||
position: relative;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
#managed_36 > td:nth-child(2) > div:last-child > span {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 70px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
</script>
|
||||
|
||||
<div class="wrap">
|
||||
<div id="poststuff">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
<div>
|
||||
<?php
|
||||
foreach ($bundled_items_per_category as $category => $category_bundled_items) {
|
||||
echo sprintf(
|
||||
'<strong style="text-transform: uppercase;" class="text-uppercase">%s (%s)</strong>',
|
||||
esc_attr( $category ),
|
||||
esc_attr(count($category_bundled_items)) );
|
||||
foreach ($category_bundled_items as $bundled_item) {
|
||||
$title = $bundled_item->product->get_title();
|
||||
echo sprintf( '<p>%s x %s</p>', esc_attr($bundled_item->get_quantity('max')), esc_attr( $title ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="postbox-container-2" class="postbox-container">
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
<h1 style="padding: 0;"><?php echo $package->get_name(); ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (! empty($package->get_short_description())) {
|
||||
?>
|
||||
<div class="postbox">
|
||||
<?php wp_editor( $package->get_short_description(), 'content', array(
|
||||
'_content_editor_dfw' => $_content_editor_dfw,
|
||||
'drag_drop_upload' => false,
|
||||
'media_buttons' => false,
|
||||
'quicktags' => false,
|
||||
'tabfocus_elements' => 'content-html',
|
||||
'tinymce' => array(
|
||||
'resize' => false,
|
||||
'wp_autoresize_on' => true,
|
||||
'add_unload_trigger' => false,
|
||||
'wp_keep_scroll_position' => ! $is_IE,
|
||||
'readonly'=> true,
|
||||
'toolbar' => false,
|
||||
),
|
||||
) ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
|
||||
<div class="wrap">
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('EPR', 'wiaas') ?></strong>
|
||||
<span><?php esc_html_e('= Extra package recurrent commission', 'wiaas') ?></span>
|
||||
</div>
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('ESR') ?></strong>
|
||||
<span><?php esc_html_e('= Extra services and support recurrent commission', 'wiaas') ?></span>
|
||||
</div>
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('Extra commission', 'wiaas') ?></strong>
|
||||
<span><?php esc_html_e('= EPR + ESR', 'wiaas') ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="tabs" data-disabled="<?php echo $has_default_cl_extras ? '' : '1' ; ?>">
|
||||
<ul id="tabs-navigation">
|
||||
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
|
||||
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
|
||||
</ul>
|
||||
|
||||
<form id="wiaas_package_extras" action="" method="post">
|
||||
<input type="hidden" name="page" value="wiaas-cl-package"/>
|
||||
<input type="hidden" id="wiaas_cl_package_id" name="cl_package_id" value="<?php echo esc_attr($package->get_id()) ?>"/>
|
||||
|
||||
<div id="tabs-1">
|
||||
|
||||
<?php require 'html-cl-package-prices.php'; ?>
|
||||
|
||||
</div>
|
||||
<div id="tabs-2">
|
||||
|
||||
<div class="form-group">
|
||||
<select id="wiaas_cl_customers" class="form-control">
|
||||
<option selected value="0" disabled> Select customer ...</option>
|
||||
<?php
|
||||
$customers = wiaas_get_customers();
|
||||
foreach ($customers as $id => $name) {
|
||||
// shik current organization if it has role of customer
|
||||
if ($id === $cl_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
?>
|
||||
<option
|
||||
<?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
|
||||
id="wiaas_cl_customer_<?php esc_attr_e($id, 'wiaas') ?>"
|
||||
value="<?php esc_attr_e($id, 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($name, 'wiaas') ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php wp_nonce_field( 'wiaas_create_cl_customer_extras', 'wiaas_create_cl_customer_extras_nonce' ); ?>
|
||||
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Render customer specific prices if any
|
||||
foreach ($customer_ids_with_extras as $customer_id) {
|
||||
require 'html-cl-package-prices.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php wp_nonce_field( 'wiaas_save_cl_extras', 'wiaas_save_cl_extras_nonce' ); ?>
|
||||
<?php submit_button( __( 'Save', 'wiaas' ), 'primary', 'submit' ); ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
|
||||
|
||||
?>
|
||||
|
||||
<table id="<?php esc_attr_e($id, 'wiaas') ?>" style="margin-top: 20px;" class="widefat wiaas-configured-prices">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
echo '<h4>'. esc_html(wiaas_get_organization_name($customer_id)). '</h4>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td><?php esc_html_e('Minimal sell price', 'wiaas') ?></td>
|
||||
<td><?php esc_html_e('Extra commision', 'wiaas') ?></td>
|
||||
<td><?php esc_html_e('Default price', 'wiaas') ?></td>
|
||||
<td><?php esc_html_e('Visible?', 'wiaas') ?>
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
?>
|
||||
<i
|
||||
data-customer_id="<?php esc_attr_e($customer_id, 'wiaas') ?>"
|
||||
class="dashicons dashicons-dismiss wiaas_remove_cl_extras"
|
||||
></i>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
|
||||
$extra_type = isset($customer_id) ? $type.'_customer_'.$customer_id : $type.'_default';
|
||||
|
||||
?>
|
||||
<input
|
||||
type="hidden"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][type]"
|
||||
value="<?php esc_attr_e($type, 'wiaas')?>"
|
||||
>
|
||||
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
?>
|
||||
<input
|
||||
type="hidden"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][customer]"
|
||||
value="<?php esc_attr_e($customer_id, 'wiaas')?>"
|
||||
>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<tr id="<?php esc_attr_e($extra_type, 'wias')?>">
|
||||
<td>
|
||||
<strong><?php esc_html_e($configured_price['payment_type']) ?></strong>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<div class="form-control">
|
||||
<label>Fixed:</label>
|
||||
<input type="text" value="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>" readonly>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label>Monthly:</label>
|
||||
<input type="text" value="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>" readonly>
|
||||
<?php
|
||||
if($configured_price['package_pay_period'] > 0) {
|
||||
echo sprintf( '<span>(%s for services)</span>', esc_attr( $configured_price['minimal_services_price'] ) );
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="fixed"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][fixed]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['fixed'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
</div>
|
||||
<?php
|
||||
if($configured_price['package_pay_period'] > 0) {
|
||||
?>
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_recurrent_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="recurrent"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][recurrent]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
<label><?php esc_html_e('(EPR)', 'wiaas') ?></label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="services"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][services]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
<label><?php esc_html_e('(ESR)', 'wiaas') ?></label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div> =
|
||||
<strong
|
||||
id="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-base="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($configured_price['minimal_fixed_price'] + $cl_extras[$extra_type]['fixed'], 'wiaas') ?>
|
||||
</strong>
|
||||
</div>
|
||||
<div> =
|
||||
<strong
|
||||
id="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-base="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>"
|
||||
data-recurrent="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||
data-services="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||
>
|
||||
<?php
|
||||
esc_html_e($configured_price['minimal_recurrent_price'] +
|
||||
$cl_extras[$extra_type]['recurrent'] +
|
||||
$cl_extras[$extra_type]['services'], 'wiaas')
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<input
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][visible]"
|
||||
<?php checked($cl_extras[$extra_type]['visible'], true, true) ?>
|
||||
type="checkbox"
|
||||
>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
add_action('wp_ajax_wiaas_create_cl_customer_extras', 'wiaas_ajax_create_cl_customer_extras');
|
||||
|
||||
function wiaas_ajax_create_cl_customer_extras() {
|
||||
check_ajax_referer('wiaas_create_cl_customer_extras');
|
||||
|
||||
$customer_id = absint($_POST['customer_id']);
|
||||
$package_id = absint($_POST['package_id']);
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$cl_extras = array();
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
$cl_extras[$type.'_customer_'.$customer_id] = array(
|
||||
'type' => $type,
|
||||
'visible' => true,
|
||||
'fixed' => 0,
|
||||
'services' => 0,
|
||||
'recurrent' => 0
|
||||
);
|
||||
}
|
||||
|
||||
require_once 'views/html-cl-package-prices.php';
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Wiaas_Admin_CL {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('init', array(__CLASS__, 'init_admin_cl'));
|
||||
}
|
||||
|
||||
public static function init_admin_cl() {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$role = $user->roles[0];
|
||||
|
||||
if ($role === 'commercial_lead') {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_script( 'wiaas_admin_cl_packages', $plugin_url . '/assets/js/wiaas-admin-cl-packages.js' );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_cl', $plugin_url . '/assets/css/wiaas-admin-cl.css' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL::init();
|
||||
@@ -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();
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Organization {
|
||||
|
||||
public static function init() {
|
||||
// role switcher for organization
|
||||
add_action( 'admin_bar_menu', array( __CLASS__, 'add_role_switcher_menu' ), 10, 2 );
|
||||
|
||||
// change user role if requested
|
||||
add_action('admin_init', array(__CLASS__, 'maybe_change_user_role'));
|
||||
|
||||
add_filter('manage_users_columns', array(__CLASS__, 'manage_users_table_columns'));
|
||||
add_filter('views_users', array(__CLASS__, 'hide_users_table_list_navigation'));
|
||||
|
||||
add_filter('get_role_list', array(__CLASS__, 'get_role_list_for_user'), 10, 2);
|
||||
|
||||
|
||||
add_filter('woocommerce_customer_meta_fields', array(__CLASS__, 'hide_woocommerce_customer_fields'));
|
||||
}
|
||||
|
||||
public static function hide_woocommerce_customer_fields() {
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function hide_users_table_list_navigation() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render user organization roles as available user roles on user list
|
||||
* @param $role_list
|
||||
* @param $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_role_list_for_user($role_list, $user) {
|
||||
$organization_id = wiaas_get_user_organization_id($user->ID);
|
||||
|
||||
if (! empty($organization_id)) {
|
||||
$organization_roles = wiaas_get_organization_roles($organization_id);
|
||||
|
||||
foreach ($organization_roles as $organization_role) {
|
||||
$role_list[$organization_role] = translate_user_role( wp_roles()->role_names[ $organization_role ] );
|
||||
}
|
||||
|
||||
if (! empty($organization_role)) {
|
||||
unset($role_list['none']);
|
||||
}
|
||||
}
|
||||
|
||||
return $role_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize columns for users table list view
|
||||
*
|
||||
* @param array $defaults
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_users_table_columns( $defaults = array() ) {
|
||||
|
||||
$defaults['role'] = __('Roles', 'wiaas');
|
||||
|
||||
unset($defaults['posts']);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds organization roles switcher menu to admin bar
|
||||
*
|
||||
* @param $admin_bar
|
||||
*/
|
||||
public static function add_role_switcher_menu($admin_bar) {
|
||||
if (is_super_admin()) {
|
||||
$roles = array( 'administrator' );
|
||||
} else {
|
||||
$organization_id = wiaas_get_current_user_organization_id();
|
||||
$roles = wiaas_get_organization_roles($organization_id);
|
||||
}
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$current_role = $user->roles[0];
|
||||
|
||||
// Add menu item.
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'wiaas-view-as',
|
||||
'parent' => 'top-secondary',
|
||||
'title' => '<span>' .
|
||||
__( 'View as:', 'wiaas' ) .
|
||||
'</span>' .
|
||||
'<span style="margin-left: 6px; font-weight: bold;">'.
|
||||
__(translate_user_role( wp_roles()->role_names[ $current_role ] ), 'wiaas') .
|
||||
'</span>' .
|
||||
'<i style="float: right;" class="ab-icon dashicons dashicons-arrow-down"></i>',
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'title' => __( 'View As', 'wiaas' ),
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$role_name = translate_user_role( wp_roles()->role_names[ $role ] );
|
||||
|
||||
if ($role === $current_role) {
|
||||
// highlight current role
|
||||
$title = '<span class="ab-label">' . __( $role_name, 'wiaas' ) . '</span>';
|
||||
|
||||
$url = false;
|
||||
|
||||
} else if ($role === 'customer') {
|
||||
// set external link for customer role
|
||||
$title = '<span>' . __( $role_name, 'wiaas' ) . '</span>';
|
||||
$title .= '<span class="ab-icon dashicons dashicons-external"></span>';
|
||||
|
||||
$url = WIAAS_CUSTOMER_INTERFACE;
|
||||
|
||||
$target = '_blank';
|
||||
|
||||
} else {
|
||||
$title = '<span>' . __( $role_name, 'wiaas' ) . '</span>';
|
||||
|
||||
$url = wp_nonce_url(admin_url(), 'wiaas-set-role', 'wiaas-set-role-nonce');
|
||||
$url = add_query_arg( 'wiaas-role', $role, $url );
|
||||
|
||||
$target = '_parent';
|
||||
}
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'wiaas_'.$role,
|
||||
'parent' => 'wiaas-view-as',
|
||||
'title' => $title,
|
||||
'href' => $url,
|
||||
'meta' => array(
|
||||
'title' => __( $role_name, 'wiaas' ),
|
||||
'target' => $target
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Process organization role switch request if needed
|
||||
*
|
||||
*/
|
||||
public static function maybe_change_user_role() {
|
||||
if (! empty($_GET['wiaas-set-role-nonce']) && ! empty($_GET['wiaas-role'])) {
|
||||
if (wp_verify_nonce($_GET['wiaas-set-role-nonce'], 'wiaas-set-role')) {
|
||||
$role_name = sanitize_key($_GET['wiaas-role']);
|
||||
|
||||
$role = wp_roles()->get_role($role_name);
|
||||
|
||||
if (! empty($role) && $role_name !== 'customer') {
|
||||
// get current user
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
update_user_meta($current_user->ID, '_wiaas_current_user_admin_role', $role->name);
|
||||
|
||||
// switch user role
|
||||
$current_user->set_role($role->name);
|
||||
}
|
||||
}
|
||||
|
||||
wp_safe_redirect( admin_url('index.php') );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Organization::init();
|
||||
@@ -7,16 +7,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class Wiaas_Admin_Package {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-linked-packages.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-package-types.php';
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Package::init();
|
||||
@@ -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();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -58,6 +58,7 @@ class Wiaas_Admin_Package_Pricing {
|
||||
$package = wc_get_product( $post->ID );
|
||||
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
|
||||
$max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
|
||||
|
||||
include 'views/html-package-pricing.php';
|
||||
}
|
||||
@@ -71,7 +72,8 @@ class Wiaas_Admin_Package_Pricing {
|
||||
Wiaas_Package_Pricing::set_package_prices(
|
||||
wc_get_product( $post_id ),
|
||||
$_POST['wiaas_pricing_rules'],
|
||||
$_POST['wiaas_pricing_rules_commision']);
|
||||
$_POST['wiaas_pricing_rules_commision'],
|
||||
$_POST['wiaas_max_cost_margin']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
<?php
|
||||
|
||||
$value = $pricing_rule['minimal_services_price'];
|
||||
if ($pricing_rule['principal_amount'] > 0 && $pay_type['package_pay_period'] > 0) {
|
||||
$value += wiaas_PMT(
|
||||
Wiaas_Pricing::INTEREST_RATE,
|
||||
$pay_type['package_pay_period'],
|
||||
$pricing_rule['principal_amount']);
|
||||
}
|
||||
$value = $pricing_rule['minimal_recurrent_price'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
|
||||
@@ -144,6 +144,20 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_max_cost_margin',
|
||||
'name' => 'wiaas_max_cost_margin',
|
||||
'value' => $max_cost_margin,
|
||||
'label' => __( 'Max cost margin:', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
|
||||
@@ -6,12 +6,24 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
$("#general_product_data").find('.pricing').addClass('hide_if_bundle');
|
||||
$("#general_product_data").find('.pricing').removeClass('show_if_bundle');
|
||||
|
||||
if ($('#product-type').val() === 'bundle') {
|
||||
$("#general_product_data .pricing").hide();
|
||||
if ($('#product-type').val() === 'simple') {
|
||||
$('#general_product_data').find('.pricing').show();
|
||||
} else {
|
||||
$('#general_product_data').find('.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>
|
||||
|
||||
@@ -21,7 +33,7 @@ woocommerce_wp_checkbox(
|
||||
'id' => '_wiaas_recurring_price',
|
||||
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
|
||||
'data_type' => 'price',
|
||||
'label' => __( $product->get_category_ids()[0], 'wiaas' ),
|
||||
'label' => __( 'Is recurring?', 'wiaas' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -3,27 +3,35 @@
|
||||
class Wiaas_Admin_Template_Selection {
|
||||
|
||||
public static function init() {
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'create_custom_meta_box'), 100);
|
||||
add_action('woocommerce_process_product_meta_bundle', array(__CLASS__, 'save_custom_content_meta_box'), 10, 1);
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'create_template_meta_box'), 100);
|
||||
add_action('woocommerce_process_product_meta_bundle', array(__CLASS__, 'save_template_content_meta_box'), 10, 1);
|
||||
|
||||
// Processes and saves type-specific data.
|
||||
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'validate_bundle'), 11);
|
||||
|
||||
}
|
||||
|
||||
public static function create_custom_meta_box() {
|
||||
/**
|
||||
* Renders template selection meta box
|
||||
*/
|
||||
public static function create_template_meta_box() {
|
||||
add_meta_box(
|
||||
'template_product_meta_box',
|
||||
__('Choose package template <em>(optional)</em>', 'cmb'),
|
||||
'Wiaas_Admin_Template_Selection::add_custom_content_meta_box',
|
||||
'Wiaas_Admin_Template_Selection::add_template_content_meta_box',
|
||||
'product',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static function add_custom_content_meta_box($post) {
|
||||
/**
|
||||
* Fill in the value of template selection dropdown,
|
||||
* and render template categories of the selected template
|
||||
*
|
||||
* @param $post WP_Post object
|
||||
*/
|
||||
public static function add_template_content_meta_box($post) {
|
||||
|
||||
$value = get_post_meta($post->ID, '_select_template', true);
|
||||
|
||||
@@ -49,49 +57,82 @@ class Wiaas_Admin_Template_Selection {
|
||||
$template_products_data = self::show_template_products($value);
|
||||
|
||||
self::render_template_products($template_products_data['hardware']);
|
||||
self::render_template_products($template_products_data['service']);
|
||||
self::render_template_products($template_products_data['services']);
|
||||
self::render_template_products($template_products_data['installation']);
|
||||
self::render_template_products($template_products_data['software']);
|
||||
?></div><?php
|
||||
|
||||
}
|
||||
|
||||
public static function get_categories_from_templates($products_form_template) {
|
||||
/**
|
||||
* Extract template categories for all of the main product categories
|
||||
* (software , hardware, services, installation) and combine them in one array
|
||||
*
|
||||
* @param $categories_form_template
|
||||
* @return array of Wiaas_Template_Category_Object
|
||||
*/
|
||||
public static function get_categories_from_templates($categories_form_template) {
|
||||
|
||||
$all_template_categories = array();
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['hardware']));
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['service']));
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['installation']));
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['software']));
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['hardware']));
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['services']));
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['installation']));
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['software']));
|
||||
|
||||
return $all_template_categories;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the template product meta_data from selected template
|
||||
*
|
||||
* @param $selected_template integer an id of selected template
|
||||
* @return array of template categories
|
||||
*/
|
||||
public static function show_template_products($selected_template) {
|
||||
|
||||
|
||||
if (empty($selected_template)) {
|
||||
return;
|
||||
return array();
|
||||
|
||||
} else {
|
||||
$template_products_hardware = (get_post_meta($selected_template, '_template_items_hardware', true));
|
||||
$template_products_service = (get_post_meta($selected_template, '_template_items_service', true));
|
||||
$template_products_installation = (get_post_meta($selected_template, '_template_items_installation', true));
|
||||
$template_products_software = (get_post_meta($selected_template, '_template_items_software', true));
|
||||
|
||||
$template_products_hardware = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_hardware');
|
||||
|
||||
$template_products_services = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_services');
|
||||
|
||||
$template_products_installation = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_installation');
|
||||
|
||||
$template_products_software = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_software');
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'hardware' => $template_products_hardware,
|
||||
'service' => $template_products_service,
|
||||
'services' => $template_products_services,
|
||||
'installation' => $template_products_installation,
|
||||
'software' => $template_products_software
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render html of template categories
|
||||
*
|
||||
* @param $template_products array containing template category information
|
||||
*/
|
||||
public static function render_template_products($template_products) {
|
||||
if (!empty($template_products)) {
|
||||
|
||||
@@ -108,90 +149,43 @@ class Wiaas_Admin_Template_Selection {
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_product_categories($category_meta) {
|
||||
$category_objects = array();
|
||||
|
||||
/**
|
||||
* Save selected template
|
||||
*
|
||||
* @param $post_id WP_Post
|
||||
*/
|
||||
|
||||
if (empty($category_meta)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($category_meta as $meta) {
|
||||
|
||||
if (!empty($meta)) {
|
||||
|
||||
|
||||
$category_template_id = $meta['template_category_id'];
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$meta['template_category_title'],
|
||||
$meta['quantity']);
|
||||
|
||||
$category_objects[$category_template_id] = $template_category_object;
|
||||
}
|
||||
|
||||
}
|
||||
return empty($category_objects) ? null : $category_objects;
|
||||
}
|
||||
|
||||
public static function get_bundled_product_categories($bundled_items) {
|
||||
|
||||
$template_category_objects = array();
|
||||
foreach ($bundled_items as $item_id => $item) {
|
||||
$item_data = $item->get_data();
|
||||
$post_terms = wp_get_object_terms($item->get_product_id(), 'template_category', array('fields' => 'id=>name'));
|
||||
|
||||
if (!empty($post_terms) && !is_wp_error($post_terms)) {
|
||||
|
||||
$cat = '';
|
||||
$category_template_id = '';
|
||||
|
||||
foreach ($post_terms as $id => $term) {
|
||||
$cat = $term;
|
||||
$category_template_id = $id;
|
||||
}
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$cat,
|
||||
$item_data['quantity_max']);
|
||||
$template_category_objects[$category_template_id] = $template_category_object;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $template_category_objects;
|
||||
}
|
||||
|
||||
|
||||
function save_custom_content_meta_box($post_id) {
|
||||
function save_template_content_meta_box($post_id) {
|
||||
$selected_template = $_POST['_select_template'];
|
||||
if (!empty($selected_template))
|
||||
update_post_meta($post_id, '_select_template', esc_attr($selected_template));
|
||||
else {
|
||||
update_post_meta($post_id, '_select_template', '');
|
||||
}
|
||||
|
||||
WC_Product_Template::bind_selected_template_to_product($selected_template, $post_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template categories from bundle products and selected template
|
||||
* Compare template categories and quantities that are required by the template with those in bundle products
|
||||
*
|
||||
* Admin error is added if validation is not satisfied
|
||||
*
|
||||
* @param $product WC_Product_Bundle
|
||||
*/
|
||||
public static function validate_bundle($product) {
|
||||
|
||||
|
||||
if ($product->get_type() == 'bundle') {
|
||||
$selected_template = $_POST['_select_template'];
|
||||
$bundled_items = $product->get_bundled_items('view');
|
||||
$products_form_template = self::show_template_products($selected_template);
|
||||
$template_categories_form_template = self::show_template_products($selected_template);
|
||||
|
||||
$missing_categories = array();
|
||||
$insufficient_product_quantities = array();
|
||||
$missing_template_categories = array();
|
||||
$insufficient_template_category_quantities = array();
|
||||
|
||||
|
||||
$categories_form_template = self::get_categories_from_templates($products_form_template);
|
||||
$categories_form_bundle = self::get_bundled_product_categories($bundled_items);
|
||||
$categories_form_template = self::get_categories_from_templates($template_categories_form_template);
|
||||
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
|
||||
$bundle_category_keys = array_keys($categories_form_bundle);
|
||||
|
||||
|
||||
if (!empty($categories_form_template)) {
|
||||
|
||||
foreach ($categories_form_template as $category) {
|
||||
@@ -200,7 +194,7 @@ class Wiaas_Admin_Template_Selection {
|
||||
|
||||
if (!in_array($template_cat_id, $bundle_category_keys)) {
|
||||
|
||||
array_push($missing_categories, $category->name);
|
||||
array_push($missing_template_categories, $category->name);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -208,37 +202,25 @@ class Wiaas_Admin_Template_Selection {
|
||||
$quantity_from_template = $category->quantity;
|
||||
|
||||
if ((int)($quantity_from_template) !== $product_from_bundle_quantity) {
|
||||
array_push($insufficient_product_quantities, $category->name);
|
||||
array_push($insufficient_template_category_quantities, $category->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$categories_message = implode(',', $missing_categories);
|
||||
$quantity_message = implode(',', $insufficient_product_quantities);
|
||||
$template_categories_message = implode(',', $missing_template_categories);
|
||||
$quantity_message = implode(',', $insufficient_template_category_quantities);
|
||||
|
||||
if (!empty($missing_categories)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $categories_message, 'woocommerce-product-bundles'));
|
||||
if (!empty($missing_template_categories)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $template_categories_message, 'woocommerce-product-bundles'));
|
||||
}
|
||||
|
||||
if (!empty($insufficient_product_quantities)) {
|
||||
if (!empty($insufficient_template_category_quantities)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories with different quantities: ' . $quantity_message, 'woocommerce-product-bundles'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function get_category_ids_form_bundle($product) {
|
||||
$products_form_budnle = $product->get_bundled_data_items();
|
||||
$product_ids = array();
|
||||
|
||||
foreach ($products_form_budnle as $product) {
|
||||
array_push($product_ids, $product->get_id());
|
||||
}
|
||||
|
||||
return self::get_product_categories($product_ids);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Template_Selection::init();
|
||||
|
||||
@@ -21,6 +21,10 @@ class Wiaas_Template_Admin_Ajax {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An ajax callback action for handling template selection
|
||||
*/
|
||||
|
||||
public static function ajax_handle_template_selection() {
|
||||
|
||||
$selected_template_id = intval($_POST['selected_template']);
|
||||
@@ -34,7 +38,7 @@ class Wiaas_Template_Admin_Ajax {
|
||||
if (!empty($template_products)) {
|
||||
ob_start();
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['hardware']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['service']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['services']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['installation']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['software']);
|
||||
|
||||
@@ -53,7 +57,7 @@ class Wiaas_Template_Admin_Ajax {
|
||||
check_ajax_referer('wc_bundles_add_bundled_product', 'security');
|
||||
|
||||
$loop = intval($_POST['id']);
|
||||
$product_id = intval($_POST['product_id']);
|
||||
$template_category_id = intval($_POST['template_category_id']);
|
||||
$title = $_POST['title'];
|
||||
$options = $_POST['options'];
|
||||
|
||||
@@ -70,13 +74,13 @@ class Wiaas_Template_Admin_Ajax {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handles adding template categories search.
|
||||
*/
|
||||
public static function ajax_wiaas_template_category_search() {
|
||||
|
||||
$term = ($_POST['term']);
|
||||
$term = wp_unslash($_GET['term']);
|
||||
$response = array();
|
||||
|
||||
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => 'template_category',
|
||||
'name__like' => $term
|
||||
|
||||
@@ -7,7 +7,6 @@ class Wiaas_template {
|
||||
|
||||
public static function init() {
|
||||
add_filter('product_type_selector', array(__CLASS__, 'add_template_product_type'));
|
||||
add_action('admin_footer', array(__CLASS__, 'templates_custom_js'));
|
||||
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'custom_product_tabs'));
|
||||
add_action('woocommerce_product_data_panels', array(__CLASS__, 'wiaastemplate_product_tab_content_all'));
|
||||
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'save_wiaastemplate'));
|
||||
@@ -35,7 +34,7 @@ class Wiaas_template {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to product type drop down.
|
||||
* Add template product type drop down.
|
||||
*/
|
||||
function add_template_product_type($types) {
|
||||
|
||||
@@ -48,27 +47,7 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Show pricing fields for template product.
|
||||
*/
|
||||
function templates_custom_js() {
|
||||
|
||||
if ('product' != get_post_type()) :
|
||||
return;
|
||||
endif;
|
||||
|
||||
?>
|
||||
<script type='text/javascript'>
|
||||
jQuery(document).ready(function () {
|
||||
jQuery('.options_group.pricing').addClass('show_if_simple_template').show();
|
||||
});
|
||||
|
||||
</script><?php
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a custom product tab.
|
||||
* Add template product, hardware, services, installation and software tabs product tab.
|
||||
*/
|
||||
function custom_product_tabs($tabs) {
|
||||
|
||||
@@ -100,6 +79,10 @@ class Wiaas_template {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content do template tabs
|
||||
*/
|
||||
|
||||
public static function wiaastemplate_product_tab_content_all() {
|
||||
|
||||
self::wiaastemplate_product_tab_content('hardware');
|
||||
@@ -110,8 +93,11 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Contents of the template options product tab.
|
||||
* Html contents of the template options product tab.
|
||||
*
|
||||
* @param $options string main wiaas category
|
||||
*/
|
||||
|
||||
public static function wiaastemplate_product_tab_content($options) {
|
||||
|
||||
global $post;
|
||||
@@ -128,7 +114,7 @@ class Wiaas_template {
|
||||
|
||||
foreach ($template_items as $item) {
|
||||
|
||||
$product_id = $item['template_category_id'];
|
||||
$template_category_id = $item['template_category_id'];
|
||||
$title = $item['template_category_title'];
|
||||
$quantity = $item['quantity'];
|
||||
|
||||
@@ -142,7 +128,7 @@ class Wiaas_template {
|
||||
<select class="wiaas-term-search" id="wiaastemplate_products<?php echo '_' . $options ?>" style="width: 250px;"
|
||||
name="template_product"
|
||||
data-placeholder="<?php _e('Add product to template…', 'wiaas'); ?>"
|
||||
data-action="woocommerce_json_search_products" multiple="multiple" data-limit="500">
|
||||
multiple="multiple" data-limit="500">
|
||||
<option></option>
|
||||
</select>
|
||||
<?php echo wc_help_tip(__('Search for a product and add it to this template by clicking its name in the results list.', 'wiaas')); ?>
|
||||
@@ -154,7 +140,7 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Save the custom fields.
|
||||
* Save the template categories that are bind to template.
|
||||
*/
|
||||
function save_wiaastemplate($post_id) {
|
||||
|
||||
@@ -163,14 +149,21 @@ class Wiaas_template {
|
||||
$posted_template_data_installation = isset($_POST['template_data_installation']) ? $_POST['template_data_installation'] : false;
|
||||
$posted_template_data_software = isset($_POST['template_data_software']) ? $_POST['template_data_software'] : false;
|
||||
|
||||
self::save_template_product_meta($post_id, $posted_template_data_hardware, 'hardware');
|
||||
self::save_template_product_meta($post_id, $posted_template_data_services, 'services');
|
||||
self::save_template_product_meta($post_id, $posted_template_data_installation, 'installation');
|
||||
self::save_template_product_meta($post_id, $posted_template_data_software, 'software');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_hardware, 'hardware');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_services, 'services');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_installation, 'installation');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_software, 'software');
|
||||
|
||||
}
|
||||
|
||||
public static function save_template_product_meta($post_id, $posted_template_data, $option) {
|
||||
/**
|
||||
* Get extract posted data and save them to meta
|
||||
*
|
||||
* @param $post_id integer id of the template
|
||||
* @param $posted_template_data mixed
|
||||
* @param $option string indicating main wiaas category
|
||||
*/
|
||||
public static function process_and_save_template_product_meta($post_id, $posted_template_data, $option) {
|
||||
$processed_template_data = array();
|
||||
|
||||
// Sort posted data by menu order.
|
||||
@@ -178,24 +171,24 @@ class Wiaas_template {
|
||||
|
||||
foreach ($posted_template_data as $data) {
|
||||
|
||||
$product_id = isset($data['product_id']) ? absint($data['product_id']) : false;
|
||||
$product_title = isset($data['product_title']) ? $data['product_title'] : false;
|
||||
$template_category_id = isset($data['template_category_id']) ? absint($data['template_category_id']) : false;
|
||||
$template_category_title = isset($data['template_category_title']) ? $data['template_category_title'] : false;
|
||||
$quantity = isset($data['quantity']) ? absint($data['quantity']) : false;
|
||||
|
||||
|
||||
$item_data = array(
|
||||
|
||||
'template_category_id' => $product_id,
|
||||
'template_category_title' => trim($product_title),
|
||||
'template_category_id' => $template_category_id,
|
||||
'template_category_title' => trim($template_category_title),
|
||||
'quantity' => $quantity
|
||||
|
||||
);
|
||||
|
||||
$processed_template_data[$product_id] = $item_data;
|
||||
$processed_template_data[$template_category_id] = $item_data;
|
||||
|
||||
}
|
||||
|
||||
update_post_meta($post_id, '_template_items_' . $option, $processed_template_data);
|
||||
WC_Product_Template::save_template_product_meta($post_id, $option, $processed_template_data);
|
||||
}
|
||||
|
||||
public static function menu_sort_order($a, $b) {
|
||||
@@ -208,7 +201,7 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Hide Attributes data panel.
|
||||
* Hide default WC_Product data panels.
|
||||
*/
|
||||
function hide_attributes_data_panel($tabs) {
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ if (!defined('ABSPATH')) {
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][item_id]" class="item_id" value="<?php echo $item_id; ?>" /><?php
|
||||
}
|
||||
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][product_title]" class="product_title" value="<?php echo $title; ?>" /><?php
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][product_id]" class="product_id" value="<?php echo $product_id; ?>" />
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][template_category_title]" class="product_title" value="<?php echo $title; ?>" /><?php
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][template_category_id]" class="product_id" value="<?php echo $template_category_id; ?>" />
|
||||
|
||||
</div><?php
|
||||
|
||||
|
||||
@@ -32,14 +32,12 @@ class Wiaas_Cart_API {
|
||||
'description' => __( 'Wiaas package ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'price_id' => array(
|
||||
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'options_ids' => array(
|
||||
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
|
||||
@@ -47,7 +45,6 @@ class Wiaas_Cart_API {
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
)
|
||||
),
|
||||
'addons_ids' => array(
|
||||
@@ -56,7 +53,6 @@ class Wiaas_Cart_API {
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'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' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -86,12 +81,69 @@ class Wiaas_Cart_API {
|
||||
'description' => __( 'New quantity cart package item.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'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(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array(__CLASS__, 'checkout'),
|
||||
@@ -158,6 +210,7 @@ class Wiaas_Cart_API {
|
||||
public static function get_cart_items() {
|
||||
return rest_ensure_response(array(
|
||||
'items' => Wiaas_Cart::get_cart_packages(),
|
||||
'raw' => WC()->cart->get_cart_contents(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -176,11 +229,13 @@ class Wiaas_Cart_API {
|
||||
$request['options_ids']
|
||||
);
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,11 +247,13 @@ class Wiaas_Cart_API {
|
||||
|
||||
$success = Wiaas_Cart::remove_package_from_cart($request['key']);
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,11 +264,51 @@ class Wiaas_Cart_API {
|
||||
|
||||
$success = Wiaas_Cart::update_package_quantity($request['key'], $request['quantity']);
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$success = Wiaas_Cart::upload_cart_document($request['doc_type'], $request['package_key']);
|
||||
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_generate_error('UPLOAD_ERROR');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('FILE_UPLOADED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +321,10 @@ class Wiaas_Cart_API {
|
||||
|
||||
Wiaas_Checkout::process_checkout($request->get_body_params());
|
||||
|
||||
if (wc_notice_count('error') > 0) {
|
||||
return wiaas_api_cart_error_notices();
|
||||
}
|
||||
|
||||
return wiaas_api_notice('ORDER_PLACED', 'success');
|
||||
}
|
||||
}
|
||||
@@ -17,26 +17,73 @@ class Wiaas_Document_API {
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'download-package-file', array(
|
||||
register_rest_route( self::$namespace, 'documents', array(
|
||||
'methods' => 'GET',
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'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
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_package_file() {
|
||||
$document_id = $_GET['document_id'];
|
||||
$package_id = $_GET['package_id'];
|
||||
public static function download_package_file($request) {
|
||||
$document_id = $request['document_id'];
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
Wiaas_Document_Download::download_document($document_id);
|
||||
}
|
||||
|
||||
$file = $package->get_file($document_id);
|
||||
|
||||
if ($file) {
|
||||
WC_Download_Handler::download_file_force($package->get_file_download_path($document_id), $file->get_name());
|
||||
}
|
||||
/**
|
||||
* Download order document
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
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,79 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Package_API {
|
||||
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
|
||||
}
|
||||
|
||||
public static function register_routes() {
|
||||
// TODO: Handle this when assigment of customer to commercial lead is done
|
||||
register_rest_route( self::$namespace, '/commercial-leads', array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array(__CLASS__, 'get_customer_commercial_leads'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
}
|
||||
|
||||
// TODO: Handle this when assigment of customer to commercial lead is done
|
||||
public static function get_customer_commercial_leads() {
|
||||
$commercial_leads = array();
|
||||
|
||||
foreach (wiaas_get_commercial_leads() as $id => $name) {
|
||||
$commercial_leads[] = array(
|
||||
'id' => $id,
|
||||
'name' => $name
|
||||
);
|
||||
}
|
||||
|
||||
return rest_ensure_response($commercial_leads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter woocommerce REST API query so only valid wiaas packages are returned to the customer
|
||||
*
|
||||
* @param $args
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filter_packages($args, $request) {
|
||||
|
||||
if ( empty($query['tax_query']) ){
|
||||
$query['tax_query'] = array();
|
||||
}
|
||||
|
||||
// Retrieve only packages with available package status
|
||||
$query['tax_query'][] = array(
|
||||
'taxonomy' => 'package_status',
|
||||
'field' => 'name',
|
||||
'terms' => Wiaas_Package_Status::AVAILABLE
|
||||
);
|
||||
|
||||
|
||||
$commercial_lead_id = absint($request['cl_id']);
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
$price_search_terms = array();
|
||||
foreach ($pay_types as $pay_type) {
|
||||
$price_search_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_default';
|
||||
$price_search_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_customer_' . $customer_id;
|
||||
}
|
||||
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => '_wiaas_shop_prices',
|
||||
'terms' => $price_search_terms,
|
||||
'field' => 'slug'
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_API::init();
|
||||
@@ -22,6 +22,59 @@ function wiaas_api_notice($message, $code, $data = null) {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc error notices
|
||||
*
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_error_notices($data = null) {
|
||||
return wiaas_api_cart_notices('error', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc warning notices
|
||||
*
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_warning_notices($data = null) {
|
||||
return wiaas_api_cart_notices('notice', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc notices
|
||||
*
|
||||
* @param string $types Notice types (error, success)
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_notices($types, $data = null) {
|
||||
|
||||
$types = is_array($types) ? $types : array( $types );
|
||||
|
||||
$messages = array();
|
||||
foreach ($types as $type) {
|
||||
$messages = array_merge($messages, wc_get_notices($type));
|
||||
}
|
||||
wc_clear_notices();
|
||||
|
||||
$messages = array_map(function($message) {
|
||||
return array(
|
||||
'code' => 'error',
|
||||
'message' => $message
|
||||
);
|
||||
}, $messages);
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'messages' => $messages,
|
||||
'data' => $data
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate REST API error
|
||||
*
|
||||
|
||||
@@ -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(
|
||||
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Access_Management {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatize access control for product and packages
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param WP_Post $post
|
||||
*/
|
||||
public static function maybe_handle_product_access($post_id, $post) {
|
||||
|
||||
// $post_id and $post are required
|
||||
if ( empty( $post_id ) || empty( $post ) || $post->post_type !== 'product') {
|
||||
return;
|
||||
}
|
||||
|
||||
$product = wc_get_product($post_id);
|
||||
|
||||
$admin_access_group = Groups_Group::read_by_name('admin');
|
||||
|
||||
$access_group_ids = array();
|
||||
|
||||
if ($admin_access_group) {
|
||||
$access_group_ids[] = $admin_access_group->group_id;
|
||||
}
|
||||
|
||||
// allow commercial lead to see published bundle products
|
||||
$cl_access_group = Groups_Group::read_by_name('commercial_lead');
|
||||
|
||||
if ($product->get_type() === 'bundle' &&
|
||||
$product->get_status() === 'publish' &&
|
||||
$cl_access_group) {
|
||||
$access_group_ids[] = $cl_access_group->group_id;
|
||||
}
|
||||
|
||||
Groups_Post_Access::update(
|
||||
array(
|
||||
'post_id' => $product->get_id(),
|
||||
'groups_read' => $access_group_ids
|
||||
) );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Access_Management::init();
|
||||
@@ -15,7 +15,23 @@ class Wiaas_Admin {
|
||||
|
||||
// Admin order projects interface
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-projects.php';
|
||||
// Admin documents
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
|
||||
// Admin organization interface
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
}
|
||||
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
|
||||
wp_enqueue_style( 'wiaas_admin_packages', $plugin_url . '/assets/css/package.css' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin::init();
|
||||
|
||||
@@ -43,6 +43,8 @@ class Wiaas_API {
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-package-api.php';
|
||||
|
||||
// API functions
|
||||
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
||||
|
||||
@@ -55,7 +57,8 @@ class Wiaas_API {
|
||||
'Wiaas_Document_API',
|
||||
'Wiass_REST_User_API',
|
||||
'Wiaas_REST_Customer_API',
|
||||
'Wiaas_Order_Projects_API'
|
||||
'Wiaas_Order_Projects_API',
|
||||
'Wiaas_Package_API'
|
||||
);
|
||||
|
||||
foreach ( $controllers as $controller ) {
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handles user authentication for wiaas
|
||||
*
|
||||
* User roles are inherited from organization
|
||||
*
|
||||
* Class Wiaas_Authentication
|
||||
*/
|
||||
class Wiaas_Authentication {
|
||||
|
||||
const SUPER_ADMIN_USER_ID = 1;
|
||||
|
||||
public static function init() {
|
||||
// authenticate current user
|
||||
add_action('determine_current_user', array(__CLASS__, 'authenticate_current_user'), 999);
|
||||
|
||||
// authenticates user on login
|
||||
add_filter( 'authenticate', array( __CLASS__, 'authenticate_user_on_login' ), 999, 3);
|
||||
|
||||
// retrieve preferred user role for user
|
||||
add_filter('get_user_metadata', array(__CLASS__, 'maybe_filter_user_roles'), 10, 3);
|
||||
|
||||
// redirect to dashboard after login
|
||||
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ) );
|
||||
|
||||
// add role selector to login form
|
||||
add_action('login_form', array(__CLASS__, 'pick_role_on_login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect admin user to dashboard
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function login_redirect() {
|
||||
return admin_url('index.php') ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add role selector to login form
|
||||
*/
|
||||
public static function pick_role_on_login() {
|
||||
?>
|
||||
<p>
|
||||
<label for="user_role"><?php esc_html_e( 'Role' , 'wiaas'); ?><br />
|
||||
<select id="user_role" class="input" name="role">
|
||||
<option value="administrator"><?php esc_html_e('Administrator', 'wiaas') ?></option>
|
||||
<option value="supplier"><?php esc_html_e('Supplier', 'wiaas') ?></option>
|
||||
<option value="commercial_lead"><?php esc_html_e('Commercial Lead', 'wiaas') ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Authenticate current user based on roles assigned to organization
|
||||
*
|
||||
* @param int|false $user_id
|
||||
* @return int|false|WP_Error
|
||||
*/
|
||||
public static function authenticate_current_user($user_id) {
|
||||
// do nothing if user not authenticated, user is super admin or this is REST API request
|
||||
if (! $user_id || $user_id === self::SUPER_ADMIN_USER_ID) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
|
||||
|
||||
$role = $is_rest_api ?
|
||||
'customer' :
|
||||
get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
|
||||
|
||||
$result = self::_can_user_have_role($user_id, $role, $is_rest_api);
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate wiaas user on login based on roles assigned to organization
|
||||
*
|
||||
* @param WP_User $user
|
||||
* @return WP_User|WP_Error
|
||||
*/
|
||||
public static function authenticate_user_on_login($user) {
|
||||
// check if rest request
|
||||
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
|
||||
// do nothing if there is an error already,
|
||||
// user is super admin or
|
||||
// this is rest request
|
||||
if (is_wp_error($user) || $user->ID === 1 || $is_rest_api) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if (empty($_POST['role'])) {
|
||||
return new WP_Error('error', 'You must selected role to login!');
|
||||
}
|
||||
|
||||
// get selected role
|
||||
$requested_role = sanitize_key($_POST['role']);
|
||||
|
||||
// validate can user have requested role
|
||||
$result = self::_can_user_have_role($user->ID, $requested_role, false);
|
||||
|
||||
// if user organization has no requested role prevent access
|
||||
if (is_wp_error($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// remember role for user and continue
|
||||
update_user_meta($user->ID, '_wiaas_current_user_admin_role', $requested_role);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Filters user roles retrieval so that selected user role is retrieved for admin panel
|
||||
* and customer role is retrieved for JSON API request
|
||||
*
|
||||
* @param $null
|
||||
* @param int $user_id
|
||||
* @param string $meta_key
|
||||
* @return array|null
|
||||
*/
|
||||
public static function maybe_filter_user_roles($null, $user_id, $meta_key) {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
if ($user_id !== 0 && $user_id !== self::SUPER_ADMIN_USER_ID && $meta_key === $wpdb->get_blog_prefix() . 'capabilities') {
|
||||
|
||||
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
|
||||
|
||||
$role = $is_rest_api ?
|
||||
'customer' :
|
||||
get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
|
||||
|
||||
return array( array ( "$role" => true ));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PRIVATE
|
||||
|
||||
/**
|
||||
* Determines if user can have requested role based on his organization roles
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string $user_role
|
||||
* @param bool $is_rest_api
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
private static function _can_user_have_role($user_id, $user_role, $is_rest_api) {
|
||||
// check if role valid for access
|
||||
if (! wp_roles()->is_role($user_role)) {
|
||||
return new WP_Error('error', 'Role is not valid!');
|
||||
}
|
||||
|
||||
// only customer role can access API
|
||||
if ($is_rest_api && $user_role !== 'customer') {
|
||||
return new WP_Error('error', 'No access!');
|
||||
}
|
||||
|
||||
// customer role cannot access admin backend
|
||||
if (! $is_rest_api && $user_role === 'customer') {
|
||||
return new WP_Error('error', 'No access!');
|
||||
}
|
||||
|
||||
// import organization functions (during user authentication it is not yet loaded)
|
||||
require_once dirname( __FILE__ ) . '/user/wiaas-organization-functions.php';
|
||||
|
||||
// get user organization
|
||||
$organization_id = wiaas_get_user_organization_id($user_id);
|
||||
|
||||
// validate if user has organization
|
||||
if (empty( $organization_id)) {
|
||||
return new WP_Error('error', 'Account not completed!');
|
||||
}
|
||||
// get organization roles
|
||||
$roles = wiaas_get_organization_roles($organization_id);
|
||||
|
||||
// validate if user has organization roles
|
||||
if (!in_array($user_role, $roles)) {
|
||||
return new WP_Error( 'error', 'Your account is not authorized for requested role. Please contact us for help.' );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Authentication::init();
|
||||
@@ -12,6 +12,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
*/
|
||||
class Wiaas_Cart {
|
||||
|
||||
private static $cart_doc_types = array(
|
||||
'template_questionaire' => 'order_questionaire',
|
||||
'template_agreement' => 'order_agreement'
|
||||
);
|
||||
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
@@ -21,7 +26,82 @@ class Wiaas_Cart {
|
||||
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
$result = Wiaas_Document_Upload::upload_document_version();
|
||||
|
||||
// File upload failed
|
||||
if (is_wp_error($result)) {
|
||||
$code = $result->get_error_code();
|
||||
|
||||
if ($code === 'wiaas_upload_error_missing_file' || $code === 'wiaas_upload_error_invalid_extension') {
|
||||
wc_add_notice($result->get_error_message(), 'error');
|
||||
} else {
|
||||
wc_add_notice('File upload failed!', 'error');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// save uploaded cart documents info to cart item
|
||||
WC()->cart->cart_contents[ $package_item_key ]['_wiaas_documents'][$doc_type] = array(
|
||||
'version' => $result,
|
||||
'key' => wp_generate_uuid4(),
|
||||
);;
|
||||
|
||||
// persist changes
|
||||
WC()->cart->calculate_totals();
|
||||
|
||||
return true;
|
||||
|
||||
} catch( Exception $e) {
|
||||
wc_add_notice('Could not upload cart document!', 'error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,17 +122,34 @@ class Wiaas_Cart {
|
||||
public static function add_package_to_cart($package_id, $price_id, $addons_ids, $options_ids) {
|
||||
// try adding package to cart
|
||||
try {
|
||||
// Check if package is in cart
|
||||
if (self::_is_package_in_cart($package_id)) {
|
||||
wc_add_notice('Package already in cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if package exists
|
||||
$package = wc_get_product( $package_id );
|
||||
if (!$package) {
|
||||
wc_add_notice('Package does not exists!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check if package is available for adding to cart
|
||||
if (Wiaas_Package_Status::get_package_status($package_id) !== Wiaas_Package_Status::AVAILABLE){
|
||||
wc_add_notice('Package cannot be purchased at the moment', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve package country
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
// Retrieve package price
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
|
||||
// Retrieve package price
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Initialize additional cart item data for wiaas packages
|
||||
@@ -61,12 +158,14 @@ class Wiaas_Cart {
|
||||
'_wiaas_addon_items' => array(),
|
||||
'_wiaas_option_items' => array(),
|
||||
'_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);
|
||||
|
||||
if (!$cart_item_key) {
|
||||
wc_add_notice('Package could not be added to cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,8 +178,6 @@ class Wiaas_Cart {
|
||||
return true;
|
||||
|
||||
} catch( Exception $e) {
|
||||
|
||||
error_log($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -181,7 +278,7 @@ class Wiaas_Cart {
|
||||
* @param $cart_item
|
||||
* @param $order
|
||||
*
|
||||
* @return array
|
||||
* @return WC_Order_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'])) {
|
||||
@@ -224,6 +321,40 @@ class Wiaas_Cart {
|
||||
if (isset($cart_item['_wiaas_addon_for'])) {
|
||||
$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 +380,7 @@ class Wiaas_Cart {
|
||||
'_wiaas_option_group_name',
|
||||
'_wiaas_standard_package',
|
||||
'_wiaas_currency',
|
||||
'_wiaas_documents'
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -401,6 +533,103 @@ class Wiaas_Cart {
|
||||
|
||||
//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
|
||||
@@ -419,6 +648,10 @@ class Wiaas_Cart {
|
||||
$addon_items_keys = array();
|
||||
$option_items_keys = array();
|
||||
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
|
||||
// Try adding package addons to cart
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
//Check if addon package exists
|
||||
@@ -427,8 +660,13 @@ class Wiaas_Cart {
|
||||
throw new Exception( __( 'Sorry, additional package does not exist.', 'wiaas' ) );
|
||||
}
|
||||
|
||||
// Retrieve addon package price
|
||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $parent_item['data']);
|
||||
// Retrieve addon package price
|
||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price(
|
||||
$addon_package,
|
||||
$parent_item['data'],
|
||||
$customer_id,
|
||||
$commercial_lead_id
|
||||
);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Initialize additional cart item data for wiaas addon packages
|
||||
@@ -459,8 +697,12 @@ class Wiaas_Cart {
|
||||
throw new Exception( __( 'Sorry, option package does not exist.', 'wiaas' ) );
|
||||
}
|
||||
|
||||
// Retrieve option package price
|
||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $parent_item['data']);
|
||||
// Retrieve option package price
|
||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price(
|
||||
$option_package,
|
||||
$parent_item['data'],
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Retrieve option package group name
|
||||
@@ -491,6 +733,24 @@ class Wiaas_Cart {
|
||||
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_addon_items'] = $addon_items_keys;
|
||||
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_option_items'] = $option_items_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if package is added to cart
|
||||
* @param int $package_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function _is_package_in_cart($package_id) {
|
||||
$cart_item = WC()->cart->get_cart_contents();
|
||||
|
||||
foreach ($cart_item as $item) {
|
||||
if($item['product_id'] === $package_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Cart::init();
|
||||
@@ -2,6 +2,23 @@
|
||||
|
||||
class Wiaas_Checkout {
|
||||
|
||||
public static function init(){
|
||||
add_action( 'woocommerce_check_cart_items', array(__CLASS__, 'validate_wiaas_packages'));
|
||||
}
|
||||
|
||||
public static function validate_wiaas_packages(){
|
||||
//check if any package became invalid
|
||||
$items = WC()->cart->get_cart();
|
||||
foreach($items as $item) {
|
||||
$item_id = $item['data']->get_id();
|
||||
if (wc_pb_is_bundle_container_cart_item($item) &&
|
||||
(Wiaas_Package_Status::get_package_status($item_id) !== Wiaas_Package_Status::AVAILABLE)){
|
||||
wc_add_notice( 'Package ' . $item['data']->get_title() . ' cannot be purchased at the moment', 'error' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the order checkout.
|
||||
*
|
||||
@@ -12,49 +29,41 @@ class Wiaas_Checkout {
|
||||
public static function process_checkout($data) {
|
||||
try {
|
||||
|
||||
$customer = wp_get_current_user();
|
||||
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
|
||||
wc_set_time_limit( 0 );
|
||||
|
||||
$order_id = WC()->checkout()->create_order(array());
|
||||
do_action( 'woocommerce_before_checkout_process' );
|
||||
|
||||
// Check if cart empty before proceeding
|
||||
if (WC()->cart->is_empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_checkout_process' );
|
||||
|
||||
// Validate cart items before proceeding
|
||||
WC()->checkout()->check_cart_items();
|
||||
|
||||
// if something is wrong bail out
|
||||
if(wc_notice_count( 'error' ) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// try processing order
|
||||
$order_id = WC()->checkout()->create_order($data);
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
// set order currency
|
||||
$line_items = $order->get_items();
|
||||
foreach ($line_items as $line_item) {
|
||||
if (isset($line_item['wiaas_currency'])) {
|
||||
$order->set_currency($line_item['wiaas_currency']);
|
||||
break;
|
||||
}
|
||||
if ( is_wp_error( $order_id ) ) {
|
||||
throw new Exception( $order_id->get_error_message() );
|
||||
}
|
||||
|
||||
$delivery_address = Wiaas_Customer::get_customer_profile_address($customer->ID, $data['delivery_address_id']);
|
||||
$billing_address = Wiaas_Customer::get_customer_billing_address($customer->ID, $data['billing_address_id']);
|
||||
|
||||
if (isset($delivery_address)) {
|
||||
$order->set_shipping_city($delivery_address['city']);
|
||||
$order->set_shipping_country($delivery_address['country_name']);
|
||||
$order->set_shipping_address_1($delivery_address['detailed_address']);
|
||||
$order->set_shipping_postcode($delivery_address['zip_code']);
|
||||
$order->set_shipping_first_name($delivery_address['first_name']);
|
||||
$order->set_shipping_last_name($delivery_address['last_name']);
|
||||
if ( ! $order ) {
|
||||
throw new Exception( __( 'Unable to create order.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
if (isset($billing_address)) {
|
||||
$order->set_billing_city($billing_address['city']);
|
||||
$order->set_billing_country($billing_address['country_name']);
|
||||
$order->set_billing_address_1($billing_address['detailed_address']);
|
||||
$order->set_billing_postcode($billing_address['zip_code']);
|
||||
$order->set_billing_first_name($billing_address['first_name']);
|
||||
$order->set_billing_last_name($billing_address['last_name']);
|
||||
}
|
||||
self::_add_wiaas_checkout_data($order, $data);
|
||||
|
||||
Wiaas_Order::set_order_vat($order_id, $data['vat']);
|
||||
Wiaas_Order::set_order_company($order_id, $data['company_name']);
|
||||
Wiaas_Order::set_order_reference($order_id, $data['reference']);
|
||||
Wiaas_Order::set_order_tender($order_id, $data['tender']);
|
||||
|
||||
if (isset($data['project_id'])) {
|
||||
Wiaas_Order_Project::set_project_for_order($order_id, $data['project_id']);
|
||||
}
|
||||
do_action( 'woocommerce_checkout_order_processed', $order_id, array(), $order );
|
||||
|
||||
$order->payment_complete();
|
||||
|
||||
@@ -63,7 +72,37 @@ class Wiaas_Checkout {
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
wc_add_notice( $e->getMessage(), 'error' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional wiaas checkout info for order
|
||||
* @param $order
|
||||
* @param array $data
|
||||
*/
|
||||
private static function _add_wiaas_checkout_data($order, $data) {
|
||||
// save currency
|
||||
$line_items = $order->get_items();
|
||||
foreach ($line_items as $line_item) {
|
||||
if (isset($line_item['wiaas_currency'])) {
|
||||
$order->set_currency($line_item['wiaas_currency']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// save additional wiaas order info
|
||||
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
|
||||
Wiaas_Order::set_order_company($order->get_id(), $data['company_name']);
|
||||
Wiaas_Order::set_order_reference($order->get_id(), $data['reference']);
|
||||
Wiaas_Order::set_order_tender($order->get_id(), $data['tender']);
|
||||
|
||||
// add order to project
|
||||
if (isset($data['project_id'])) {
|
||||
Wiaas_Order_Project::set_project_for_order($order->get_id(), $data['project_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Checkout::init();
|
||||
|
||||
@@ -8,12 +8,19 @@ class Wiaas_DB_Update {
|
||||
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
|
||||
'20180801222206' => 'wiaas_db_update_setup_gravity',
|
||||
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
|
||||
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
|
||||
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
|
||||
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
|
||||
'20180826153509' => 'wiaas_create_broker_access_group',
|
||||
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
|
||||
'20180912101010' => 'wiaas_db_setup_default_cl'
|
||||
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
|
||||
'201810111644700' => 'wiaas_db_update_add_organization_info_ui_fields',
|
||||
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
|
||||
'201810171645700' => 'wiaas_db_update_create_default_roles',
|
||||
'201810171745700' => 'wiaas_db_import_aam_role_settings',
|
||||
'201810173045700' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
||||
'201810173145700' => 'wiaas_db_update_update_supplier_capabilities',
|
||||
'201810173245700' => 'wiaas_db_update_update_admin_capabilities',
|
||||
'201810173345700' => 'wiaas_create_role_access_groups'
|
||||
);
|
||||
|
||||
public static function execute() {
|
||||
|
||||
@@ -5,98 +5,21 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Wiaas Document types
|
||||
* Implements 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() {
|
||||
add_action( 'init', array( __CLASS__, 'register_wiaas_document_types' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' ),
|
||||
);
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document.php';
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'label' => __( 'Document types', 'wiaas' ),
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'wiaas_document_types' ),
|
||||
);
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-upload.php';
|
||||
|
||||
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) {
|
||||
wp_insert_term($available_doc_type['name'], 'wiaas_document_types', array(
|
||||
'slug' => $key
|
||||
));
|
||||
}
|
||||
require_once dirname( __FILE__ ) . '/document/wiaas-document-functions.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,6 @@ class Wiaas_Order {
|
||||
|
||||
// add only product lines that represent product bundles
|
||||
if (isset($item['wiaas_standard_package'])) {
|
||||
|
||||
# get payment type info
|
||||
$product_line['payment_type'] = $item['wiaas_payment_type'];
|
||||
$product_line['service_price'] = floatval($item['wiaas_services_extra']);
|
||||
@@ -362,34 +361,16 @@ class Wiaas_Order {
|
||||
* @param $request
|
||||
*/
|
||||
private static function _append_documents($data, $order, $request) {
|
||||
if (isset($request['id'])) {
|
||||
$data['documents'] = array();
|
||||
|
||||
//This requires _append_packages to be called before this method
|
||||
|
||||
foreach($data['line_items'] as $item){
|
||||
$product = wc_get_product($item['product_id']);
|
||||
|
||||
$product_documents = array();
|
||||
foreach ( $product->get_downloads() as $file_id => $file ) {
|
||||
$product_documents[] = array(
|
||||
'id' => $file_id,
|
||||
'name' => $file->get_name(),
|
||||
'extension' => $file->get_file_extension()
|
||||
);
|
||||
}
|
||||
// Go trough available line items and append documents for wiaas standard packages line items
|
||||
foreach ($data['line_items'] as $index => $product_line) {
|
||||
$order_item = $order->get_item($product_line['id']);
|
||||
|
||||
if (count($product_documents)){
|
||||
$data['documents'][] = array(
|
||||
'package' => array(
|
||||
'id' => $product->get_id(),
|
||||
'name' => $product->get_name()
|
||||
),
|
||||
'documents' => $product_documents
|
||||
);
|
||||
}
|
||||
if (wiaas_is_order_item__standard_package($order_item)) {
|
||||
$documents = wiaas_get_standard_package_order_item_documents($order, $product_line['id']);
|
||||
$data['line_items'][$index] ['documents'] = $documents;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -12,6 +12,7 @@ class Wiaas_Package {
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-option-groups.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-type.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-status.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/wiaas-package-functions.php';
|
||||
|
||||
@@ -54,15 +55,11 @@ class Wiaas_Package {
|
||||
*/
|
||||
private static function _append_documents_info($data, $package, $request) {
|
||||
|
||||
unset($data['downloads']);
|
||||
|
||||
$data['documents'] = array_map(function($download) {
|
||||
return array(
|
||||
'id' => $download->get_id(),
|
||||
'name' => $download->get_name(),
|
||||
'extension' => $download->get_file_extension(),
|
||||
);
|
||||
}, array_values($package->get_downloads()));
|
||||
$data['documents'] = array_map(function($doc) {
|
||||
unset($doc['url']);
|
||||
unset($doc['version']);
|
||||
return $doc;
|
||||
}, wiaas_get_standard_package_documents($package, true));
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -96,6 +93,9 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_additional_packages($data, $package, $request) {
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
|
||||
$data['additional_packages'] = array();
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
@@ -104,7 +104,7 @@ class Wiaas_Package {
|
||||
'id' => $addon->get_id(),
|
||||
'name' => $addon->get_name(),
|
||||
'description' => $addon->get_description(),
|
||||
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package),
|
||||
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package, $customer_id, $commercial_lead_id),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ class Wiaas_Package {
|
||||
'name' => $option_package->get_name(),
|
||||
'description' => $option_package->get_description(),
|
||||
'default' => $default_option_id === $option_package->get_id(),
|
||||
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package),
|
||||
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package, $customer_id, $commercial_lead_id),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,11 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_package_prices($data, $package, $request) {
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9,233 +9,240 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
*/
|
||||
class Wiaas_Pricing {
|
||||
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
|
||||
const COMMERCIAL_LEAD_NAME = 'Coor Service Management';
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-cl-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
|
||||
}
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
|
||||
}
|
||||
/**
|
||||
* Calculates total cost for product
|
||||
* @param WC_Product_Simple $product
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_product_total_cost($product) {
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
/**
|
||||
* Calculates total cost for product
|
||||
* @param $product
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_product_total_cost($product) {
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param WC_Product_Bundle $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
$total_cost_per_category = array();
|
||||
|
||||
$total_cost_per_category = array();
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
if (Wiaas_Product_Category::is_installation($product)) {
|
||||
$total_cost_per_category[$product_cat] = $total_cost_per_category[$product_cat] < $total_item_cost ?
|
||||
$total_item_cost :
|
||||
$total_cost_per_category[$product_cat];
|
||||
} else {
|
||||
$total_cost_per_category[$product_cat] += $total_item_cost;
|
||||
}
|
||||
}
|
||||
|
||||
if (Wiaas_Product_Category::is_installation($product)) {
|
||||
$total_cost_per_category[$product_cat] = $total_cost_per_category[$product_cat] < $total_item_cost ?
|
||||
$total_item_cost :
|
||||
$total_cost_per_category[$product_cat];
|
||||
} else {
|
||||
$total_cost_per_category[$product_cat] += $total_item_cost;
|
||||
}
|
||||
}
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
/**
|
||||
* Calculates customer prices for wiaas standard package
|
||||
* @param WC_Product_Bundle $package
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id) {
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas standard package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_standard_package_customer_prices($package) {
|
||||
return self::_get_package_customer_prices(
|
||||
$package,
|
||||
(100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100, // commercial lead commission
|
||||
self::get_package_total_cost($package), // total cost of package items
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100;
|
||||
$total_cost = self::get_package_total_cost($package);
|
||||
}
|
||||
|
||||
$customer_package_prices = array();
|
||||
/**
|
||||
* Calculates customer prices for wiaas addon package
|
||||
*
|
||||
* @param WC_Product_Bundle $addon_package
|
||||
* @param WC_Product_Bundle $parent_package
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_addon_package_customer_price($addon_package, $parent_package, $customer_id, $commercial_lead_id) {
|
||||
|
||||
foreach ($package_prices as $type => $package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$package_price,
|
||||
$cl_commision,
|
||||
$total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
|
||||
return $customer_package_prices;
|
||||
return self::_get_package_customer_prices(
|
||||
$addon_package,
|
||||
$parent_cl_commision, // commercial lead commission of parent package
|
||||
$parent_total_cost, // total cost of parent package items
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Calculates customer prices for wiaas option package
|
||||
*
|
||||
* @param WC_Product_Bundle $option_package
|
||||
* @param WC_Product_Bundle $parent_package
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_option_package_customer_price($option_package, $parent_package, $customer_id, $commercial_lead_id) {
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas addon package
|
||||
* @param $addon_package
|
||||
* @param $parent_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_addon_package_customer_price($addon_package, $parent_package) {
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
$addon_package_prices = Wiaas_Package_Pricing::get_package_prices($addon_package);
|
||||
return self::_get_package_customer_prices(
|
||||
$option_package,
|
||||
$parent_cl_commision, // commercial lead commission of parent package
|
||||
$parent_total_cost, // total cost of parent package items
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
}
|
||||
|
||||
$customer_package_prices = array();
|
||||
|
||||
foreach ($addon_package_prices as $type => $addon_package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$addon_package_price,
|
||||
$parent_cl_commision,
|
||||
$parent_total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas option package
|
||||
* @param $option_package
|
||||
* @param $parent_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_option_package_customer_price($option_package, $parent_package) {
|
||||
// PRIVATE SECTION
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
$option_package_prices = Wiaas_Package_Pricing::get_package_prices($option_package);
|
||||
|
||||
$customer_package_prices = array();
|
||||
/**
|
||||
* Calculates customer prices for all package payment types
|
||||
*
|
||||
* @param WC_Product_Bundle $package
|
||||
* @param int $cl_commision
|
||||
* @param int $total_cost
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_prices($package, $cl_commision, $total_cost, $customer_id, $commercial_lead_id) {
|
||||
$is_same_company_as_cl = $customer_id === $commercial_lead_id;
|
||||
|
||||
foreach ($option_package_prices as $type => $option_package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$option_package_price,
|
||||
$parent_cl_commision,
|
||||
$parent_total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
$customer_package_prices = array();
|
||||
|
||||
// PRIVATE
|
||||
foreach ($package_prices as $type => $package_price) {
|
||||
$cl_package_extras = Wiaas_Package_CL_Pricing::get_extras_for_customer(
|
||||
$commercial_lead_id,
|
||||
$package_price['id'],
|
||||
$package->get_id(),
|
||||
$customer_id
|
||||
);
|
||||
|
||||
/**
|
||||
* Determines if customer and commercial lead are in the same company
|
||||
* For now this is hardcoded and we have only one CL
|
||||
*
|
||||
* TODO: This should be changed after customer leads are handled
|
||||
* @return bool
|
||||
*/
|
||||
private static function _is_customer_same_company_as_cl() {
|
||||
$current_user = wp_get_current_user();
|
||||
$user_organization = Wiaas_User_Organization::get_user_organization($current_user->ID);
|
||||
$is_same_company_as_cl = $user_organization->name === self::COMMERCIAL_LEAD_NAME;
|
||||
// commercial lead did not set prices for this payment type so it must not be visible for customer
|
||||
if (empty($cl_package_extras)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $is_same_company_as_cl;
|
||||
}
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$package_price,
|
||||
$total_cost,
|
||||
$cl_package_extras,
|
||||
$cl_commision,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas package
|
||||
* @param $package_price
|
||||
* @param $cl_commision
|
||||
* @param $total_cost
|
||||
* @param $is_same_company_as_cl
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_price($package_price, $cl_commision, $total_cost, $is_same_company_as_cl) {
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
$package_total_margin = wiaas_get_price_margin(
|
||||
$package_price['minimal_fixed_price'],
|
||||
$package_price['principal_amount'],
|
||||
$total_cost);
|
||||
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
|
||||
/**
|
||||
* Calculates customer price for single package payment type
|
||||
*
|
||||
* @param array $package_price
|
||||
* @param int $total_cost
|
||||
* @param array $cl_package_extras
|
||||
* @param int $cl_commision
|
||||
* @param bool $is_same_company_as_cl
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_price($package_price, $total_cost, $cl_package_extras, $cl_commision, $is_same_company_as_cl) {
|
||||
$package_total_margin = wiaas_get_price_margin(
|
||||
$package_price['minimal_fixed_price'],
|
||||
$package_price['principal_amount'],
|
||||
$total_cost);
|
||||
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
|
||||
|
||||
$cl_package_prices = array(
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
$customer_package_price = array(
|
||||
'id' => $package_price['id'],
|
||||
'payment_type' => $package_price['payment_type'],
|
||||
'max_contract_period' => $package_price['max_contract_period'],
|
||||
'package_pay_period' => $package_price['package_pay_period'],
|
||||
'period_unit' => $package_price['period_unit'],
|
||||
'services_contract_period' => $package_price['services_contract_period'],
|
||||
|
||||
$interest_rate = self::INTEREST_RATE;
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
|
||||
$customer_price = array(
|
||||
'id' => $package_price['id'],
|
||||
'payment_type' => $package_price['payment_type'],
|
||||
'max_contract_period' => $package_price['max_contract_period'],
|
||||
'package_pay_period' => $package_price['package_pay_period'],
|
||||
'period_unit' => $package_price['period_unit'],
|
||||
'services_contract_period' => $package_price['services_contract_period'],
|
||||
if ($is_same_company_as_cl) {
|
||||
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
if ($package_price['package_pay_period'] > 0) {
|
||||
$customer_package_price['fixed_extra'] = $package_price['minimal_fixed_price'];
|
||||
$customer_package_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
$cl_margin,
|
||||
self::INTEREST_RATE);
|
||||
} else {
|
||||
$customer_package_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
|
||||
$customer_package_price['recurrent_extra'] = 0;
|
||||
}
|
||||
$customer_package_price['services_extra'] = $package_price['minimal_services_price'];
|
||||
|
||||
if ($is_same_company_as_cl) {
|
||||
} else {
|
||||
|
||||
if ($package_price['package_pay_period'] > 0) {
|
||||
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'];
|
||||
$customer_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
$cl_margin,
|
||||
$interest_rate);
|
||||
} else {
|
||||
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
|
||||
$customer_price['recurrent_extra'] = 0;
|
||||
}
|
||||
$customer_price['services_extra'] = $package_price['minimal_services_price'];
|
||||
$customer_package_price['fixed_extra'] = $cl_package_extras['fixed'] + $package_price['minimal_fixed_price'];
|
||||
$customer_package_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
|
||||
$cl_package_extras['recurrent'] + wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
0,
|
||||
self::INTEREST_RATE)
|
||||
: 0;
|
||||
$customer_package_price['services_extra'] = $cl_package_extras['services'] + $package_price['minimal_services_price'];
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$customer_price['fixed_extra'] = $cl_package_prices['fixed_extra'] + $package_price['minimal_fixed_price'];
|
||||
$customer_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
|
||||
$cl_package_prices['recurrent_extra'] + wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
0,
|
||||
$interest_rate)
|
||||
: 0;
|
||||
$customer_price['services_extra'] = $cl_package_prices['services_extra'] + $package_price['minimal_services_price'];
|
||||
}
|
||||
|
||||
return $customer_price;
|
||||
}
|
||||
return $customer_package_price;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Pricing::init();
|
||||
@@ -4,6 +4,31 @@ class Wiaas_Product {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
|
||||
|
||||
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'define_product_capabilities'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define capabilities for editing products so we can easily control read/edit/create access for them
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function define_product_capabilities($args) {
|
||||
|
||||
$args['capabilities'] = array(
|
||||
'edit_post' => 'edit_product',
|
||||
'read_post' => 'read_product',
|
||||
'delete_post' => 'delete_product',
|
||||
'edit_posts' => 'edit_products',
|
||||
'edit_others_posts' => 'edit_others_products',
|
||||
'publish_posts' => 'publish_products',
|
||||
'read_private_posts' => 'read_private_products',
|
||||
'create_posts' => 'create_products', // use `create_products` instead of default `edit_products`
|
||||
);
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
75
backend/app/plugins/wiaas/includes/class-wiaas-shop.php
Normal file
75
backend/app/plugins/wiaas/includes/class-wiaas-shop.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Shop {
|
||||
|
||||
public static function init() {
|
||||
|
||||
// registers special prices taxonomy that will enable package search based on
|
||||
// set and visible price types (default and customer specific ones)
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_prices_taxonomy'));
|
||||
|
||||
// update prices search terms for package after prices extras have been updated
|
||||
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register special prices taxonomy to enable search of packages by prices inside every shop
|
||||
*/
|
||||
public static function register_prices_taxonomy() {
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => false,
|
||||
'public' => true,
|
||||
'capabilities' => array(
|
||||
'manage_terms' => 'manage_wiaas_package_price_terms',
|
||||
'edit_terms' => 'edit_wiaas_package_price_terms',
|
||||
'delete_terms' => 'delete_wiaas_package_price_terms',
|
||||
'assign_terms' => 'assign_wiaas_package_price_terms',
|
||||
),
|
||||
);
|
||||
|
||||
register_taxonomy( '_wiaas_shop_prices', array( 'product' ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Relate pricing search terms to package so customer can retrieve packages with default or
|
||||
* their own specific prices.
|
||||
* (ex: Package which will be hidden fro Customer 1 because default price
|
||||
* is hidden can be visible for Customer 2 because specific prices are set for that customer)
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param int $package_id
|
||||
* @param array $cl_extras {
|
||||
* $extra_price_payment_type => {
|
||||
* @type bool visible Indicates if payment type is visible to customer
|
||||
* }
|
||||
* }
|
||||
* @param array $old_cl_extras {
|
||||
* $extra_price_payment_type => {
|
||||
* @type bool visible Indicates if payment type is visible to customer
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public static function update_package_prices_search_terms($owner_id, $package_id, $cl_extras, $old_cl_extras) {
|
||||
// remove pricing terms for previous prices
|
||||
if (! empty($old_cl_extras)) {
|
||||
|
||||
$old_visible_price_types = array_keys(wp_list_filter($old_cl_extras, array( 'visible' => true )));
|
||||
|
||||
$old_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $old_visible_price_types);
|
||||
|
||||
wp_remove_object_terms($package_id, $old_terms_names, '_wiaas_shop_prices');
|
||||
}
|
||||
|
||||
// get visible price types set by shop owner (commercial lead)
|
||||
$visible_price_types = array_keys(wp_list_filter($cl_extras, array('visible' => true)));
|
||||
|
||||
$new_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $visible_price_types);
|
||||
|
||||
// create term for every visible pricing type and link them to package so package can be queried
|
||||
wp_set_object_terms($package_id, $new_terms_names, '_wiaas_shop_prices');
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Shop::init();
|
||||
@@ -21,6 +21,7 @@ class Wiaas_User {
|
||||
public static function load_user_organization() {
|
||||
if (class_exists('WP_User_Taxonomy')) {
|
||||
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
|
||||
require_once dirname( __FILE__ ) . '/user/wiaas-organization-functions.php';
|
||||
|
||||
new Wiaas_User_Organization();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ class Wiaas_CLI_Update_DB_Command {
|
||||
$wpdb->hide_errors();
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-db-update.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-functions.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-general.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-roles.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-ui-fields.php';
|
||||
|
||||
$pending_db_updates = Wiaas_DB_Update::get_pending_db_updates();
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,90 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbe558ba265c",
|
||||
"title": "Organization Info",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bbe5c0d1f1a7",
|
||||
"label": "Phone",
|
||||
"name": "_wiaas_organization_phone",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbe5c291f1a8",
|
||||
"label": "VAT Code",
|
||||
"name": "_wiaas_organization_vat",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbe559d66d17",
|
||||
"label": "Roles",
|
||||
"name": "_wiaas_organization_roles",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"administrator": "Administrator",
|
||||
"supplier": "Supplier",
|
||||
"commercial_lead": "Commercial Lead",
|
||||
"customer": "Customer"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 1,
|
||||
"ui": 1,
|
||||
"ajax": 1,
|
||||
"return_format": "label",
|
||||
"placeholder": ""
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "taxonomy",
|
||||
"operator": "==",
|
||||
"value": "wiaas-user-organization"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "normal",
|
||||
"style": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "field",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,52 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbce9f38f149",
|
||||
"title": "User Organization",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bbe54366aac1",
|
||||
"label": "Organization",
|
||||
"name": "_wiaas_organization_id",
|
||||
"type": "taxonomy",
|
||||
"instructions": "Select Organization for user",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "wiaas-user-organization",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "user_form",
|
||||
"operator": "==",
|
||||
"value": "edit"
|
||||
},
|
||||
{
|
||||
"param": "current_user_role",
|
||||
"operator": "==",
|
||||
"value": "administrator"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "normal",
|
||||
"style": "seamless",
|
||||
"label_placement": "left",
|
||||
"instruction_placement": "field",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Wiaas DB updates
|
||||
* General Wiaas DB updates
|
||||
*
|
||||
* Functions for updating database to latest version
|
||||
* General functions for updating wiaas database to latest version
|
||||
*/
|
||||
|
||||
|
||||
@@ -78,16 +78,6 @@ function wiaas_db_update_add_delivery_process_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() {
|
||||
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
||||
|
||||
@@ -123,6 +113,16 @@ function wiaas_db_setup_exclusive_taxonomies() {
|
||||
));
|
||||
}
|
||||
|
||||
function wiaas_db_setup_default_cl() {
|
||||
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,176 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Roles Wiaas DB updates
|
||||
*
|
||||
* Functions for updating wiaas roles in database
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
function wiaas_db_update_create_default_roles() {
|
||||
$roles = array(
|
||||
'customer', // this role will be created by woocommerce so we do not have to create it here
|
||||
'supplier',
|
||||
'commercial_lead'
|
||||
);
|
||||
|
||||
// remove wordpress default roles
|
||||
remove_role('author');
|
||||
remove_role('contributor');
|
||||
remove_role('editor');
|
||||
remove_role('subscriber');
|
||||
|
||||
// remove woocoommerce shop manager role
|
||||
remove_role('shop_manager');
|
||||
|
||||
// Dummy gettext calls to get strings in the catalog.
|
||||
/* translators: user role */
|
||||
_x( 'Supplier', 'User role', 'wiaas' );
|
||||
/* translators: user role */
|
||||
_x( 'Commercial Lead', 'User role', 'wiaas' );
|
||||
|
||||
// Add wiaas roles
|
||||
add_role(
|
||||
'commercial_lead',
|
||||
'Commercial Lead',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'supplier',
|
||||
'Supplier',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'user',
|
||||
'User',
|
||||
array(
|
||||
'read' => true
|
||||
)
|
||||
);
|
||||
|
||||
// set default wiaas role
|
||||
update_option('default_role', 'user');
|
||||
|
||||
// capabilities
|
||||
|
||||
$capabilities = array();
|
||||
|
||||
$capability_types = array( 'wiaas_doc' );
|
||||
|
||||
foreach ( $capability_types as $capability_type ) {
|
||||
|
||||
$capabilities[ $capability_type ] = array(
|
||||
// Post type.
|
||||
"edit_{$capability_type}",
|
||||
"read_{$capability_type}",
|
||||
"delete_{$capability_type}",
|
||||
"edit_{$capability_type}s",
|
||||
"edit_others_{$capability_type}s",
|
||||
"publish_{$capability_type}s",
|
||||
"read_private_{$capability_type}s",
|
||||
"delete_{$capability_type}s",
|
||||
"delete_private_{$capability_type}s",
|
||||
"delete_published_{$capability_type}s",
|
||||
"delete_others_{$capability_type}s",
|
||||
"edit_private_{$capability_type}s",
|
||||
"edit_published_{$capability_type}s",
|
||||
|
||||
// Terms.
|
||||
"manage_{$capability_type}_terms",
|
||||
"edit_{$capability_type}_terms",
|
||||
"delete_{$capability_type}_terms",
|
||||
"assign_{$capability_type}_terms",
|
||||
);
|
||||
}
|
||||
|
||||
foreach ( $capabilities as $cap_group ) {
|
||||
foreach ( $cap_group as $cap ) {
|
||||
wp_roles()->add_cap( 'administrator', $cap );
|
||||
wp_roles()->add_cap( 'commercial_lead', $cap );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function wiaas_db_import_aam_role_settings() {
|
||||
// update role settings that are imported
|
||||
$content = file_get_contents( dirname( __FILE__ ) . '/data/aam-settings.json' );
|
||||
|
||||
$importer = new AAM_Core_Importer($content);
|
||||
|
||||
$importer->run();
|
||||
|
||||
// update toolbar settins manually since it does not get imported
|
||||
update_option('aam_toolbar_default', array (
|
||||
'about' => '1',
|
||||
'toolbar-wp-logo' => '1',
|
||||
'wporg' => '1',
|
||||
'documentation' => '1',
|
||||
'support-forums' => '1',
|
||||
'feedback' => '1',
|
||||
'toolbar-site-name' => '0',
|
||||
'view-site' => '1',
|
||||
'view-store' => '1',
|
||||
'toolbar-updates' => '1',
|
||||
'toolbar-comments' => '1',
|
||||
'toolbar-new-content' => '1',
|
||||
'new-post' => '1',
|
||||
'new-media' => '1',
|
||||
'new-page' => '1',
|
||||
'new-product' => '1',
|
||||
'new-shop_order' => '1',
|
||||
'new-shop_coupon' => '1',
|
||||
'new-wiaas_doc' => '1',
|
||||
'new-user' => '1',
|
||||
'gravityforms-new-form' => '1',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wiaas_db_update_update_commercial_lead_capabilities() {
|
||||
// add commercial lead specific roles
|
||||
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_products' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'view_admin_dashboard' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'read' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'upload_files' );
|
||||
|
||||
wp_roles()->add_cap( 'commercial_lead', 'edit_products' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'edit_others_products' );
|
||||
}
|
||||
|
||||
function wiaas_db_update_update_supplier_capabilities() {
|
||||
// add supplier specific roles
|
||||
wp_roles()->add_cap( 'supplier', 'view_admin_dashboard' );
|
||||
wp_roles()->add_cap( 'supplier', 'read' );
|
||||
}
|
||||
|
||||
function wiaas_db_update_update_admin_capabilities() {
|
||||
wp_roles()->add_cap( 'administrator', 'create_products' );
|
||||
}
|
||||
|
||||
|
||||
function wiaas_create_role_access_groups() {
|
||||
Groups_Group::create(array(
|
||||
'name' => 'admin',
|
||||
));
|
||||
|
||||
Groups_Group::create(array(
|
||||
'name' => 'commercial_lead',
|
||||
));
|
||||
|
||||
Groups_Group::create(array(
|
||||
'name' => 'supplier',
|
||||
));
|
||||
|
||||
Groups_Group::create(array(
|
||||
'name' => 'customer',
|
||||
));
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
function wiaas_db_update_add_organization_info_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-organization-info.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_user_organization_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-user-organization.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?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 ( isset($_GET['wiaasdoc']) ) {
|
||||
add_action( 'init', array( __CLASS__, 'admin_download' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Since only REST api uses JWT Authentication this endpoint will work only for users
|
||||
* that are logged in directly to wordpress
|
||||
*/
|
||||
public static function admin_download() {
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$document_id = (int)$_GET['wiaasdoc'];
|
||||
if ($document_id <= 0) {
|
||||
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$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' ), array( 'response' => 404 ) );
|
||||
}
|
||||
|
||||
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' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$item = $order->get_item($item_id);
|
||||
if (!$item) {
|
||||
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$item_documents = wiaas_get_standard_package_order_item_documents($order, $item_id);
|
||||
|
||||
$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' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$file_path = wiaas_get_document_version_path($order_document['version']);
|
||||
|
||||
if (!file_exists($file_path)) {
|
||||
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
|
||||
}
|
||||
|
||||
WC_Download_Handler::download_file_force(
|
||||
$file_path,
|
||||
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$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' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$cart_document = $item_documents[$type];
|
||||
if ($cart_document['key'] !== $document_key) {
|
||||
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$file_path = wiaas_get_document_version_path($cart_document['version']);
|
||||
|
||||
if (!file_exists($file_path)) {
|
||||
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
|
||||
}
|
||||
|
||||
WC_Download_Handler::download_file_force(
|
||||
$file_path,
|
||||
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_error_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_extension', '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,412 @@
|
||||
<?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' => 'wiaas_doc',
|
||||
'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' ),
|
||||
'capabilities' => array(
|
||||
'manage_terms' => 'manage_wiaas_doc_terms',
|
||||
'edit_terms' => 'edit_wiaas_doc_terms',
|
||||
'delete_terms' => 'delete_wiaas_doc_terms',
|
||||
'assign_terms' => 'assign_wiaas_doc_terms',
|
||||
),
|
||||
);
|
||||
|
||||
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 standard 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_standard_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 standard package item
|
||||
*
|
||||
* @param WC_Order $order
|
||||
* @param int $package_item_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_standard_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();
|
||||
}
|
||||
|
||||
$available_terms = array();
|
||||
|
||||
foreach ($all_terms as $term) {
|
||||
if (self::is_order_project_available($term->term_id)) {
|
||||
$available_terms[] = array(
|
||||
|
||||
@@ -49,6 +49,16 @@ class Wiaas_Package_Addon {
|
||||
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
|
||||
* @param $package
|
||||
|
||||
@@ -81,6 +81,24 @@ class Wiaas_Package_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
|
||||
* @param $package
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class Wiaas_Package_Status
|
||||
*/
|
||||
|
||||
|
||||
class Wiaas_Package_Status {
|
||||
|
||||
const AVAILABLE = 'available';
|
||||
const INVALID_MARGIN = 'margin_exceeded';
|
||||
const INVALID_TEMPLATE = 'invalid_template';
|
||||
|
||||
public static function init() {
|
||||
add_action('init', array( __CLASS__, 'register_package_status_taxonomy' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register wiaas package status taxonomy
|
||||
*/
|
||||
public static function register_package_status_taxonomy() {
|
||||
|
||||
$labels = array(
|
||||
'name' => _x( 'Package status', 'taxonomy general name', 'wiaas' ),
|
||||
'singular_name' => _x( 'Package status', 'taxonomy singular name', 'wiaas' ),
|
||||
'search_items' => __( 'Search Package statuses', 'wiaas' ),
|
||||
'all_items' => __( 'All Package statuses', 'wiaas' ),
|
||||
'parent_item' => __( 'Parent Package status', 'wiaas' ),
|
||||
'parent_item_colon' => __( 'Parent Package status:', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit Package status', 'wiaas' ),
|
||||
'update_item' => __( 'Update Package status', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add New Package status', 'wiaas' ),
|
||||
'new_item_name' => __( 'New Package status Name', 'wiaas' ),
|
||||
'menu_name' => __( 'Package status', 'wiaas' ),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'labels' => $labels,
|
||||
'show_ui' => false,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'package_status' ),
|
||||
);
|
||||
|
||||
register_taxonomy( 'package_status', array( 'product' ), $args );
|
||||
|
||||
|
||||
// Register available package statuses
|
||||
|
||||
$statuses = [self::AVAILABLE, self::INVALID_MARGIN, self::INVALID_TEMPLATE];
|
||||
|
||||
foreach ($statuses as $status) {
|
||||
wp_insert_term($status, 'package_status');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve available wiaas package statuses
|
||||
* @return array
|
||||
*/
|
||||
public static function get_available_package_statuses() {
|
||||
$statuses = get_terms( array(
|
||||
'taxonomy' => 'package_status',
|
||||
'hide_empty' => false,
|
||||
) );
|
||||
|
||||
return array_map(function($status) {
|
||||
return $status->name;
|
||||
}, $statuses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve package status for provided package id
|
||||
* @param $package_id
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function get_package_status($package_id) {
|
||||
$terms = wp_get_object_terms($package_id, 'package_status');
|
||||
$package_status = isset($terms[0]) ? $terms[0]->name : null;
|
||||
return $package_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set package status for provided package id
|
||||
* @param $package_id
|
||||
* @param $status
|
||||
*/
|
||||
public static function set_package_status($package_id, $status) {
|
||||
|
||||
wp_delete_object_term_relationships( $package_id, 'package_status' );
|
||||
|
||||
if (isset($status)) {
|
||||
wp_set_object_terms($package_id, $status, 'package_status', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Status::init();
|
||||
@@ -88,4 +88,14 @@ function wiaas_get_cart_item_addons($cart_item) {
|
||||
}
|
||||
|
||||
return $addon_cart_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if order item is wiaas standard package
|
||||
* @param WC_Order_Item $item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function wiaas_is_order_item__standard_package($item) {
|
||||
return isset($item['wiaas_standard_package']);
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handles logic for setting and retrieving commercial lead extra prices
|
||||
*
|
||||
* Class Wiaas_Package_CL_Pricing
|
||||
*/
|
||||
class Wiaas_Package_CL_Pricing {
|
||||
|
||||
/**
|
||||
* Sets package extra prices
|
||||
*
|
||||
* @param int $owner_id ID of the shop owner organization who set extra prices
|
||||
* @param int $package_id
|
||||
* @param array $cl_extras
|
||||
*/
|
||||
public static function set_extras($owner_id, $package_id, $cl_extras) {
|
||||
|
||||
foreach ($cl_extras as $extra_type => $cl_extra) {
|
||||
unset($cl_extra['type']);
|
||||
unset($cl_extra['customer']);
|
||||
|
||||
$cl_extras[$extra_type] = $cl_extra;
|
||||
}
|
||||
|
||||
$old_extras = self::get_extras($owner_id, $package_id);
|
||||
|
||||
// Persist package price extras
|
||||
update_term_meta(
|
||||
$owner_id,
|
||||
'_wiaas_cm_extras_'.$package_id,
|
||||
$cl_extras);
|
||||
|
||||
do_action('wiaas_package_prices_extras_set', $owner_id, $package_id, $cl_extras, $old_extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves package catalogue extra prices
|
||||
*
|
||||
* @param int $owner_id ID of the shop owner organization who set extra prices
|
||||
* @param int $package_id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_extras($owner_id, $package_id) {
|
||||
$cl_extras = get_term_meta(
|
||||
$owner_id,
|
||||
'_wiaas_cm_extras_'.$package_id,
|
||||
true);
|
||||
|
||||
return is_array($cl_extras) ? $cl_extras : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve catalogue package extra prices for provided customer
|
||||
*
|
||||
* If customer specific prices are set for the package, only those will be retrieved
|
||||
* otherwise deafult prices exras will be retrieved
|
||||
*
|
||||
* @param int $owner_id ID of the shop owner organization who set extra prices
|
||||
* @param string $pay_type Payment type for the pacakge
|
||||
* @param int $package_id ID of the package
|
||||
* @param int $customer_id ID of the customer
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_extras_for_customer($owner_id, $pay_type, $package_id, $customer_id) {
|
||||
$cl_extras = self::get_extras($owner_id, $package_id);
|
||||
|
||||
if (! empty($cl_extras)) {
|
||||
// if customer specific prices are set for this package use only them
|
||||
// else use default prices set for this package
|
||||
if (self::_customer_specific_prices_exist($cl_extras, $customer_id)) {
|
||||
$cl_pay_type = $pay_type . '_customer_' . $customer_id;
|
||||
} else {
|
||||
$cl_pay_type = $pay_type . '_default';
|
||||
}
|
||||
|
||||
$cl_pay_type_extras = $cl_extras[$cl_pay_type];
|
||||
|
||||
// if commercial lead has default price for this package then use it
|
||||
if (! empty($cl_pay_type_extras) && $cl_pay_type_extras['visible']) {
|
||||
|
||||
return array(
|
||||
'fixed' => floatval($cl_pay_type_extras['fixed']),
|
||||
'services' => floatval($cl_pay_type_extras['services']),
|
||||
'recurrent' => floatval($cl_pay_type_extras['recurrent'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// there are no prices set for this payment type
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static function _customer_specific_prices_exist($cl_extras, $customer_id) {
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
$cl_customer_pay_types = array();
|
||||
foreach ($pay_types as $pay_type) {
|
||||
$cl_customer_pay_types[] = $pay_type.'_customer_'.$customer_id;
|
||||
}
|
||||
|
||||
foreach ($cl_extras as $cl_pay_type => $data) {
|
||||
if (in_array($cl_pay_type, $cl_customer_pay_types)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,8 @@ class Wiaas_Package_Pricing {
|
||||
public static function init() {
|
||||
|
||||
add_filter('woocommerce_bundle_price_html', array( __CLASS__, 'get_package_price_html' ), 10, 2);
|
||||
|
||||
add_action('woocommerce_update_product', array(__CLASS__, 'on_product_update' ), 10, 1 );
|
||||
}
|
||||
|
||||
public static function get_package_price_html($price_html, $package) {
|
||||
@@ -101,21 +103,46 @@ class Wiaas_Package_Pricing {
|
||||
return self::_get_package_pricing_commision($package);
|
||||
}
|
||||
|
||||
public static function get_package_max_cost_margin($package){
|
||||
return self::_get_package_max_cost_margin($package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist payment prices configuration for package
|
||||
* @param $package
|
||||
* @param $pricing_rules
|
||||
*/
|
||||
public static function set_package_prices($package, $pricing_rules, $commision) {
|
||||
public static function set_package_prices($package, $pricing_rules, $commision, $max_cost_margin) {
|
||||
if ( isset( $pricing_rules ) ) {
|
||||
$package->update_meta_data( '_wiaas_pricing_rules', $pricing_rules );
|
||||
$package->update_meta_data('_package_pricing_commision', $commision, true);
|
||||
$package->update_meta_data('_package_max_cost_margin', $max_cost_margin, true);
|
||||
} else {
|
||||
$package->delete_meta_data( '_wiaas_pricing_rules' );
|
||||
}
|
||||
$package->save_meta_data();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes when woocommerce product is updated
|
||||
*/
|
||||
public static function on_product_update($product_id) {
|
||||
$product = wc_get_product($product_id);
|
||||
|
||||
if ($product->get_type() === WC_Product_Simple::get_type()){
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
$packages_containing_updated_product = wc_pb_get_bundled_product_map( $product );
|
||||
|
||||
foreach($packages_containing_updated_product as $index => $package_id){
|
||||
$package = new WC_Product_Bundle($package_id);
|
||||
self::_validate_package($package);
|
||||
}
|
||||
}else if ($product->get_type() === WC_Product_Bundle::get_type()){
|
||||
self::_validate_package($product);
|
||||
}
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
private static function _get_package_prices($package) {
|
||||
@@ -140,6 +167,16 @@ class Wiaas_Package_Pricing {
|
||||
'principal_amount' => floatval($pricing_rule['principal_amount']),
|
||||
'minimal_services_price' => floatval($pricing_rule['minimal_services_price']),
|
||||
);
|
||||
|
||||
$minimal_recurrent_price = $prices[$type]['minimal_services_price'];
|
||||
if ($prices[$type]['principal_amount'] > 0 && $prices[$type]['package_pay_period'] > 0) {
|
||||
$minimal_recurrent_price += wiaas_PMT(
|
||||
Wiaas_Pricing::INTEREST_RATE,
|
||||
$prices[$type]['package_pay_period'],
|
||||
$prices[$type]['principal_amount']);
|
||||
}
|
||||
|
||||
$prices[$type]['minimal_recurrent_price'] = round($minimal_recurrent_price);
|
||||
}
|
||||
|
||||
return $prices;
|
||||
@@ -154,6 +191,26 @@ class Wiaas_Package_Pricing {
|
||||
|
||||
return (float) $commision;
|
||||
}
|
||||
|
||||
private static function _get_package_max_cost_margin($package) {
|
||||
$max_cost_margin = $package->get_meta( '_package_max_cost_margin', true);
|
||||
|
||||
if (!isset($max_cost_margin) || $max_cost_margin === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (float) $max_cost_margin;
|
||||
}
|
||||
|
||||
private static function _validate_package($package){
|
||||
$package_total_cost = Wiaas_Pricing::get_package_total_cost($package);
|
||||
$package_max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
|
||||
if (($package_max_cost_margin != 0) && ($package_total_cost > $package_max_cost_margin)){
|
||||
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::INVALID_MARGIN);
|
||||
}else{
|
||||
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::AVAILABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_Pricing::init();
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Wiaas_Product_Supplier {
|
||||
public static function init() {
|
||||
|
||||
add_action('init', array(__CLASS__, 'register_supplier_taxonomy'));
|
||||
add_action('created_' . 'wiaas-user-organization', array(__CLASS__, 'on_organization_added'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register wiaas template category taxonomy
|
||||
*/
|
||||
public static function register_supplier_taxonomy() {
|
||||
|
||||
$labels = array(
|
||||
'name' => _x('Supplier', 'taxonomy general name', 'wiaas'),
|
||||
'singular_name' => _x('Supplier', 'taxonomy singular name', 'wiaas'),
|
||||
'search_items' => __('Search Suppliers', 'wiaas'),
|
||||
'all_items' => __('All Suppliers', 'wiaas'),
|
||||
'parent_item' => __('Parent Supplier', 'wiaas'),
|
||||
'parent_item_colon' => __('Parent Supplier', 'wiaas'),
|
||||
'edit_item' => __('Edit Supplier', 'wiaas'),
|
||||
'update_item' => __('Update Supplier', 'wiaas'),
|
||||
'add_new_item' => __('Add New Supplier', 'wiaas'),
|
||||
'new_item_name' => __('New Supplier Name', 'wiaas'),
|
||||
'menu_name' => __('Supplier', 'wiaas'),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array('slug' => 'template_category'),
|
||||
);
|
||||
|
||||
register_taxonomy('supplier', array('product'), $args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create corresponding supplier term for organization
|
||||
*
|
||||
* @param $organization_id
|
||||
*/
|
||||
public static function on_organization_added($organization_id) {
|
||||
$organization = get_term_by('id', $organization_id, 'wiaas-user-organization');
|
||||
|
||||
$supplier = term_exists($organization->slug, 'supplier');
|
||||
|
||||
if (! $supplier) {
|
||||
$supplier = wp_insert_term($organization->name, 'supplier', array(
|
||||
'slug' => $organization->slug
|
||||
));
|
||||
}
|
||||
|
||||
add_term_meta($supplier['term_id'], 'organisation_id', $organization->term_id);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Product_Supplier::init();
|
||||
@@ -27,7 +27,108 @@ function construct_template_products_class() {
|
||||
return 'wiaastemplate';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template categories from template product meta
|
||||
*
|
||||
* @param $template_id integer
|
||||
* @param $template_category_slug string the name of the main wiaas category
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_template_categories_from_meta($template_id, $template_category_slug) {
|
||||
|
||||
return get_post_meta($template_id, $template_category_slug, true);
|
||||
}
|
||||
|
||||
public static function extract_template_product_categories($category_meta) {
|
||||
$category_objects = array();
|
||||
|
||||
|
||||
if (empty($category_meta)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($category_meta as $meta) {
|
||||
|
||||
if (!empty($meta)) {
|
||||
|
||||
|
||||
$category_template_id = $meta['template_category_id'];
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$meta['template_category_title'],
|
||||
$meta['quantity']);
|
||||
|
||||
$category_objects[$category_template_id] = $template_category_object;
|
||||
}
|
||||
|
||||
}
|
||||
return empty($category_objects) ? null : $category_objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get template categories from bundled products items
|
||||
*
|
||||
* @param $bundled_items array
|
||||
* @return array
|
||||
*/
|
||||
public static function extract_bundled_product_categories($bundled_items) {
|
||||
|
||||
$template_category_objects = array();
|
||||
foreach ($bundled_items as $item_id => $item) {
|
||||
$item_data = $item->get_data();
|
||||
$post_terms = wp_get_object_terms($item->get_product_id(), 'template_category', array('fields' => 'id=>name'));
|
||||
|
||||
if (!empty($post_terms) && !is_wp_error($post_terms)) {
|
||||
|
||||
$cat = '';
|
||||
$category_template_id = '';
|
||||
|
||||
foreach ($post_terms as $id => $term) {
|
||||
$cat = $term;
|
||||
$category_template_id = $id;
|
||||
}
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$cat,
|
||||
$item_data['quantity_max']);
|
||||
$template_category_objects[$category_template_id] = $template_category_object;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $template_category_objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save selected template to bundled product meta
|
||||
*
|
||||
* @param $selected_template integer
|
||||
* @param $post_id integer
|
||||
*/
|
||||
|
||||
public static function bind_selected_template_to_product($selected_template, $post_id) {
|
||||
if (!empty($selected_template))
|
||||
update_post_meta($post_id, '_select_template', esc_attr($selected_template));
|
||||
else {
|
||||
update_post_meta($post_id, '_select_template', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save template categories to template product meta
|
||||
*
|
||||
* @param $post_id integer
|
||||
* @param $option string a main wiaas category
|
||||
* @param $processed_template_data array actual template category data
|
||||
*/
|
||||
|
||||
public static function save_template_product_meta($post_id, $option, $processed_template_data) {
|
||||
|
||||
update_post_meta($post_id, '_template_items_' . $option, $processed_template_data);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,24 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
|
||||
parent::hooks();
|
||||
|
||||
add_action('user_new_form', array( $this, 'show_organizations_selection' ));
|
||||
add_action('user_register', array( $this, 'save_terms_for_user' ));
|
||||
|
||||
add_action( 'created_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_added' ));
|
||||
add_action( 'pre_delete_term', array( __CLASS__, 'on_taxonomy_term_will_be_deleted' ), 10, 2);
|
||||
add_action('set_object_terms', array( __CLASS__, 'on_taxonomy_term_assigned' ), 10, 4);
|
||||
add_action('deleted_term_relationships', array( __CLASS__, 'on_taxonomy_term_unassigned' ), 10, 3);
|
||||
|
||||
|
||||
// Remove bulk editor for organizations on users list
|
||||
remove_filter( 'admin_notices', array( $this, 'bulk_notice'));
|
||||
remove_filter( 'bulk_actions-users', array( $this, 'bulk_actions'));
|
||||
remove_filter( 'bulk_actions-users', array( $this, 'bulk_actions_sort'));
|
||||
remove_action( 'handle_bulk_actions-users', array( $this, 'handle_bulk_actions'));
|
||||
|
||||
// remove default organization info from profiles
|
||||
// it will be handled by custom fields
|
||||
remove_action( 'show_user_profile', array( $this, 'edit_user_relationships' ), 99);
|
||||
remove_action( 'edit_user_profile', array( $this, 'edit_user_relationships' ), 99 );
|
||||
}
|
||||
|
||||
// hooks functions
|
||||
@@ -78,7 +89,7 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
if ($taxonomy === self::TAXONOMY_NAME) {
|
||||
$user_id = $object_id;
|
||||
$organization_id = $tt_ids[0];
|
||||
add_user_meta($user_id, 'organization_id', $organization_id, true);
|
||||
|
||||
self::_add_user_to_access_group($user_id, $organization_id);
|
||||
}
|
||||
}
|
||||
@@ -95,7 +106,7 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
if ($taxonomy === self::TAXONOMY_NAME) {
|
||||
$user_id = $object_id;
|
||||
$organization_id = $tt_ids[0];
|
||||
delete_user_meta($user_id, 'organization_id');
|
||||
|
||||
self::_remove_user_from_organization_access_groups($user_id, $organization_id);
|
||||
}
|
||||
}
|
||||
@@ -106,13 +117,13 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
* @param null $user_id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_user_organization($user_id = null) {
|
||||
public static function get_user_organization_id($user_id = null) {
|
||||
if (!isset($user_id)) {
|
||||
$user = wp_get_current_user();
|
||||
$user_id = $user->ID;
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$terms = wp_get_object_terms($user_id, self::TAXONOMY_NAME);
|
||||
return $terms[0];
|
||||
$organization_id = get_user_meta($user_id, '_wiaas_organization_id', true);
|
||||
|
||||
return empty($organization_id) ? null : (int) $organization_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,8 +135,8 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
* @param $user_id
|
||||
*/
|
||||
public static function assign_post_to_user_organization($post_id, $user_id) {
|
||||
$organization = self::get_user_organization($user_id);
|
||||
self::_assign_post_to_organization($post_id, $organization->term_id);
|
||||
$organization_id = self::get_user_organization_id($user_id);
|
||||
self::_assign_post_to_organization($post_id, $organization_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -240,73 +251,4 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show organizations selection on new user form
|
||||
*/
|
||||
function show_organizations_selection() {
|
||||
$terms = get_terms( array(
|
||||
'taxonomy' => self::TAXONOMY_NAME,
|
||||
'hide_empty' => false,
|
||||
) );
|
||||
$taxonomy = get_taxonomy(self::TAXONOMY_NAME);
|
||||
$this->table_contents(null, $taxonomy, $terms);
|
||||
}
|
||||
|
||||
function edit_user_relationships($user = false) {
|
||||
$tax = get_taxonomy( $this->taxonomy );
|
||||
|
||||
// Get the terms of the taxonomy.
|
||||
$terms = get_terms( $this->taxonomy, array(
|
||||
'hide_empty' => false
|
||||
) );
|
||||
|
||||
$this->table_contents( $user, $tax, $terms );
|
||||
}
|
||||
|
||||
function table_contents( $user, $tax, $terms ) {
|
||||
$active_organization_id = -1;
|
||||
if ($user) {
|
||||
$active_organization = self::get_user_organization($user->ID);
|
||||
$active_organization_id = $active_organization ? $active_organization->term_id : -1;
|
||||
}
|
||||
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr class="form-field">
|
||||
<th scope="row">
|
||||
<label for="<?php echo esc_attr( $this->taxonomy ); ?>[]">
|
||||
<?php echo esc_html( $tax->labels->singular_name ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="<?php echo esc_attr( $this->taxonomy ); ?>[]" id="<?php echo esc_attr( $this->taxonomy ); ?>">
|
||||
<?php
|
||||
foreach ( $terms as $term ) :
|
||||
$selected = $active_organization_id === $term->term_id;
|
||||
?>
|
||||
<option
|
||||
value="<?php echo esc_attr( $term->slug ); ?>"
|
||||
<?php selected( $selected ); ?>
|
||||
>
|
||||
<?php echo esc_attr( $term->name ); ?>
|
||||
</option>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
<?php
|
||||
wp_nonce_field( $this->taxonomy, $this->get_nonce_key() );
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function get_nonce_key() {
|
||||
return "wp_user_taxonomy_{$this->taxonomy}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Retrieves name for provided organization_id
|
||||
* @param int $organization_id
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function wiaas_get_organization_name($organization_id) {
|
||||
$term = get_term($organization_id);
|
||||
|
||||
if ($term instanceof WP_Term) {
|
||||
return $term->name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve array of organization role names
|
||||
*
|
||||
* @param int $organization_id
|
||||
*
|
||||
* @return array Array of organization roles
|
||||
*/
|
||||
function wiaas_get_organization_roles($organization_id) {
|
||||
$roles = get_term_meta($organization_id, '_wiaas_organization_roles', true);
|
||||
|
||||
return empty($roles) ? array() : $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $organization_id
|
||||
* @param array $roles
|
||||
*/
|
||||
function wiaas_set_organization_roles($organization_id, $roles) {
|
||||
update_term_meta($organization_id, '_wiaas_organization_roles', $roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves list of organizations with provided role in [ 'id' => 'name'] format
|
||||
* @param string $role
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_organizations_with_role($role) {
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => Wiaas_User_Organization::TAXONOMY_NAME,
|
||||
'meta_key' => '_wiaas_organization_roles',
|
||||
'meta_value' => $role,
|
||||
'fields' => 'id=>name',
|
||||
'meta_compare' => 'LIKE',
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
return is_array($terms) ? $terms : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves list of commercial lead organizations in [ 'id' => 'name' ] format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_commercial_leads() {
|
||||
return wiaas_get_organizations_with_role('commercial_lead');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves list of customer organizations in [ 'id' => 'name'] format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_customers() {
|
||||
return wiaas_get_organizations_with_role('customer');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves list of supplier organizations in [ 'id' => 'name'] format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function wiaas_get_suppliers() {
|
||||
return wiaas_get_organizations_with_role('supplier');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves id of organization for provided user_id
|
||||
*
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
function wiaas_get_user_organization_id($user_id) {
|
||||
$organization_id = get_user_meta($user_id, '_wiaas_organization_id', true);
|
||||
|
||||
return empty($organization_id) ? null : (int) $organization_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves id of current user organization
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
function wiaas_get_current_user_organization_id() {
|
||||
return wiaas_get_user_organization_id(get_current_user_id());
|
||||
}
|
||||
@@ -37,7 +37,6 @@ function load_active_plugins_list() {
|
||||
'jwt-authentication-for-wp-rest-api/jwt-auth.php',
|
||||
'gravityforms/gravityforms.php',
|
||||
'gravityflow/gravityflow.php',
|
||||
'capability-manager-enhanced/capsman-enhanced.php',
|
||||
'groups/groups.php',
|
||||
'wp-user-groups/wp-user-groups.php',
|
||||
'wiaas/wiaas.php'
|
||||
@@ -65,5 +64,5 @@ function load_wiaas_test_setup() {
|
||||
|
||||
# Require classes needed for db updates
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/class-wiaas-db-update.php';
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php';
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-general.php';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_Status::register_package_status_taxonomy()
|
||||
* @covers Wiaas_Package_Status::get_available_package_statuses()
|
||||
*/
|
||||
function test_register_package_status_taxonomy() {
|
||||
$taxonomy = get_taxonomy('package_status');
|
||||
|
||||
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||
|
||||
$package_statuses = Wiaas_Package_Status::get_available_package_statuses();
|
||||
|
||||
$this->assertNotEmpty($package_statuses);
|
||||
|
||||
$this->assertContains(Wiaas_Package_Status::AVAILABLE, $package_statuses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_Type::set_package_status()
|
||||
* @covers Wiaas_Package_Type::get_package_status()
|
||||
*/
|
||||
function test_adding_package_status() {
|
||||
$package = $this->create_new_package();
|
||||
|
||||
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::AVAILABLE);
|
||||
|
||||
$package_status = Wiaas_Package_Status::get_package_status($package->get_id());
|
||||
|
||||
$this->assertNotNull($package_status);
|
||||
$this->assertEquals($package_status, Wiaas_Package_Status::AVAILABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test package status update on simple product price update
|
||||
*/
|
||||
function test_package_status_update_on_simple_product_price_update() {
|
||||
$product1 = $this->create_new_product(20);
|
||||
$this->add_product_category($product1, 'hardware');
|
||||
|
||||
$product2 = $this->create_new_product(20);
|
||||
$this->add_product_category($product2, 'software');
|
||||
|
||||
$package = $this->create_new_package();
|
||||
|
||||
$this->add_products_to_package($package, array( $product1, $product2));
|
||||
|
||||
$pricing_rules = array(
|
||||
'purchase' => array(
|
||||
'minimal_fixed_price' => 100,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 0
|
||||
),
|
||||
'purchase_24' => array(
|
||||
'minimal_fixed_price' => 100,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 100
|
||||
),
|
||||
'managed_36' => array(
|
||||
'minimal_fixed_price' => 100,
|
||||
'principal_amount' => 100,
|
||||
'minimal_services_price' => 100
|
||||
)
|
||||
);
|
||||
$commision = 50;
|
||||
$cost_margin = 100;
|
||||
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
||||
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::AVAILABLE);
|
||||
|
||||
$product1->set_price(1000);
|
||||
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::MARGIN_EXCEEDED);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test package status update on cost margin update
|
||||
*/
|
||||
function test_package_status_update_on_margin_cost_update() {
|
||||
$product1 = $this->create_new_product(20);
|
||||
$this->add_product_category($product1, 'hardware');
|
||||
|
||||
$product2 = $this->create_new_product(20);
|
||||
$this->add_product_category($product2, 'software');
|
||||
|
||||
$package = $this->create_new_package();
|
||||
|
||||
$this->add_products_to_package($package, array( $product1, $product2));
|
||||
|
||||
$pricing_rules = array(
|
||||
'purchase' => array(
|
||||
'minimal_fixed_price' => 100,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 0
|
||||
),
|
||||
'purchase_24' => array(
|
||||
'minimal_fixed_price' => 100,
|
||||
'principal_amount' => 0,
|
||||
'minimal_services_price' => 100
|
||||
),
|
||||
'managed_36' => array(
|
||||
'minimal_fixed_price' => 100,
|
||||
'principal_amount' => 100,
|
||||
'minimal_services_price' => 100
|
||||
)
|
||||
);
|
||||
$commision = 50;
|
||||
$cost_margin = 0;
|
||||
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
||||
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::AVAILABLE);
|
||||
|
||||
$cost_margin = 1;
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
||||
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::MARGIN_EXCEEDED);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Package_CL_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
var $shop_owner_id, $customer_id, $package_id, $cl_extras;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->shop_owner_id = wp_insert_term(
|
||||
'Shop owner organization',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME)['term_id'];
|
||||
|
||||
$this->customer_id = wp_insert_term(
|
||||
'Customer Organization',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME)['term_id'];
|
||||
|
||||
$package = $this->create_new_package();
|
||||
|
||||
$this->add_products_to_package($package, array( $this->create_new_product()));
|
||||
|
||||
$this->package_id = $package->get_id();
|
||||
|
||||
$this->cl_extras = array(
|
||||
'purchase_default' => array(
|
||||
'fixed' => 10,
|
||||
'recurrent' => 10,
|
||||
'services' => 10,
|
||||
'visible' => true
|
||||
),
|
||||
'purchase_24_default' => array(
|
||||
'fixed' => 10,
|
||||
'recurrent' => 10,
|
||||
'services' => 10,
|
||||
'visible' => true
|
||||
),
|
||||
'managed_36_default' => array(
|
||||
'fixed' => 10,
|
||||
'recurrent' => 10,
|
||||
'services' => 10,
|
||||
'visible' => true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_CL_Pricing::set_extras()
|
||||
*/
|
||||
function test_packages_extras_set() {
|
||||
Wiaas_Package_CL_Pricing::set_extras(
|
||||
$this->shop_owner_id,
|
||||
$this->package_id,
|
||||
$this->cl_extras);
|
||||
|
||||
// validate data saved
|
||||
$cl_extras = get_term_meta(
|
||||
$this->shop_owner_id,
|
||||
'_wiaas_cm_extras_' . $this->package_id,
|
||||
true);
|
||||
|
||||
$this->_validate_default_cl_extras($cl_extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_CL_Pricing::get_extras()
|
||||
*/
|
||||
function test_package_extras_retrieved() {
|
||||
update_term_meta(
|
||||
$this->shop_owner_id,
|
||||
'_wiaas_cm_extras_' . $this->package_id,
|
||||
$this->cl_extras);
|
||||
|
||||
$cl_extras = Wiaas_Package_CL_Pricing::get_extras($this->shop_owner_id, $this->package_id);
|
||||
|
||||
$this->_validate_default_cl_extras($cl_extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_CL_Pricing::get_extras_for_customer()
|
||||
*/
|
||||
function test_default_extras_retrieved_for_customer() {
|
||||
update_term_meta(
|
||||
$this->shop_owner_id,
|
||||
'_wiaas_cm_extras_' . $this->package_id,
|
||||
$this->cl_extras);
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
foreach ($pay_types as $pay_type) {
|
||||
$customer_cl_extra = Wiaas_Package_CL_Pricing::get_extras_for_customer(
|
||||
$this->shop_owner_id,
|
||||
$pay_type,
|
||||
$this->package_id,
|
||||
$this->customer_id);
|
||||
|
||||
$this->assertNotNull($customer_cl_extra);
|
||||
|
||||
$this->assertEquals(10, $customer_cl_extra['fixed']);
|
||||
$this->assertEquals(10, $customer_cl_extra['recurrent']);
|
||||
$this->assertEquals(10, $customer_cl_extra['services']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Package_CL_Pricing::get_extras_for_customer()
|
||||
*/
|
||||
function test_customer_specific_extras_retrieved_for_customer() {
|
||||
// append customer specific extras for purchase payment type
|
||||
$this->cl_extras['purchase_customer_' . $this->customer_id] = array(
|
||||
'fixed' => 100,
|
||||
'recurrent' => 100,
|
||||
'services' => 100,
|
||||
'visible' => true
|
||||
);
|
||||
|
||||
// set prices extras
|
||||
update_term_meta(
|
||||
$this->shop_owner_id,
|
||||
'_wiaas_cm_extras_' . $this->package_id,
|
||||
$this->cl_extras);
|
||||
|
||||
// test that only extras are retrieved for purchase payment type
|
||||
// and the rest are not retrieved
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
foreach ($pay_types as $pay_type) {
|
||||
$customer_cl_extra = Wiaas_Package_CL_Pricing::get_extras_for_customer(
|
||||
$this->shop_owner_id,
|
||||
$pay_type,
|
||||
$this->package_id,
|
||||
$this->customer_id);
|
||||
|
||||
if ($pay_type === 'purchase') {
|
||||
|
||||
$this->assertNotNull($customer_cl_extra);
|
||||
|
||||
$this->assertEquals(100, $customer_cl_extra['fixed']);
|
||||
$this->assertEquals(100, $customer_cl_extra['recurrent']);
|
||||
$this->assertEquals(100, $customer_cl_extra['services']);
|
||||
} else {
|
||||
|
||||
$this->assertNull($customer_cl_extra);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// HELPERS
|
||||
|
||||
private function _validate_default_cl_extras($cl_extras) {
|
||||
$this->assertNotEmpty($cl_extras);
|
||||
|
||||
$this->assertArrayHasKey('purchase_default', $cl_extras);
|
||||
$this->assertArrayHasKey('purchase_24_default', $cl_extras);
|
||||
$this->assertArrayHasKey('managed_36_default', $cl_extras);
|
||||
|
||||
foreach ($cl_extras as $cl_extra) {
|
||||
$this->assertEquals(10, $cl_extra['fixed']);
|
||||
$this->assertEquals(10, $cl_extra['recurrent']);
|
||||
$this->assertEquals(10, $cl_extra['services']);
|
||||
$this->assertTrue($cl_extra['visible']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,9 @@ class Wiaas_Package_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
);
|
||||
|
||||
$commision = 60;
|
||||
$cost_margin = 0;
|
||||
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision);
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
|
||||
@@ -0,0 +1,388 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Wiaas_Authentication_Test extends Wiaas_Unit_Test_Case {
|
||||
var $user_id, $organization_id, $request_uri;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// set admin as current user
|
||||
wp_set_current_user(1);
|
||||
|
||||
// create testing user
|
||||
$this->user_id = wp_create_user('test', 'test', 'test@mail.com');
|
||||
|
||||
// create organization
|
||||
$this->organization_id = wp_insert_term(
|
||||
'test_organization',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
|
||||
update_user_meta($this->user_id, '_wiaas_organization_id', $this->organization_id);
|
||||
|
||||
|
||||
# assign user to organization
|
||||
wp_set_terms_for_user(
|
||||
$this->user_id,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||
[$this->organization_id]);
|
||||
|
||||
wp_set_current_user($this->user_id);
|
||||
|
||||
$this->request_uri = $_SERVER['REQUEST_URI'];
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
parent::tearDown();
|
||||
|
||||
wp_set_current_user(1);
|
||||
|
||||
wp_delete_user($this->user_id);
|
||||
|
||||
wp_delete_term(
|
||||
$this->organization_id,
|
||||
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||
|
||||
delete_user_meta($this->user_id, '_wiaas_organization_id');
|
||||
delete_user_meta($this->user_id, '_wiaas_current_user_admin_role');
|
||||
|
||||
$_SERVER['REQUEST_URI'] = $this->request_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_user_authentication_fail_when_no_selected_role() {
|
||||
|
||||
$this->assertFalse(
|
||||
Wiaas_Authentication::authenticate_current_user($this->user_id)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
is_wp_error(
|
||||
Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user())
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_user_authentication_forwards_error() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'supplier', 'customer' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
|
||||
|
||||
$this->assertFalse(
|
||||
Wiaas_Authentication::authenticate_current_user(false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_current_user_authentication_fail_when_organization_has_no_roles() {
|
||||
|
||||
$roles = array('administrator', 'supplier', 'customer', 'commercial_lead');
|
||||
|
||||
foreach ($roles as $role) {
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $role);
|
||||
|
||||
$this->assertFalse(
|
||||
Wiaas_Authentication::authenticate_current_user($this->user_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_current_user_authentication_fail_when_organization_has_different_roles() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'supplier', 'customer' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
$user_roles = array('administrator', 'commercial_lead');
|
||||
|
||||
foreach ($user_roles as $user_role) {
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
|
||||
|
||||
$this->assertFalse(
|
||||
Wiaas_Authentication::authenticate_current_user($this->user_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_current_user_authentication_valid_when_organization_has_requested_role() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'administrator', 'commercial_lead' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
$user_roles = $organization_roles;
|
||||
|
||||
foreach ($user_roles as $user_role) {
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->user_id,
|
||||
Wiaas_Authentication::authenticate_current_user($this->user_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_current_user_authentication_invalid_when_organization_has_no_customer_role() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'administrator', 'commercial_lead' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
$user_roles = $organization_roles;
|
||||
|
||||
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
|
||||
|
||||
foreach ($user_roles as $user_role) {
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
|
||||
|
||||
$this->assertFalse(
|
||||
Wiaas_Authentication::authenticate_current_user($this->user_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_current_user()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_current_user_authentication_valid_when_organization_has_customer_role() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'administrator', 'commercial_lead', 'customer' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
$user_roles = $organization_roles;
|
||||
|
||||
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
|
||||
|
||||
foreach ($user_roles as $user_role) {
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
|
||||
|
||||
$this->assertEquals(
|
||||
$this->user_id,
|
||||
Wiaas_Authentication::authenticate_current_user($this->user_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_fails_if_no_role_posted() {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$error = Wiaas_Authentication::authenticate_user_on_login($user);
|
||||
|
||||
$this->assertTrue(is_wp_error($error));
|
||||
|
||||
$this->assertEquals('You must selected role to login!', $error->get_error_message());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_does_nothing_if_rest_request() {
|
||||
|
||||
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
|
||||
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$response_user = Wiaas_Authentication::authenticate_user_on_login($user);
|
||||
|
||||
$this->assertEquals(
|
||||
$user->ID,
|
||||
$response_user->ID
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_fails_if_customer_role_requested() {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$_POST['role'] = 'customer';
|
||||
|
||||
$error = Wiaas_Authentication::authenticate_user_on_login($user);
|
||||
|
||||
$this->assertTrue(is_wp_error($error));
|
||||
|
||||
$this->assertEquals('No access!', $error->get_error_message());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_fails_when_user_has_no_organization() {
|
||||
|
||||
$_POST['role'] = 'supplier';
|
||||
|
||||
delete_user_meta($this->user_id, '_wiaas_organization_id');
|
||||
|
||||
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
|
||||
|
||||
$this->assertTrue(is_wp_error($error));
|
||||
|
||||
$this->assertEquals('Account not completed!', $error->get_error_message());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_fails_when_organization_has_no_roles() {
|
||||
|
||||
$_POST['role'] = 'supplier';
|
||||
|
||||
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
|
||||
|
||||
$this->assertTrue(is_wp_error($error));
|
||||
|
||||
$this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_fails_when_organization_has_different_roles() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'supplier', 'customer' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
$_POST['role'] = 'commercial_lead';
|
||||
|
||||
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
|
||||
|
||||
$this->assertTrue(is_wp_error($error));
|
||||
|
||||
$this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::authenticate_user_on_login()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_login_authentication_valid_when_organization_has_requested_role() {
|
||||
// add roles to organization
|
||||
$organization_roles = array( 'administrator', 'commercial_lead' );
|
||||
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
|
||||
|
||||
$user_roles = $organization_roles;
|
||||
|
||||
foreach ($user_roles as $user_role) {
|
||||
$_POST['role'] = $user_role;
|
||||
|
||||
$response_user = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
|
||||
|
||||
$this->assertEquals(
|
||||
$this->user_id,
|
||||
$response_user->ID
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::maybe_filter_user_roles()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_user_has_customer_role_on_rest_request() {
|
||||
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
|
||||
null, $this->user_id,
|
||||
$wpdb->get_blog_prefix() . 'capabilities'
|
||||
);
|
||||
|
||||
$this->assertNotNull($user_roles);
|
||||
$this->assertCount(1, $user_roles);
|
||||
|
||||
$user_roles = $user_roles[0];
|
||||
|
||||
$this->assertNotNull($user_roles);
|
||||
$this->assertCount(1, $user_roles);
|
||||
$this->assertArrayHasKey('customer', $user_roles);
|
||||
$this->assertTrue($user_roles['customer']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::maybe_filter_user_roles()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_user_has_no_role_if_not_selected() {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
|
||||
null, $this->user_id,
|
||||
$wpdb->get_blog_prefix() . 'capabilities'
|
||||
);
|
||||
|
||||
$this->assertNotNull($user_roles);
|
||||
$this->assertCount(1, $user_roles);
|
||||
|
||||
$user_roles = $user_roles[0];
|
||||
|
||||
$this->assertNotNull($user_roles);
|
||||
$this->assertCount(1, $user_roles);
|
||||
$this->assertEmpty(array_keys($user_roles)[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Authentication::maybe_filter_user_roles()
|
||||
* @group authentication
|
||||
*/
|
||||
function test_user_has_selected_role() {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
|
||||
|
||||
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
|
||||
null, $this->user_id,
|
||||
$wpdb->get_blog_prefix() . 'capabilities'
|
||||
);
|
||||
|
||||
$this->assertNotNull($user_roles);
|
||||
$this->assertCount(1, $user_roles);
|
||||
|
||||
$user_roles = $user_roles[0];
|
||||
|
||||
$this->assertNotNull($user_roles);
|
||||
$this->assertCount(1, $user_roles);
|
||||
$this->assertArrayHasKey('supplier', $user_roles);
|
||||
$this->assertTrue($user_roles['supplier']);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
|
||||
update_user_meta($this->customer_id, '_wiaas_organization_id', $this->customer_organization_id);
|
||||
|
||||
# add customer to organization
|
||||
wp_set_terms_for_user(
|
||||
$this->customer_id,
|
||||
@@ -198,28 +200,4 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
|
||||
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Wiaas_Order::transform_rest_order()
|
||||
*/
|
||||
function test_order_rest_response_has_empty_documents_when_package_has_no_documents() {
|
||||
$order_response = array(
|
||||
'customer_id' => $this->customer_id,
|
||||
'status' => 'processing',
|
||||
'line_items' => array()
|
||||
);
|
||||
$request = array( 'id' => $this->order_id);
|
||||
|
||||
$order_rest_response = new WP_REST_Response($order_response);
|
||||
|
||||
$order_rest_response = Wiaas_Order::transform_rest_order(
|
||||
$order_rest_response,
|
||||
wc_get_order($this->order_id),
|
||||
$request);
|
||||
|
||||
$transformed_order_response = $order_rest_response->get_data();
|
||||
|
||||
$this->assertNotNull($transformed_order_response['documents']);
|
||||
$this->assertTrue(is_array($transformed_order_response['documents']));
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,21 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
)
|
||||
);
|
||||
$commision = 50;
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision);
|
||||
$cost_margin = 0;
|
||||
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
|
||||
|
||||
$customer_id = wp_create_term(
|
||||
'Customer',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
|
||||
$commercial_lead_id = wp_create_term(
|
||||
'Commercial Lead',
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
|
||||
|
||||
self::_set_package_default_extras($commercial_lead_id, $package->get_id());
|
||||
|
||||
$expected_prices = array(
|
||||
'purchase' => array(
|
||||
@@ -51,7 +65,32 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
)
|
||||
);
|
||||
|
||||
return array( $package, $expected_prices );
|
||||
return array( $package, $expected_prices, $customer_id, $commercial_lead_id );
|
||||
}
|
||||
|
||||
private function _set_package_default_extras($commercial_lead_id, $package_id) {
|
||||
$cl_extras = array(
|
||||
'purchase_default' => array(
|
||||
'fixed' => 0,
|
||||
'recurrent' => 0,
|
||||
'services' => 0,
|
||||
'visible' => true
|
||||
),
|
||||
'purchase_24_default' => array(
|
||||
'fixed' => 0,
|
||||
'recurrent' => 0,
|
||||
'services' => 0,
|
||||
'visible' => true
|
||||
),
|
||||
'managed_36_default' => array(
|
||||
'fixed' => 0,
|
||||
'recurrent' => 0,
|
||||
'services' => 0,
|
||||
'visible' => true
|
||||
)
|
||||
);
|
||||
|
||||
Wiaas_Package_CL_Pricing::set_extras($commercial_lead_id, $package_id, $cl_extras);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,9 +210,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
*/
|
||||
function test_get_standard_package_customer_price() {
|
||||
|
||||
list( $package, $expected_prices ) = $this->_create_package_to_sell();
|
||||
list( $package, $expected_prices, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
|
||||
|
||||
$customer_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
$customer_prices = Wiaas_Pricing::get_standard_package_customer_prices(
|
||||
$package,
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
|
||||
$this->assertCount(3, $customer_prices);
|
||||
|
||||
@@ -202,7 +244,7 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Pricing::get_addon_package_customer_price()
|
||||
*/
|
||||
function test_get_addon_package_customer_price() {
|
||||
list( $package ) = $this->_create_package_to_sell();
|
||||
list( $package, $expected_prices, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
|
||||
|
||||
$addon_product = $this->create_new_product(20);
|
||||
$this->add_product_category($addon_product, 'hardware');
|
||||
@@ -229,7 +271,10 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
)
|
||||
);
|
||||
$commision = 50;
|
||||
Wiaas_Package_Pricing::set_package_prices($addon_package, $pricing_rules, $commision);
|
||||
$cost_margin = 0;
|
||||
Wiaas_Package_Pricing::set_package_prices($addon_package, $pricing_rules, $commision, $cost_margin);
|
||||
|
||||
self::_set_package_default_extras($commercial_lead_id, $addon_package->get_id());
|
||||
|
||||
Wiaas_Package_Addon::set_package_addons($package, array($addon_package->get_id()));
|
||||
|
||||
@@ -251,7 +296,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
)
|
||||
);
|
||||
|
||||
$customer_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $package);
|
||||
$customer_prices = Wiaas_Pricing::get_addon_package_customer_price(
|
||||
$addon_package,
|
||||
$package,
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
|
||||
$this->assertCount(3, $customer_prices);
|
||||
|
||||
@@ -279,7 +328,7 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_Pricing::get_option_package_customer_price()
|
||||
*/
|
||||
function test_get_option_package_customer_price() {
|
||||
list( $package ) = $this->_create_package_to_sell();
|
||||
list( $package, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
|
||||
|
||||
$option_product = $this->create_new_product(20);
|
||||
$this->add_product_category($option_product, 'hardware');
|
||||
@@ -306,7 +355,10 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
)
|
||||
);
|
||||
$commision = 50;
|
||||
Wiaas_Package_Pricing::set_package_prices($option_package, $pricing_rules, $commision);
|
||||
$cost_margin = 0;
|
||||
Wiaas_Package_Pricing::set_package_prices($option_package, $pricing_rules, $commision, $cost_margin);
|
||||
|
||||
self::_set_package_default_extras($commercial_lead_id, $option_package->get_id());
|
||||
|
||||
Wiaas_Package_Option_Groups::set_package_option_groups($package, array(
|
||||
'id' => 'option',
|
||||
@@ -333,7 +385,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||
)
|
||||
);
|
||||
|
||||
$customer_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $package);
|
||||
$customer_prices = Wiaas_Pricing::get_option_package_customer_price(
|
||||
$option_package,
|
||||
$package,
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
|
||||
$this->assertCount(3, $customer_prices);
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Wiaas_Templates_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $template, $product, $package, $template_category, $template_meta;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
# set admin as current user
|
||||
wp_set_current_user(1);
|
||||
|
||||
$this->template_category = wp_create_term('Test', 'template_category');
|
||||
$this->template_meta = array(
|
||||
'template_category_id' => $this->template_category['term_id'],
|
||||
'template_category_title' => 'Test',
|
||||
'quantity' => 1
|
||||
);
|
||||
|
||||
$this->template = $this->create_new_wiaas_template();
|
||||
$this->product = $this->create_new_product();
|
||||
$this->package = $this->create_new_package();
|
||||
$this->add_products_to_package($this->package, $this->product);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function test_template_category_taxonomy_created() {
|
||||
$taxonomy = get_taxonomy('template_category');
|
||||
|
||||
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||
|
||||
$template_category_names = array_map(function ($term) {
|
||||
return $term->name;
|
||||
}, get_terms(array('taxonomy' => 'template_category', 'hide_empty' => false)));
|
||||
|
||||
$this->assertNotEmpty($template_category_names);
|
||||
$this->assertContains('Test', $template_category_names);
|
||||
|
||||
}
|
||||
|
||||
function test_adding_template_category_to_template() {
|
||||
|
||||
WC_Product_Template::save_template_product_meta($this->template->get_id(), 'hardware', $this->template_meta);
|
||||
|
||||
$test_template_category = WC_Product_Template::get_template_categories_from_meta(
|
||||
$this->template->get_id(), '_template_items_hardware');
|
||||
|
||||
$this->assertEquals($test_template_category['template_category_id'], $this->template_meta['template_category_id']);
|
||||
$this->assertEquals($test_template_category['template_category_title'], $this->template_meta['template_category_title']);
|
||||
$this->assertEquals($test_template_category['quantity'], $this->template_meta['quantity']);
|
||||
}
|
||||
|
||||
function save_bind_package_to_template() {
|
||||
WC_Product_Template::bind_selected_template_to_product($this->template->get_id(), $this->package->get_id());
|
||||
$value = get_post_meta($this->package->get_id(), '_select_template', true);
|
||||
|
||||
$this->assertNotEmpty($value);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
|
||||
Wiaas_User_Organization::TAXONOMY_NAME
|
||||
)['term_id'];
|
||||
|
||||
update_user_meta($this->user_id, '_wiaas_organization_id', $this->user_organization_id);
|
||||
|
||||
# create department
|
||||
$this->user_department_id = wp_insert_term(
|
||||
$this->user_department_name,
|
||||
@@ -63,11 +65,10 @@ class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
|
||||
* @covers Wiaas_User_Organization::get_user_organization()
|
||||
*/
|
||||
function test_retrieve_user_organization() {
|
||||
$organization = Wiaas_User_Organization::get_user_organization($this->user_id);
|
||||
$organization_id = Wiaas_User_Organization::get_user_organization_id($this->user_id);
|
||||
|
||||
$this->assertNotNull($organization);
|
||||
$this->assertEquals($organization->term_id, $this->user_organization_id);
|
||||
$this->assertEquals($organization->name, $this->user_organization_name);
|
||||
$this->assertNotNull($organization_id);
|
||||
$this->assertEquals($organization_id, $this->user_organization_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,8 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
|
||||
Wiaas_Package_Type::register_package_type_taxonomy();
|
||||
|
||||
Wiaas_Order_Project::register_order_project_taxonomy();
|
||||
|
||||
Wiaas_Product_Supplier::register_supplier_taxonomy();
|
||||
|
||||
define('WP_TEST_IN_PROGRESS',true);
|
||||
}
|
||||
@@ -88,6 +90,21 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
|
||||
$package->sync(true);
|
||||
}
|
||||
|
||||
|
||||
function create_new_wiaas_template() {
|
||||
$post_id = wp_insert_post(array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'post_name' => 'product',
|
||||
'post_title' => 'Package',
|
||||
'post_content' => 'Package',
|
||||
'post_excerpt' => 'Package'
|
||||
), true);
|
||||
|
||||
return new WC_Product_Template($post_id);
|
||||
|
||||
}
|
||||
|
||||
function create_new_customer($login = 'customer_test', $organization_name = 'test-customer-organization') {
|
||||
$customer_id = wp_insert_user(array(
|
||||
'user_login' => $login,
|
||||
|
||||
17
backend/app/plugins/wiaas/tests/wiaas-unit-test-factory.php
Normal file
17
backend/app/plugins/wiaas/tests/wiaas-unit-test-factory.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Unit_Test_Factory {
|
||||
|
||||
//
|
||||
public $product;
|
||||
|
||||
//
|
||||
public $package;
|
||||
|
||||
//
|
||||
public $organization;
|
||||
|
||||
function __construct() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,14 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-cli.php';
|
||||
}
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-authentication.php';
|
||||
|
||||
if (is_admin()) {
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
||||
}
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-access-management.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-order.php';
|
||||
@@ -30,6 +38,8 @@ include_once WIAAS_DIR . '/includes/class-wiaas-product.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-package.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-shop.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-user.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-pricing.php';
|
||||
@@ -44,6 +54,10 @@ include_once WIAAS_DIR . '/includes/class-wiaas-checkout.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiass-templates.php';
|
||||
|
||||
function wiaas_redirect_to_login() {
|
||||
wp_safe_redirect(get_site_url('', 'wp-login.php'));
|
||||
}
|
||||
|
||||
add_filter('wp_die_handler', 'wiaas_redirect_to_login');
|
||||
|
||||
@@ -62,6 +62,8 @@
|
||||
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
|
||||
"wpackagist-plugin/wp-user-groups": "2.2.0",
|
||||
"wpackagist-plugin/radio-buttons-for-taxonomies": "1.8.3",
|
||||
"wpackagist-plugin/advanced-access-manager": "5.4.3.2",
|
||||
"wpackagist-plugin/advanced-custom-fields" : "5.7.7",
|
||||
|
||||
"3rdparty/gravityforms": "*",
|
||||
"3rdparty/gravityflow": "*",
|
||||
@@ -96,6 +98,8 @@
|
||||
"wp plugin activate groups",
|
||||
"wp plugin activate wp-user-groups",
|
||||
"wp plugin activate radio-buttons-for-taxonomies",
|
||||
"wp plugin activate advanced-access-manager",
|
||||
"wp plugin activate advanced-custom-fields",
|
||||
"wp plugin activate wiaas"
|
||||
],
|
||||
"update-db": [
|
||||
|
||||
42
backend/composer.lock
generated
42
backend/composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "d979d3435513dd818189e2f68cc023fe",
|
||||
"content-hash": "da3d7fa874b9a31355d3c3d4df50ae94",
|
||||
"packages": [
|
||||
{
|
||||
"name": "3rdparty/gravityflow",
|
||||
@@ -428,6 +428,46 @@
|
||||
"homepage": "https://woocommerce.com/",
|
||||
"time": "2018-07-25T18:00:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "wpackagist-plugin/advanced-access-manager",
|
||||
"version": "5.4.3.2",
|
||||
"source": {
|
||||
"type": "svn",
|
||||
"url": "https://plugins.svn.wordpress.org/advanced-access-manager/",
|
||||
"reference": "tags/5.4.3.2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://downloads.wordpress.org/plugin/advanced-access-manager.5.4.3.2.zip",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "~1.0"
|
||||
},
|
||||
"type": "wordpress-plugin",
|
||||
"homepage": "https://wordpress.org/plugins/advanced-access-manager/"
|
||||
},
|
||||
{
|
||||
"name": "wpackagist-plugin/advanced-custom-fields",
|
||||
"version": "5.7.7",
|
||||
"source": {
|
||||
"type": "svn",
|
||||
"url": "https://plugins.svn.wordpress.org/advanced-custom-fields/",
|
||||
"reference": "tags/5.7.7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://downloads.wordpress.org/plugin/advanced-custom-fields.5.7.7.zip",
|
||||
"reference": null,
|
||||
"shasum": null
|
||||
},
|
||||
"require": {
|
||||
"composer/installers": "~1.0"
|
||||
},
|
||||
"type": "wordpress-plugin",
|
||||
"homepage": "https://wordpress.org/plugins/advanced-custom-fields/"
|
||||
},
|
||||
{
|
||||
"name": "wpackagist-plugin/akismet",
|
||||
"version": "4.0.3",
|
||||
|
||||
@@ -63,6 +63,10 @@ define('NONCE_SALT', env('WP_NONCE_SALT'));
|
||||
define('JWT_AUTH_SECRET_KEY', env('WP_JWT_AUTH_SECRET_KEY'));
|
||||
define('JWT_AUTH_CORS_ENABLE', true);
|
||||
|
||||
/**
|
||||
* Wiaas Env variables
|
||||
*/
|
||||
define('WIAAS_CUSTOMER_INTERFACE', env('WIAAS_CUSTOMER_INTERFACE') ?: WP_HOME);
|
||||
|
||||
/**
|
||||
* Custom Settings
|
||||
|
||||
@@ -7,6 +7,7 @@ services:
|
||||
dockerfile: backend.dockerfile
|
||||
args:
|
||||
- API_URL
|
||||
- WIAAS_CUSTOMER_INTERFACE
|
||||
- MYSQL_DATABASE
|
||||
- MYSQL_USER
|
||||
- MYSQL_PASSWORD
|
||||
|
||||
@@ -7,6 +7,8 @@ MYSQL_PASSWORD=wp_password
|
||||
# Url where backend application api is available
|
||||
API_URL=http://localhost
|
||||
|
||||
WIAAS_CUSTOMER_INTERFACE=http://localhost:8080
|
||||
|
||||
#Wordpress config
|
||||
|
||||
# Determines loading of enviroment specific non sensitive wordpress config file (/backend/config/environments/[WP_ENV].php)
|
||||
|
||||
@@ -70,6 +70,10 @@ export const fetchCartCount = () => {
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchCartNotices = () => {
|
||||
|
||||
};
|
||||
|
||||
export const fetchCartItems = (isForSteps = false) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCartItems());
|
||||
@@ -225,15 +229,15 @@ export const previousStep = (params) => ({type: GO_TO_PREVIOUS_STEP, params});
|
||||
|
||||
export const uploadDocumnet = () => ({type: UPLOAD_DOCUMENT});
|
||||
|
||||
export const uploadOrderDocument = (idPackage, idDocumentType, file, packages) => {
|
||||
export const uploadOrderDocument = (packageCartKey, idDocumentType, file, packages) => {
|
||||
return dispatch => {
|
||||
dispatch(uploadDocumnet());
|
||||
|
||||
return client.uploadFile(file, {
|
||||
url: `${API_SERVER}/cart/api/uploadOrderDocument`,
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||
data: {
|
||||
idDocumentType,
|
||||
idPackage
|
||||
'doc_type': idDocumentType,
|
||||
'package_key': packageCartKey
|
||||
}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
@@ -266,30 +270,21 @@ export const fetchCartDocuments = (packages, isForSteps = false) => {
|
||||
return dispatch => {
|
||||
dispatch(requestCartDocuments());
|
||||
|
||||
dispatch(receiveCartDocuments({
|
||||
areFilesUploaded: true,
|
||||
templates: [],
|
||||
uploaded: []
|
||||
}));
|
||||
if(isForSteps) {
|
||||
dispatch(loadSteps(true));
|
||||
}
|
||||
|
||||
// return client.fetch({
|
||||
// url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||
// method: 'get',
|
||||
// data: {packages}
|
||||
// }).then(response => {
|
||||
// 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);
|
||||
// });
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||
method: 'get',
|
||||
data: {packages}
|
||||
}).then(response => {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,6 +330,19 @@ export const placeOrder = (orderInfo) => {
|
||||
project_id: orderDetails.details.idProject,
|
||||
delivery_address_id: orderDetails.delivery.id,
|
||||
billing_address_id: orderDetails.billing.id,
|
||||
shipping_city: orderDetails.delivery.city,
|
||||
shipping_country: orderDetails.delivery.countryName,
|
||||
shipping_address_1: orderDetails.delivery.detailedAddress,
|
||||
shipping_postcode: orderDetails.delivery.zipCode,
|
||||
shipping_first_name: orderDetails.delivery.firstName,
|
||||
shipping_last_name: orderDetails.delivery.lastName,
|
||||
billing_city: orderDetails.billing.city,
|
||||
billing_country: orderDetails.billing.countryName,
|
||||
billing_address_1: orderDetails.billing.detailedAddress,
|
||||
billing_postcode: orderDetails.billing.zipCode,
|
||||
billing_first_name: orderDetails.billing.firstName,
|
||||
billing_last_name: orderDetails.billing.lastName,
|
||||
billing_last_email: orderDetails.billing.invoiceMail
|
||||
}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
|
||||
@@ -27,15 +27,9 @@ export const fetchShopPackages = (cl, search) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopPackages());
|
||||
let searchParam = search ? '?search=' +search : ''
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products` + searchParam,
|
||||
// TODO: Add comercialLead parameter after the support for it is added on backend
|
||||
|
||||
// method: 'post',
|
||||
// data: {
|
||||
// idCommercialLead: (cl && cl.value) || 0,
|
||||
// search
|
||||
// }
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/wp-json/wc/v2/products?cl_id=${cl.idCommercialLead}` + searchParam,
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
@@ -68,23 +62,29 @@ const generateClOptions = (commercialLeads) => {
|
||||
export const fetchShopCommercialLeads = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCommercialLeads());
|
||||
// TODO: FetchcomercialLead after the support for it is added on backend
|
||||
// return client.fetch({url: `${API_SERVER}/coMarket/api/getAllCommercialLeads`})
|
||||
// .then(response => {
|
||||
// if(response.data && response.data.commercialLeads){
|
||||
const clOptions = generateClOptions([{ "idCommercialLead": 14, "commercialLeadName": "Coor Service Management", "mail": "rikard@co-ideation.com" }]);
|
||||
dispatch(recieveShopCommercialLeads(clOptions));
|
||||
if (clOptions.length) {
|
||||
dispatch(selectCommercialLead(clOptions[0]));
|
||||
dispatch(fetchShopPackages(clOptions[0]));
|
||||
}
|
||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/commercial-leads` })
|
||||
.then(response => {
|
||||
|
||||
if(response.data){
|
||||
|
||||
const clOptions = generateClOptions(response.data.map(cl => ({
|
||||
idCommercialLead: cl.id,
|
||||
commercialLeadName: cl.name
|
||||
})));
|
||||
|
||||
dispatch(recieveShopCommercialLeads(clOptions));
|
||||
|
||||
if (clOptions.length) {
|
||||
dispatch(selectCommercialLead(clOptions[0]));
|
||||
dispatch(fetchShopPackages(clOptions[0]));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
// })
|
||||
// .catch(error => {
|
||||
// client.onError(error, dispatch);
|
||||
// });
|
||||
}
|
||||
// }
|
||||
|
||||
export const selectCommercialLead = (cl) => ({
|
||||
type: SELECT_SHOP_COMMERCIAL_LEAD,
|
||||
|
||||
@@ -147,9 +147,9 @@ export const cartTexts = {
|
||||
DOC_NOT_REQUIRED: 'Document not required',
|
||||
FILE_UPLOADED_TEXT: 'File uploaded! Select or drop to replace ',
|
||||
FILE: 'file',
|
||||
NO_FILE_UPLOAD_TEXT_1: 'Click here to select',
|
||||
NO_FILE_UPLOAD_TEXT_2: 'or drag and drop file here',
|
||||
TEMPLATES: 'Templates',
|
||||
NO_FILE_UPLOAD_TEXT_1: 'Drag and drop',
|
||||
NO_FILE_UPLOAD_TEXT_2: 'click to upload',
|
||||
TEMPLATE: 'Template',
|
||||
UPLOADED: 'Uploaded dcuments',
|
||||
PACKAGE_UNAVAILABLE: 'This package is no longer available. Remove it from the cart to place the order successfully',
|
||||
BID_AVAILABLE: 'Bids available!',
|
||||
@@ -167,7 +167,7 @@ export const cartTexts = {
|
||||
buttons: {
|
||||
YES: 'Yes',
|
||||
CANCEL: 'Cancel',
|
||||
PREVIOUS: 'Previous',
|
||||
BACK: 'Back',
|
||||
NEXT: 'Next',
|
||||
ADD_ADDRESS: 'Add address',
|
||||
USE: 'Use',
|
||||
|
||||
@@ -38,7 +38,7 @@ class CartStepsContainer extends Component {
|
||||
{(cartSteps && cartSteps[currentStep] && cartSteps[currentStep].previous && !isLoading) &&
|
||||
<span onClick={()=>{this.handleStepChange('previous')}} className="prev-btn">
|
||||
<Col sm="12" xs="12">
|
||||
{cartTexts.buttons.PREVIOUS}
|
||||
{cartTexts.buttons.BACK}
|
||||
</Col>
|
||||
</span>
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import {updateMessages} from '../../actions/notification/notificationActions';
|
||||
import {nextStep, setNextActionFct} from '../../actions/cart/cartActions';
|
||||
|
||||
const DOCUMENT_TYPES = {
|
||||
TEMPLATE_QUESTINNAIRE: 1,
|
||||
QUESTIONNAIRE: 2,
|
||||
TEMPLATE_AGREEMENT: 6,
|
||||
AGREEMENT: 7
|
||||
TEMPLATE_QUESTINNAIRE: 'template_questionaire',
|
||||
QUESTIONNAIRE: 'order_questionaire',
|
||||
TEMPLATE_AGREEMENT: 'template_agreement',
|
||||
AGREEMENT: 'order_agreement'
|
||||
};
|
||||
|
||||
class CartCustomerQuestionnaireContainer extends Component {
|
||||
@@ -34,7 +34,7 @@ class CartCustomerQuestionnaireContainer extends Component {
|
||||
}
|
||||
|
||||
handleStepChange() {
|
||||
if(this.props.cartDocuments && this.props.cartDocuments.areFilesUploaded) {
|
||||
if(this.props.cartDocuments && !this.props.cartDocuments.pending) {
|
||||
this.props.dispatch(nextStep());
|
||||
} else {
|
||||
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 FileDownloader from '../../../helpers/FileDownloader';
|
||||
import {cartTexts} from '../../../constants/cartConstants';
|
||||
import {getDocumentIcon} from '../../../helpers/DocumentHelper';
|
||||
import classnames from 'classnames';
|
||||
|
||||
const fileHandler = new FileDownloader();
|
||||
const documentTypes = {
|
||||
2 : 'Customer Questionnaire',
|
||||
7 : 'Customer Agreement'
|
||||
'order_questionaire' : 'Customer Questionnaire',
|
||||
'order_agreement' : 'Customer Agreement'
|
||||
};
|
||||
|
||||
class CartUploadDocument extends Component {
|
||||
@@ -20,11 +22,11 @@ class CartUploadDocument extends Component {
|
||||
this.uploadFile = this.uploadFile.bind(this);
|
||||
}
|
||||
|
||||
uploadFile(idPackage, idDocumentType,acceptedFiles, rejectedFiles, packages){
|
||||
uploadFile(packageCartKey, idDocumentType,acceptedFiles, rejectedFiles, packages){
|
||||
const self = this;
|
||||
|
||||
acceptedFiles.forEach(file => {
|
||||
self.props.dispatch(uploadOrderDocument(idPackage, idDocumentType, file, packages));
|
||||
self.props.dispatch(uploadOrderDocument(packageCartKey, idDocumentType, file, packages));
|
||||
});
|
||||
|
||||
if(rejectedFiles && rejectedFiles.length) {
|
||||
@@ -33,9 +35,15 @@ class CartUploadDocument extends Component {
|
||||
}
|
||||
|
||||
downloadDocument(document){
|
||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}`
|
||||
const fileName = document.documentName + '.' + document.extension;
|
||||
fileHandler.download(fileUrl, fileName);
|
||||
fileHandler.download(
|
||||
`${API_SERVER}/wp-json/wiaas/cart/items/${this.props.cartItem.key}/documents/${this.props.idDocumentType}?document_key=${document.key}`,
|
||||
`${document.name}.${document.extension}`);
|
||||
}
|
||||
|
||||
downloadTemplate(document) {
|
||||
fileHandler.download(
|
||||
`${API_SERVER}/wp-json/wiaas/documents?document_id=${document.id}`,
|
||||
`${document.name}.${document.extension}`);
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -45,30 +53,51 @@ class CartUploadDocument extends Component {
|
||||
{
|
||||
templateDocument &&
|
||||
<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"
|
||||
onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(cartItem.idPackage, idDocumentType, acceptedFiles, rejectedFiles, packages)}}>
|
||||
onDrop={(acceptedFiles, rejectedFiles)=>{this.uploadFile(cartItem.key, idDocumentType, acceptedFiles, rejectedFiles, packages)}}>
|
||||
{
|
||||
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>
|
||||
{
|
||||
uploadedDocument &&
|
||||
<div>
|
||||
<div className="cart-subtitle">{cartTexts.labels.UPLOADED}:</div>
|
||||
<div className="document-link" onClick={() => {this.downloadDocument(uploadedDocument)}}>
|
||||
<i className="fa fa-file" aria-hidden="true"></i>
|
||||
{' ' + uploadedDocument.documentName + ' (' + uploadedDocument.extension + ')'}
|
||||
</div>
|
||||
<span className="document-link" onClick={() => {this.downloadDocument(uploadedDocument)}}>
|
||||
<strong>
|
||||
<i className={`fa fa-${getDocumentIcon(uploadedDocument.extension)}`} aria-hidden="true"></i> {uploadedDocument.name}
|
||||
</strong>
|
||||
</span>
|
||||
</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>
|
||||
}
|
||||
|
||||
|
||||
@@ -6,19 +6,37 @@
|
||||
|
||||
.upload-file-drop-zone {
|
||||
width: 100%;
|
||||
border: 3px dashed $borderColor;
|
||||
margin-top: 1rem;
|
||||
height: 5rem;
|
||||
border: 1px dashed $borderColor;
|
||||
margin: 1rem 0;
|
||||
padding: 1rem;
|
||||
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 {
|
||||
text-align: center;
|
||||
padding: 1.3rem 0.5rem;
|
||||
color: $font-light-color;
|
||||
padding: 0;
|
||||
font-size: $font-size-small;
|
||||
}
|
||||
|
||||
.uploaded {
|
||||
color: #155724;
|
||||
.drop-zone-icon {
|
||||
color: #b3b3b3;
|
||||
}
|
||||
|
||||
.next-btn {
|
||||
@@ -28,18 +46,33 @@
|
||||
color: $darkGreyColor;
|
||||
}
|
||||
|
||||
.cart-template {
|
||||
margin: 1rem 0;
|
||||
.cart-subtitle {
|
||||
margin-right: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.cart-subtitle {
|
||||
font-weight: $font-weight;
|
||||
color: $font-light-color;
|
||||
font-size: $font-size-small;
|
||||
padding-top: 0.3rem;
|
||||
}
|
||||
}
|
||||
|
||||
.upload-layer{
|
||||
background: $whiteColor;
|
||||
padding-bottom: 1rem;
|
||||
padding: 1rem;
|
||||
color: $title-color;
|
||||
|
||||
.upload-layer {
|
||||
color: $title-color;
|
||||
}
|
||||
|
||||
.document-link{
|
||||
cursor: pointer;
|
||||
color: #2b6279;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ class CoMarketNavContainer extends Component {
|
||||
|
||||
handleSearchChange(event) {
|
||||
this.setState({searchValue: event.target.value});
|
||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
||||
if (this.props.selectedCommercialLead) {
|
||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -8,7 +8,9 @@ import {fetchShopPackages} from '../../actions/coMarket/coMarketPackagesActions'
|
||||
|
||||
class CoMarketPackagesContainer extends Component {
|
||||
componentDidMount() {
|
||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead));
|
||||
if (this.props.selectedCommercialLead) {
|
||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead));
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -43,7 +43,9 @@ class CoMarketCatalogSelect extends Component {
|
||||
|
||||
handleSearchChange(event) {
|
||||
this.setState({searchValue: event.target.value});
|
||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
||||
if (this.props.selectedCommercialLead) {
|
||||
this.props.dispatch(fetchShopPackages(this.props.selectedCommercialLead, event.target.value));
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -8,9 +8,9 @@ const fileHandler = new FileDownloader();
|
||||
|
||||
class PackageInfo extends Component {
|
||||
downloadDocument(document){
|
||||
const fileUrl = `${API_SERVER}/wp-json/wiaas/download-package-file?document_id=${document.idDocument}&package_id=${document.idPackage}`
|
||||
const fileName = document.documentName + '.' + document.extension;
|
||||
fileHandler.download(fileUrl, fileName);
|
||||
fileHandler.download(
|
||||
`${API_SERVER}/wp-json/wiaas/documents?document_id=${document.id}`,
|
||||
`${document.name}.${document.extension}`);
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -41,9 +41,9 @@ class PackageInfo extends Component {
|
||||
<div className="shop-package-label">{coMarketTexts.labels.DOCUMENTS}:</div>
|
||||
{
|
||||
documents.map((document) =>
|
||||
<span key={document.idDocument} className="document-link"
|
||||
<span key={document.id} className="document-link"
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,14 +5,21 @@ import {orderTexts} from '../../../constants/ordersConstants';
|
||||
|
||||
class OrderDocuments extends Component {
|
||||
render() {
|
||||
const {orderDocumentsBundle} = this.props;
|
||||
const {orderInfo} = this.props;
|
||||
|
||||
return (
|
||||
<div id="order-documents" className="order-documents">
|
||||
{
|
||||
orderDocumentsBundle.map(bundle => <OrderDocumentsGroup key={'order-package-' + bundle.package.name} packageName={bundle.package.name} packageID={bundle.package.id} documents={bundle.documents} />)
|
||||
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}} />
|
||||
}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user