Compare commits
3 Commits
authentica
...
backoffice
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed0f512273 | ||
|
|
0e6f5bdab6 | ||
|
|
0e8816abc0 |
@@ -2,8 +2,6 @@ FROM php:7.0-apache
|
||||
|
||||
ARG API_URL
|
||||
|
||||
ARG WIAAS_CUSTOMER_INTERFACE
|
||||
|
||||
ARG MYSQL_DATABASE
|
||||
ARG MYSQL_USER
|
||||
ARG MYSQL_PASSWORD
|
||||
@@ -37,8 +35,6 @@ 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
|
||||
@@ -51,9 +47,7 @@ COPY docker/php/setup.sh /init-scripts/
|
||||
RUN chmod +x /init-scripts/setup.sh
|
||||
|
||||
RUN docker-php-ext-install pdo pdo_mysql mysqli
|
||||
RUN a2enmod rewrite
|
||||
RUN a2enmod headers
|
||||
COPY docker/php/000-default.conf /etc/apache2/sites-available
|
||||
RUN a2enmod rewrite ssl
|
||||
|
||||
COPY backend /home/wiaas/backend
|
||||
|
||||
@@ -67,8 +61,8 @@ RUN cp -r backend/* /var/www/html/
|
||||
WORKDIR /var/www/html
|
||||
RUN ln -s ../html api
|
||||
|
||||
COPY docker/php/.htaccess /var/www/html/
|
||||
|
||||
|
||||
#RUN chown -R www-data:www-data /var/www/html
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
CMD /init-scripts/setup.sh
|
||||
|
||||
13
backend/.htaccess
Normal file
13
backend/.htaccess
Normal file
@@ -0,0 +1,13 @@
|
||||
# BEGIN WordPress
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteBase /
|
||||
RewriteRule ^index\.php$ - [L]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule . /index.php [L]
|
||||
RewriteCond %{HTTP:Authorization} ^(.*)
|
||||
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
|
||||
</IfModule>
|
||||
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
|
||||
# END WordPress
|
||||
@@ -1,21 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
.wc-order-preview footer {
|
||||
display: none;
|
||||
}
|
||||
@@ -30,9 +30,19 @@
|
||||
}
|
||||
|
||||
#wiaas_package_pricing_rules > .wiaas-pricing-rule {
|
||||
border:1px #dfdfdf solid;
|
||||
background-color:#fff;
|
||||
width: 95%;
|
||||
border-color:#dfdfdf;
|
||||
border-width:1px;
|
||||
border-style:solid;
|
||||
-moz-border-radius:3px;
|
||||
-khtml-border-radius:3px;
|
||||
-webkit-border-radius:3px;
|
||||
border-radius:3px;
|
||||
padding: 0;
|
||||
border-style:solid;
|
||||
border-spacing:0;
|
||||
background-color:#F9F9F9;
|
||||
margin-bottom: 12px;
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
#wiaas_package_pricing_rules > .wiaas-pricing-rule .section {
|
||||
@@ -110,25 +120,4 @@
|
||||
|
||||
#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';
|
||||
}
|
||||
|
||||
.wiaas-package-error {
|
||||
color: #a00 !important;
|
||||
}
|
||||
|
||||
table.wp-list-table .column-price {
|
||||
width: auto !important;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#posts-filter .tablenav .actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#menu-posts-product .wp-submenu li:last-child {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.woocommerce-BlankState .button {
|
||||
display: none !important
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
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,150 +0,0 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas-add-pricing").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var pay_type = $('#wiaas_pay_types').val();
|
||||
|
||||
if (! pay_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
|
||||
$("#wiaas_package_pricing_rules").data('setindex', set_index);
|
||||
|
||||
var data = {
|
||||
'pay_type': pay_type,
|
||||
action: 'create_empty_pricing_rule'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_pricing_rules').append(response);
|
||||
|
||||
$(`#wiaas_pay_type_${pay_type}`).prop( 'disabled', true );
|
||||
|
||||
$('#wiaas_pay_types').val('0');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//Remove Pricing Type
|
||||
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm('Are you sure you would like to remove this pay type?')) {
|
||||
var name = $(this).data('name');
|
||||
$('#wiaas-pricing-rule-' + name).slideUp().remove();
|
||||
|
||||
// append new option to controls
|
||||
$(`#wiaas_pay_type_${name}`).prop( 'disabled', false );
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var minimal_services_price = parseFloat($(this).val()) || 0;
|
||||
var principal_amount = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
|
||||
if (principal_amount_input) {
|
||||
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
|
||||
}
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
|
||||
var services_contract_period = $(this).data('period');
|
||||
if (services_contract_period > 0) {
|
||||
var final_services_price = minimal_services_price * services_contract_period;
|
||||
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var value = parseFloat($(this).val());
|
||||
var period = parseFloat($(this).data('period'));
|
||||
var interestRate = 0.58;
|
||||
|
||||
|
||||
var principal_amount = wiaasCalculateFinancing(interestRate, period, value);
|
||||
var minimal_services_price = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
|
||||
if (minimal_services_price_input) {
|
||||
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
|
||||
}
|
||||
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(0));
|
||||
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(0));
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_editor').delegate('#wiaas_pricing_rules_commision', 'change', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var value = parseInt($(this).val());
|
||||
|
||||
$('#wiaas_pricing_rules_commission_details').text('Commercial lead: ' + (100 - value) + ' %');
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_editor').delegate('#wiaas_pricing_rules_max_cost_margin', 'change', function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var value = parseFloat($(this).val());
|
||||
var total = parseFloat($(this).data('total'));
|
||||
|
||||
if (value > 0 && value < total) {
|
||||
$('#wiaas_pricing_rules_max_cost_margin_error').show();
|
||||
} else {
|
||||
$('#wiaas_pricing_rules_max_cost_margin_error').hide();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Copy of Excel's PMT function.
|
||||
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
|
||||
*
|
||||
* @param ratePerPeriod The interest rate for the loan.
|
||||
* @param numberOfPayments The total number of payments for the loan in months.
|
||||
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
|
||||
* Also known as the principal.
|
||||
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
|
||||
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
|
||||
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
|
||||
* 0 = At the end of period
|
||||
* 1 = At the beginning of the period
|
||||
* @returns {number}
|
||||
*/
|
||||
function wiaasCalculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
|
||||
/*var q = 0;
|
||||
var c = 0;
|
||||
const monthlyRatePerPeriod = ratePerPeriod / 12;
|
||||
|
||||
if (monthlyRatePerPeriod !== 0.0) {
|
||||
// Interest rate exists
|
||||
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
|
||||
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
|
||||
return c.toFixed(2);
|
||||
|
||||
} else if (numberOfPayments !== 0.0) {
|
||||
// No interest rate, but number of payments exists
|
||||
return -(futureValue + presentValue) / numberOfPayments;
|
||||
}
|
||||
|
||||
return 0;*/
|
||||
const rates = {
|
||||
24 : 4.282,
|
||||
30 : 3.451,
|
||||
36 : 2.896,
|
||||
42 : 2.500,
|
||||
48 : 2.223,
|
||||
54 : 2.025,
|
||||
60 : 1.834
|
||||
};
|
||||
|
||||
const interest = rates[numberOfPayments] || 10;
|
||||
|
||||
return presentValue * (interest / 100);
|
||||
}
|
||||
});
|
||||
@@ -1,11 +0,0 @@
|
||||
jQuery(document).ready(function($) {
|
||||
if ($('#product-type').val() === 'simple') {
|
||||
$('#general_product_data').find('.pricing').show();
|
||||
} else {
|
||||
$('#general_product_data').find('.pricing').hide();
|
||||
}
|
||||
|
||||
$('#general_product_data').find('.pricing').addClass('hide_if_wiaastemplate hide_if_bundle');
|
||||
$('#general_product_data').find('.pricing').removeClass('show_if_bundle show_if_wiaastemplate');
|
||||
|
||||
});
|
||||
@@ -1,23 +1,76 @@
|
||||
jQuery(function ($) {
|
||||
|
||||
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'),
|
||||
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'),
|
||||
|
||||
$template_categories = $('.wc-bundled-item',
|
||||
$template_categories_container_services,
|
||||
$template_categories_container_software,
|
||||
$template_categories_container_hardware,
|
||||
$template_categories_container_isntallation),
|
||||
$template_products = $('.wc-bundled-item',
|
||||
$template_products_container_services,
|
||||
$template_products_container_software,
|
||||
$template_products_container_hardware,
|
||||
$template_products_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'),
|
||||
template_category_objects = {},
|
||||
template_category_add_count = $template_categories.length;
|
||||
bundled_product_objects = {},
|
||||
bundled_products_add_count = $template_products.length,
|
||||
block_params = {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
};
|
||||
|
||||
$.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();
|
||||
@@ -28,50 +81,52 @@ jQuery(function ($) {
|
||||
$template_search_hardware
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedTemplateCategory('hardware', $template_search_hardware, $template_categories_container_hardware)
|
||||
addSearchedProduct('hardware', $template_search_hardware, $template_products_container_hardware)
|
||||
});
|
||||
|
||||
$template_search_software
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedTemplateCategory('software', $template_search_software, $template_categories_container_software)
|
||||
addSearchedProduct('software', $template_search_software, $template_products_container_software)
|
||||
});
|
||||
|
||||
|
||||
$template_search_installation
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedTemplateCategory('installation', $template_search_installation, $template_categories_container_isntallation)
|
||||
addSearchedProduct('services', $template_search_installation, $template_products_container_isntallation)
|
||||
});
|
||||
|
||||
|
||||
$template_search_services
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedTemplateCategory('services', $template_search_services, $template_categories_container_services)
|
||||
addSearchedProduct('installation', $template_search_services, $template_products_container_services)
|
||||
});
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
var template_category_title =search.text();
|
||||
|
||||
if (!template_category_id) {
|
||||
if (!bundled_product_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
search.val([]).change();
|
||||
|
||||
template_category_add_count++;
|
||||
$bundled_products_panel.block(block_params);
|
||||
|
||||
bundled_products_add_count++;
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_add_template_product',
|
||||
post_id: woocommerce_admin_meta_boxes.post_id,
|
||||
id: template_category_add_count,
|
||||
id: bundled_products_add_count,
|
||||
title: template_category_title,
|
||||
template_category_id: template_category_id,
|
||||
product_id: bundled_product_id,
|
||||
security: wc_bundles_admin_params.add_bundled_product_nonce,
|
||||
options: options,
|
||||
};
|
||||
@@ -85,11 +140,13 @@ jQuery(function ($) {
|
||||
container.append(response.markup);
|
||||
|
||||
var $added = $('.wiaas-template-item', container).last(),
|
||||
added_id = 'bundled_item_' + template_category_add_count;
|
||||
added_id = 'bundled_item_' + bundled_products_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);
|
||||
}
|
||||
@@ -104,6 +161,8 @@ jQuery(function ($) {
|
||||
}
|
||||
search.text('');
|
||||
|
||||
$bundled_products_panel.unblock();
|
||||
|
||||
});
|
||||
|
||||
}, 250);
|
||||
@@ -111,7 +170,7 @@ jQuery(function ($) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$template_categories_container_isntallation
|
||||
$template_products_container_isntallation
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -122,13 +181,15 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete template_category_objects[el_id];
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_categories_container_hardware
|
||||
$template_products_container_hardware
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -139,13 +200,15 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete template_category_objects[el_id];
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_categories_container_software
|
||||
$template_products_container_software
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -156,13 +219,15 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete template_category_objects[el_id];
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_categories_container_services
|
||||
$template_products_container_services
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -173,7 +238,9 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete template_category_objects[el_id];
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_CL_Customers
|
||||
*/
|
||||
class Wiaas_Admin_CL_Customers {
|
||||
|
||||
/**
|
||||
* Displays table list of customers that are linked to commercial lead
|
||||
*
|
||||
* Enables commercial lead to update default order type for his shop
|
||||
*
|
||||
* Enables commercial lead to update order type for specific shop customer
|
||||
*
|
||||
*/
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'admin_menu', array( __CLASS__, 'add_customers_page' ), 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add customer menu page for commercial lead
|
||||
*/
|
||||
public static function add_customers_page() {
|
||||
add_menu_page(
|
||||
__( 'Customers', 'wiaas' ),
|
||||
__( 'Customers', 'wiaas' ),
|
||||
'manage_wiaas_cl_customers',
|
||||
'wiaas-cl-customers',
|
||||
array(__CLASS__, 'output_customers'),
|
||||
'dashicons-groups',
|
||||
'66.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content for customer menu page
|
||||
*/
|
||||
public static function output_customers() {
|
||||
$organization_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
// handle default order type update if needed
|
||||
if (! empty($_POST['wiaas_update_cl_default_order_type_nonce']) &&
|
||||
! empty($_POST['default_order_type']) &&
|
||||
wp_verify_nonce(
|
||||
$_POST['wiaas_update_cl_default_order_type_nonce'],
|
||||
'wiaas_update_cl_default_order_type')
|
||||
) {
|
||||
|
||||
$default_order_type = sanitize_key($_POST['default_order_type']);
|
||||
|
||||
Wiaas_Shop::update_default_order_type($organization_id, $default_order_type);
|
||||
|
||||
}
|
||||
|
||||
// handle customer order type update if needed
|
||||
if (! empty($_POST['wiaas_update_cl_customer_order_type_nonce']) &&
|
||||
! empty($_POST['customer_order_type']) &&
|
||||
wp_verify_nonce(
|
||||
$_POST['wiaas_update_cl_customer_order_type_nonce'],
|
||||
'wiaas_update_cl_customer_order_type')
|
||||
) {
|
||||
|
||||
$customer_id = absint($_POST['customer_order_type']['customer_id']);
|
||||
$order_type = sanitize_key($_POST['customer_order_type']['order_type']);
|
||||
|
||||
Wiaas_Shop::update_shop_customer_order_type(
|
||||
$organization_id,
|
||||
$customer_id,
|
||||
$order_type);
|
||||
}
|
||||
|
||||
$customers = Wiaas_Shop::get_shop_customers($organization_id);
|
||||
|
||||
require 'views/html-admin-cl-customers-page.php';
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL_Customers::init();
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_CL_Orders
|
||||
*/
|
||||
class Wiaas_Admin_CL_Orders {
|
||||
|
||||
/**
|
||||
* Displays list of orders from commercial lead owned shop
|
||||
*
|
||||
* Enables quick preview of each order
|
||||
*
|
||||
* This list of orders is achieved with customization of default order list for `shop_order` post
|
||||
* by using hooks and filters to allow only data that commercial lead should be able to see
|
||||
*
|
||||
*/
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter( 'bulk_actions-edit-shop_order', array( __CLASS__, 'remove_bulk_actions_for_list_table_orders' ), 999 );
|
||||
|
||||
add_filter('woocommerce_admin_order_preview_actions', array(__CLASS__, 'remove_actions_from_order_preview'));
|
||||
|
||||
add_filter('woocommerce_admin_order_preview_line_items', array(__CLASS__, 'filter_order_items_for_order_preview'), 10, 2);
|
||||
|
||||
add_filter('manage_shop_order_posts_columns', array(__CLASS__, 'columns_for_list_table_orders'), 999);
|
||||
|
||||
add_filter( 'manage_edit-shop_order_sortable_columns', array( __CLASS__, 'define_sortable_columns_for_list_table_orders' ) );
|
||||
|
||||
add_action('manage_shop_order_posts_custom_column', array(__CLASS__, 'render_columns_for_list_table_orders'), 999, 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all bulk actions for commercial lead
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function remove_bulk_actions_for_list_table_orders() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove actions from shop order preview modal so only data info is visible
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function remove_actions_from_order_preview() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show only packages on order preview
|
||||
*
|
||||
* @param $order_items
|
||||
* @param $order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_order_items_for_order_preview($order_items, $order) {
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ($order_items as $order_item) {
|
||||
if (isset($order_item['wiaas_standard_package'])) {
|
||||
$items[] = $order_item;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override default table columns so only commercial lead specific columns are visible
|
||||
*
|
||||
* @param $columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function columns_for_list_table_orders($columns) {
|
||||
$show_columns = array();
|
||||
$show_columns['cb'] = $columns['cb'];
|
||||
$show_columns['_wiaas_order_number'] = __( 'Order', 'woocommerce' );
|
||||
$show_columns['order_date'] = __( 'Date', 'woocommerce' );
|
||||
$show_columns['order_status'] = __( 'Status', 'woocommerce' );
|
||||
$show_columns['order_total'] = __( 'Total', 'woocommerce' );
|
||||
|
||||
return $show_columns;
|
||||
}
|
||||
|
||||
|
||||
/** Append commercial lead columns to table sortable columns
|
||||
*
|
||||
* @param $sortable_columns
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function define_sortable_columns_for_list_table_orders($sortable_columns) {
|
||||
|
||||
$sortable_columns['_wiaas_order_number'] = 'ID';
|
||||
|
||||
return $sortable_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render commercial lead specific columns
|
||||
*
|
||||
* @param $column
|
||||
* @param $order_id
|
||||
*/
|
||||
public static function render_columns_for_list_table_orders($column, $order_id) {
|
||||
|
||||
if ($column === '_wiaas_order_number') {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
echo '<strong>#' . esc_attr( $order->get_order_number() ) . '</strong>';
|
||||
|
||||
if ( $order->get_status() !== 'trash' ) {
|
||||
echo '<a href="#" class="order-preview" data-order-id="' . absint( $order->get_id() ) . '" title="' . esc_attr( __( 'Preview', 'wiaas' ) ) . '">' . esc_html( __( 'Preview', 'wiaas' ) ) . '</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL_Orders::init();
|
||||
@@ -1,259 +0,0 @@
|
||||
<?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') {
|
||||
|
||||
$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-product_tag'] = __( 'Reference', 'wiaas' );
|
||||
$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();
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
select {
|
||||
width: 300px;
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( 'Customers', 'wiaas' ); ?> </h1>
|
||||
|
||||
<br class="clear" />
|
||||
<div id="col-container">
|
||||
|
||||
<div id="col-right">
|
||||
<div class="col-wrap">
|
||||
<table class="widefat wp-list-table striped" style="width:100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php esc_html_e( 'Name', 'wiaas' ); ?></th>
|
||||
<th scope="col"><?php esc_html_e( 'Order type', 'wiaas' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($customers as $customer) {
|
||||
$name = wiaas_get_organization_name($customer['customer_id']);
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<h2><?php esc_html_e($name, 'wiaas') ?></h2>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e(
|
||||
$customer['order_type']=== 'commercial_lead' ? 'Commercial Lead' : 'Reseller',
|
||||
'wiaas'
|
||||
)
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="col-left">
|
||||
<div class="col-wrap">
|
||||
<div class="inside">
|
||||
<div class="form-wrap">
|
||||
<h2><?php esc_html_e('Default order type:', 'wiaas') ?></h2>
|
||||
<form class="form" action="" method="post">
|
||||
<input type="hidden" name="page" value="wiaas-cl-customers"/>
|
||||
<div class="form-field">
|
||||
<select class="form-control" name="default_order_type">
|
||||
<option
|
||||
value="commercial_lead"
|
||||
<?php selected('commercial_lead', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
|
||||
>
|
||||
<?php esc_html_e('Commercial Lead', 'wiaas') ?>
|
||||
</option>
|
||||
<option
|
||||
value="reseller"
|
||||
<?php selected('reseller', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
|
||||
>
|
||||
<?php esc_html_e('Reseller', 'wiaas') ?>
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<input class="button button-primary button-large" type="submit" value="Change"/>
|
||||
<?php wp_nonce_field( 'wiaas_update_cl_default_order_type', 'wiaas_update_cl_default_order_type_nonce' ); ?>
|
||||
</form>
|
||||
</div>
|
||||
<hr style="margin: 30px 0;" />
|
||||
|
||||
<div class="form-wrap">
|
||||
<h2><?php esc_html_e('Update order type for customer', 'wiaas') ?></h2>
|
||||
<form class="form" action="" method="post">
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e('Customer:', 'wiaas') ?> </label>
|
||||
<select class="form-control" name="customer_order_type[customer_id]">
|
||||
<?php
|
||||
foreach ($customers as $customer) {
|
||||
$name = wiaas_get_organization_name($customer['customer_id']);
|
||||
?>
|
||||
<option
|
||||
value="<?php esc_html_e($customer['customer_id'], 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($name, 'wiaas') ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e('Order type:', 'wiaas') ?> </label>
|
||||
<select class="form-control" name="customer_order_type[order_type]">
|
||||
<option value="commercial_lead">
|
||||
<?php esc_html_e('Commercial Lead', 'wiaas') ?>
|
||||
</option>
|
||||
<option value="reseller">
|
||||
<?php esc_html_e('Reseller', 'wiaas') ?>
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<input class="button button-large" type="submit" value="Update"/>
|
||||
<?php wp_nonce_field( 'wiaas_update_cl_customer_order_type', 'wiaas_update_cl_customer_order_type_nonce' ); ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
@@ -1,237 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,162 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,31 +0,0 @@
|
||||
<?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();
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?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() {
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
$role = $current_user->roles[0];
|
||||
|
||||
$is_cl = $role === 'commercial_lead';
|
||||
|
||||
if ($is_cl) {
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-customers.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-orders.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();
|
||||
@@ -1,14 +0,0 @@
|
||||
<?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();
|
||||
@@ -6,6 +6,7 @@ class Wiaas_Admin_Order_Projects {
|
||||
// Add admin page and subpage since woocommerce orders have custom menu page
|
||||
// so this will not be automatic
|
||||
add_filter('admin_menu', array(__CLASS__, 'add_admin_page'));
|
||||
add_action( 'parent_file', array(__CLASS__, 'highlight_order_projects_parent_menu') );
|
||||
|
||||
// Add is available fields to create and edit forms
|
||||
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
|
||||
@@ -32,6 +33,19 @@ class Wiaas_Admin_Order_Projects {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Correctly highlight parent menu page when order projects submenu is selected
|
||||
* @param $parent_file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function highlight_order_projects_parent_menu($parent_file) {
|
||||
if ( get_current_screen()->taxonomy == 'shop_order_project' ) {
|
||||
$parent_file = 'woocommerce';
|
||||
}
|
||||
return $parent_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add is available field to order project creation form
|
||||
*/
|
||||
|
||||
@@ -1,246 +0,0 @@
|
||||
<?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);
|
||||
|
||||
// hide woocommerce meta fields form customer user profile
|
||||
add_filter('woocommerce_customer_meta_fields', array(__CLASS__, 'hide_woocommerce_customer_fields'));
|
||||
|
||||
// save related customers when organization form data has been saved by acf
|
||||
add_action('acf/save_post', array(__CLASS__, 'maybe_save_related_customers'), 999);
|
||||
|
||||
// load related customers for organization form
|
||||
add_filter('acf/load_value/name=_wiaas_organization_customers', array(__CLASS__, 'load_related_customer_organizations'), 10, 3);
|
||||
|
||||
// retrieve only customer organizations as options to link to commercial lead
|
||||
add_filter('acf/fields/taxonomy/query/name=_wiaas_organization_customers', array(__CLASS__, 'filter_customer_organizations'));
|
||||
}
|
||||
|
||||
public static function hide_woocommerce_customer_fields() {
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function hide_users_table_list_navigation() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve only customer organization as options to link customers to commercial lead
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_customer_organizations($args) {
|
||||
|
||||
$args['meta_key'] = '_wiaas_organization_roles';
|
||||
$args['meta_value'] = 'customer';
|
||||
$args['meta_compare'] = 'LIKE';
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves related customers if organization new/edit form has been submited
|
||||
* Customer ids are collected from posted data of linked customers acf field and saved
|
||||
*
|
||||
* @param string $id in format `term_{$organization_id}`
|
||||
*/
|
||||
public static function maybe_save_related_customers($id) {
|
||||
if ($_POST['taxonomy'] === Wiaas_User_Organization::TAXONOMY_NAME && ! empty($_POST['acf'])) {
|
||||
|
||||
$field = get_field_object('_wiaas_organization_customers', $id);
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
if (!$id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$customer_organization_ids = $_POST['acf'][$field['key']];
|
||||
|
||||
$customer_organization_ids = is_array($customer_organization_ids) ?
|
||||
wp_parse_id_list($customer_organization_ids) :
|
||||
array();
|
||||
|
||||
Wiaas_Shop::set_shop_customers($id, $customer_organization_ids);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads related customers for linked customers acf field on organization edit form
|
||||
*
|
||||
* @param array $value
|
||||
* @param string $id in format `term_{$organization_id}`
|
||||
* @param array $field acf field details
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function load_related_customer_organizations($value, $id, $field) {
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
$customers = wp_list_pluck(
|
||||
Wiaas_Shop::get_shop_customers($id),
|
||||
'customer_id');
|
||||
|
||||
return $customers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,45 +7,15 @@ 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';
|
||||
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ), 1 );
|
||||
|
||||
add_action( 'manage_product_posts_columns', array( __CLASS__, 'manage_list_table_products_columns' ), 999, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide default WC_Product data panels.
|
||||
*
|
||||
* @param array $tabs
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function package_data_tabs($tabs) {
|
||||
|
||||
$tabs['general']['class'] = array( 'show_if_simple', 'show_if_bundle');
|
||||
|
||||
unset($tabs['attribute']);
|
||||
unset($tabs['variations']);
|
||||
unset($tabs['advanced']);
|
||||
unset($tabs['shipping']);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize list table product columns
|
||||
*
|
||||
* @param array $columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_list_table_products_columns($columns) {
|
||||
$columns['product_tag'] = __( 'Reference', 'wiaas' );
|
||||
|
||||
return $columns;
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('acf/save_post', array(__CLASS__, 'wiaas_my_save_post'), 20, 1);
|
||||
add_action('woocommerce_after_register_post_type', array(__CLASS__, 'wiaas_register_product_status'));
|
||||
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'wiaas_modify_product'));
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'wiaas_maybe_remove_metaboxes'), 999);
|
||||
add_filter('wp_insert_post_data', array(__CLASS__, 'wiaas_maybe_set_no_country_status'), 999, 2);
|
||||
add_action('acf/render_field/type=taxonomy', array(__CLASS__, 'wiaas_render_field'), 10, 1);
|
||||
|
||||
}
|
||||
|
||||
public static function wiaas_modify_product($args) {
|
||||
$args['supports'] = array('title');
|
||||
return $args;
|
||||
}
|
||||
|
||||
public static function wiaas_register_product_status() {
|
||||
register_post_status('_wiaas_no_country', array(
|
||||
'label' => _x('No Country', 'Product status', 'wiaas'),
|
||||
'public' => false,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => false,
|
||||
'show_in_admin_status_list' => false,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
public static function wiaas_render_field($field) {
|
||||
|
||||
if ($field['_name'] === '_wiaas_product_country') {
|
||||
?>
|
||||
<div id="submitpost" style="padding: 20px;">
|
||||
<input style="float:right;" name="save" id="save-post" class="button" type="submit" value="Choose"/>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function wiaas_maybe_remove_metaboxes() {
|
||||
$screen = get_current_screen();
|
||||
$screen_id = $screen ? $screen->id : '';
|
||||
|
||||
if ($screen_id !== 'product') {
|
||||
return;
|
||||
}
|
||||
global $post;
|
||||
|
||||
$post_id = $post->ID;
|
||||
|
||||
if ($post_id === 0 ||
|
||||
($post->post_status !== 'publish' && !(Wiaas_Countries::get_package_country(wc_get_product($post_id))))) {
|
||||
|
||||
remove_meta_box('woocommerce-product-data', 'product', 'normal');
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('slugdiv', 'product', 'normal');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
|
||||
remove_meta_box('postexcerpt', 'product', 'normal');
|
||||
remove_meta_box('template_product_meta_box', 'product', 'normal');
|
||||
remove_meta_box('postimagediv', 'product', 'normal');
|
||||
remove_meta_box('woocommerce-product-images', 'product', 'normal');
|
||||
remove_meta_box('wc-jetpack-product_by_user_role', 'product', 'normal');
|
||||
|
||||
|
||||
remove_meta_box('groups-permissions', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-product_tag', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-template_category', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-supplier', 'product', 'side');
|
||||
remove_meta_box('postimagediv', 'product', 'side');
|
||||
remove_meta_box('woocommerce-product-images', 'product', 'side');
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
remove_meta_box('wiaas_upload_and_link_document', 'product', 'side');
|
||||
remove_meta_box('radio-tagsdiv-product_country', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-_wiaas_shop_prices', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-wiaas_units', 'product', 'side');
|
||||
}
|
||||
|
||||
//Always hide product category, it is added wit advanced custom fields plugin for simple product
|
||||
remove_meta_box('radio-product_catdiv', 'product', 'side');
|
||||
|
||||
}
|
||||
|
||||
public static function wiaas_maybe_set_no_country_status($data, $postarr) {
|
||||
if ($postarr['post_type'] === 'product' && (!isset($postarr['ID']) || !$postarr['ID'])) {
|
||||
$data['post_status'] = '_wiaas_no_country';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for post status and and if there is country available
|
||||
* Set post status to draft if the country is added
|
||||
*
|
||||
* @param $post_id
|
||||
*/
|
||||
|
||||
public static function wiaas_my_save_post($post_id) {
|
||||
|
||||
global $post;
|
||||
$status = get_post_status( $post->ID);
|
||||
|
||||
$value = get_field('_wiaas_product_country', $post_id, true);
|
||||
$type = get_field('_wiaas_product_type', $post_id, true);
|
||||
|
||||
|
||||
if (!empty($value) && $status === '_wiaas_no_country' ) {
|
||||
|
||||
wp_set_object_terms($post_id, $value, 'product_country', true);
|
||||
wp_set_object_terms($post_id, $type, 'product_type', true);
|
||||
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'draft'
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product::init();
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Simple_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/simple-product/class-wiaas-admin-product-additional-info.php';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Simple_Product::init();
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
<?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();
|
||||
@@ -1,78 +0,0 @@
|
||||
<?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();
|
||||
@@ -1,51 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,258 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,87 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,84 +0,0 @@
|
||||
<?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>
|
||||
@@ -1,105 +0,0 @@
|
||||
<?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,6 +28,20 @@ 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>
|
||||
|
||||
@@ -11,63 +11,12 @@ class Wiaas_Admin_Package_Pricing {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'admin_menu', array(__CLASS__, 'add_package_pricing_editor_page') );
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
|
||||
add_action( 'wp_ajax_create_empty_pricing_rule', array(__CLASS__, 'create_empty_pricing_rule') );
|
||||
|
||||
add_action('woocommerce_product_options_general_product_data', array(__CLASS__, 'render_edit_prices_link'));
|
||||
|
||||
add_filter('woocommerce_bundle_price_html', array( __CLASS__, 'get_package_price_html' ), 10, 2);
|
||||
}
|
||||
|
||||
public static function get_package_price_html($price_html, $package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
|
||||
$recurring_price = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
if ($product_price['is_recurring']) {
|
||||
$recurring_price += $product_price['price'] * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
|
||||
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-package_price_editor&id=' . absint( $package->get_id() ) );
|
||||
|
||||
$price_html = 'Fixed: ' . $price_html . ' and ' . $recurring_price . ' / month' .
|
||||
' <br> <a class="button button-link" href="' . esc_url($edit_link) .'" target="_blank">Edit price<a>';
|
||||
|
||||
return $price_html;
|
||||
}
|
||||
|
||||
public static function render_edit_prices_link() {
|
||||
global $post;
|
||||
|
||||
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-package_price_editor&id=' . absint( $post->ID ) );
|
||||
|
||||
?>
|
||||
<div class="options_group hide_if_simple hide_if_wiaastemplate">
|
||||
<p>
|
||||
<a href="<?php echo esc_url($edit_link) ?>" target="_blank">
|
||||
<span>Edit prices</span>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function add_package_pricing_editor_page() {
|
||||
|
||||
add_submenu_page(
|
||||
'edit.php?post_type=product',
|
||||
__( 'Edit prices', 'wiaas' ),
|
||||
null,
|
||||
'create_products',
|
||||
'wiaas-package_price_editor',
|
||||
array(__CLASS__, 'package_pricing_editor')
|
||||
);
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,84 +33,47 @@ class Wiaas_Admin_Package_Pricing {
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderes wiaas pricing tab content for package
|
||||
* Registers wiaas pricing tab for package data
|
||||
* @param $tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function package_pricing_editor() {
|
||||
public static function package_data_tabs($tabs) {
|
||||
$tabs[ 'bundled_packages_price' ] = array(
|
||||
'label' => __( 'Pricing', 'wiaas' ),
|
||||
'target' => 'wiaas_package_price',
|
||||
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
|
||||
'priority' => 50
|
||||
);
|
||||
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_script('admin_package_edit_prices', $plugin_url . '/assets/js/wiaas-admin-package-edit-prices.js');
|
||||
|
||||
$package_id = absint($_GET['id']);
|
||||
$package = wc_get_product( $package_id );
|
||||
|
||||
if (empty($package) || $package->get_type() !== 'bundle') {
|
||||
return;
|
||||
}
|
||||
|
||||
// save prices
|
||||
if (! empty($_POST['wiaas_save_package_prices_nonce']) &&
|
||||
wp_verify_nonce($_POST['wiaas_save_package_prices_nonce'], 'wiaas_save_package_prices')) {
|
||||
self::_save_posted_package_prices($package_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);
|
||||
|
||||
// collect package bundle items pricing info to display
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$bundled_items_per_category = array();
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
|
||||
if ($product_cat === 'hardware' || $product_cat === 'software') {
|
||||
$product_cat = 'product';
|
||||
}
|
||||
|
||||
$bundled_items_per_category[$product_cat] ?: array( );
|
||||
|
||||
$bundled_items_per_category[$product_cat][] = $bundled_item;
|
||||
|
||||
|
||||
}
|
||||
|
||||
include 'views/html-package-pricing-page.php';
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderes wiaas pricing tab content for package
|
||||
*/
|
||||
public static function package_data_panel() {
|
||||
|
||||
// PRIVATE HELPERS
|
||||
global $post;
|
||||
$package = wc_get_product( $post->ID );
|
||||
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
|
||||
$minimum_cost_margin = Wiaas_Package_Pricing::get_package_minimum_cost_margin($package);
|
||||
|
||||
include 'views/html-package-pricing.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Save posted package pricing information
|
||||
*
|
||||
* @param int $package_id
|
||||
* Saves posted package pricing rules
|
||||
* @param $post_id
|
||||
* @param $post
|
||||
*/
|
||||
private static function _save_posted_package_prices($package_id) {
|
||||
$commission = wp_unslash($_POST['wiaas_pricing_rules_commision']);
|
||||
$max_cost_margin = wp_unslash($_POST['wiaas_max_cost_margin']);
|
||||
$pricing_rules = array();
|
||||
|
||||
$posted_pricing_rules = isset($_POST['wiaas_pricing_rules']) ? wp_unslash($_POST['wiaas_pricing_rules']) : array();
|
||||
|
||||
foreach ($posted_pricing_rules as $rule_type => $posted_prices) {
|
||||
|
||||
$posted_prices = wp_unslash($posted_prices);
|
||||
$prices = array();
|
||||
|
||||
foreach ($posted_prices as $posted_price_type => $posted_price) {
|
||||
$prices[sanitize_key($posted_price_type)] = wp_unslash($posted_price);
|
||||
}
|
||||
|
||||
$pricing_rules[sanitize_key($rule_type)] = $prices;
|
||||
}
|
||||
|
||||
public function process_meta_box( $post_id, $post ) {
|
||||
Wiaas_Package_Pricing::set_package_prices(
|
||||
wc_get_product( $package_id ),
|
||||
$pricing_rules,
|
||||
$commission,
|
||||
$max_cost_margin);
|
||||
wc_get_product( $post_id ),
|
||||
$_POST['wiaas_pricing_rules'],
|
||||
$_POST['wiaas_pricing_rules_commision'],
|
||||
$_POST['wiaas_minimum_cost_margin']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,277 +0,0 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<style>
|
||||
table tr:not(.wiaas-package-price) td:not(:first-child) {
|
||||
text-align: center;
|
||||
vertical-align: middle; !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="wiaas_package_pricing_editor" class="wrap">
|
||||
|
||||
<h1>
|
||||
<?php
|
||||
esc_html_e($package->get_title(), 'wiaas');
|
||||
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
if (! empty($country)) {
|
||||
|
||||
esc_html_e(' (sold in ' . $country['name'] . ')', 'wiaas');
|
||||
}
|
||||
?>
|
||||
</h1>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<div id="col-container">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
|
||||
<div id="col-right">
|
||||
|
||||
<div class="col-wrap">
|
||||
|
||||
<div class="inside">
|
||||
|
||||
<table class="widefat">
|
||||
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
$products_total_cost = 0;
|
||||
$one_time_services_cost = 0;
|
||||
$recurring_services_cost = 0;
|
||||
$installation_cost = 0;
|
||||
|
||||
foreach ($bundled_items_per_category as $cat => $items) {
|
||||
|
||||
?>
|
||||
<tr style="background: #F5F5F5;">
|
||||
<td colspan="4">
|
||||
<strong style="text-transform: uppercase;">
|
||||
<?php esc_html_e($cat . ' (' . count($items) . ')', 'wiaas') ?>
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
foreach ($items as $item) {
|
||||
$product = $item->product;
|
||||
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<span>
|
||||
<?php esc_html_e($item->get_quantity(), 'wiaas') ?>
|
||||
x
|
||||
<?php esc_html_e($product->get_title(), 'wiaas') ?>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e(
|
||||
$total_cost * $item->get_quantity(),
|
||||
'wiaas')
|
||||
?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e(
|
||||
$total_cost . ' per unit',
|
||||
'wiaas');
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
if ($product_price['is_recurring']) {
|
||||
esc_html_e(
|
||||
$product_price['price'] . ' / month for ' . $product_price['pay_period'] . ' months',
|
||||
'wiaas');
|
||||
|
||||
} else {
|
||||
|
||||
echo '-';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<tr class="wiaas-package-price">
|
||||
<td style="border-top: 1px solid #e5e5e5;"></td>
|
||||
<td colspan="3" style="border-top: 1px solid #e5e5e5;">
|
||||
<strong>
|
||||
<?php
|
||||
|
||||
if ($cat === 'product') {
|
||||
|
||||
$products_total_cost = wiaas_get_package_hardware_procurement_cost($package) +
|
||||
wiaas_get_package_software_procurement_cost($package);
|
||||
|
||||
esc_html_e('Total: ' . $products_total_cost, 'wiaas');
|
||||
}
|
||||
|
||||
if ($cat === 'service') {
|
||||
|
||||
$one_time_services_cost = wiaas_get_package_one_time_services_procurement_cost($package);
|
||||
|
||||
$recurring_services_cost = wiaas_get_package_recurring_services_procurement_cost($package);
|
||||
|
||||
esc_html_e('One time services: ' . $one_time_services_cost, 'wiaas');
|
||||
|
||||
echo '<br>';
|
||||
|
||||
esc_html_e('Recurring services: ' . $recurring_services_cost . ' / month ', 'wiaas');
|
||||
}
|
||||
|
||||
if ($cat === 'installation') {
|
||||
|
||||
$installation_cost = wiaas_get_package_installation_procurement_cost($package);
|
||||
|
||||
esc_html_e('Installation: ' . $installation_cost, 'wiaas');
|
||||
}
|
||||
?>
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
|
||||
<tfoot>
|
||||
<tr class="wiaas-package-price">
|
||||
<td>
|
||||
<h4>TOTAL COST :</h4>
|
||||
</td>
|
||||
<td colspan="3">
|
||||
<strong>Fixed: <?php esc_html_e($products_total_cost + $one_time_services_cost + $installation_cost)?></strong>
|
||||
<br>
|
||||
<strong>Recurring: <?php esc_html_e($recurring_services_cost)?> / month</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="col-left">
|
||||
|
||||
<div class="col-wrap">
|
||||
<div class="form-wrap">
|
||||
|
||||
<h2><?php esc_html_e('Set package prices', 'wiaas') ?></h2>
|
||||
|
||||
<form action="" method="post">
|
||||
|
||||
<input type="hidden" name="page" value="wiaas-package_price_editor">
|
||||
<input type="hidden" name="id" value="<?php esc_attr_e($package->get_id(), 'wiaas') ?>">
|
||||
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e('Max cost margin:', 'wiaas') ?></label>
|
||||
<input
|
||||
id="wiaas_pricing_rules_max_cost_margin"
|
||||
name="wiaas_max_cost_margin"
|
||||
type="number"
|
||||
min="0"
|
||||
value="<?php esc_attr_e($max_cost_margin, 'wiaas') ?>"
|
||||
data-total="<?php esc_attr_e(Wiaas_Pricing::get_package_total_cost($package), 'wiaas') ?>"
|
||||
>
|
||||
|
||||
<p
|
||||
id="wiaas_pricing_rules_max_cost_margin_error"
|
||||
<?php if(Wiaas_Package_Status::get_package_status($package->get_id()) !== Wiaas_Package_Status::INVALID_MARGIN) echo 'style="display: none;"' ?>
|
||||
class="wiaas-package-error"
|
||||
>The total costs are greater than the package max margin!</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e('Commision ( % ):', 'wiaas') ?></label>
|
||||
<input
|
||||
id="wiaas_pricing_rules_commision"
|
||||
name="wiaas_pricing_rules_commision"
|
||||
type="number"
|
||||
value="<?php esc_attr_e($commission, 'wiaas') ?>"
|
||||
min="0" max="100"
|
||||
>
|
||||
<p id="wiaas_pricing_rules_commission_details">
|
||||
<?php esc_html_e('Commercial lead: ' . (100 - $commission) .'%', 'wiaas') ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
|
||||
<div class="wrap">
|
||||
|
||||
<select id="wiaas_pay_types" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<option selected value="0" disabled> Select payment type ...</option>
|
||||
|
||||
<?php
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
$is_added = ! empty( $pricing_rules[$name])
|
||||
?>
|
||||
<option
|
||||
value="<?php esc_attr_e($name, 'wiaas') ?>"
|
||||
id="wiaas_pay_type_<?php esc_attr_e($name, 'wiaas') ?>"
|
||||
<?php disabled($is_added, true, true) ?>
|
||||
>
|
||||
<?php esc_html_e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_package_pricing_rules">
|
||||
|
||||
<?php
|
||||
require 'html-package-pricing-rules-list.php';
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php wp_nonce_field( 'wiaas_save_package_prices', 'wiaas_save_package_prices_nonce' ); ?>
|
||||
|
||||
<input type="submit" value="Save" class="button button-primary button-large">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -6,7 +6,13 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
<?php
|
||||
|
||||
$value = $pricing_rule['minimal_recurrent_price'];
|
||||
$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']);
|
||||
}
|
||||
|
||||
?>
|
||||
<tr>
|
||||
|
||||
@@ -8,7 +8,7 @@ $available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ( $pricing_rules as $name => $pricing_rule ) {
|
||||
$pay_type = $available_pay_types[$name];
|
||||
?>
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule form-field">
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule">
|
||||
<div class="section">
|
||||
<h4 class="first"><?php echo $pay_type['title']; ?>
|
||||
<a href="#" data-name="<?php echo $name; ?>"
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_package_price" class="panel woocommerce_options_panel">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas-add-pricing").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
|
||||
$("#wiaas_package_pricing_rules").data('setindex', set_index);
|
||||
|
||||
var pay_type = $('#wiaas_pay_type').val();
|
||||
|
||||
var data = {
|
||||
'pay_type': pay_type,
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'create_empty_pricing_rule'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_pricing_rules').append(response);
|
||||
|
||||
$(`#wiaas_pay_type_${pay_type}`).addClass('wiaas_hidden');
|
||||
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 0) {
|
||||
$('#wiaas_package_price_controls').addClass('wiaas_hidden');
|
||||
} else {
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//Remove Pricing Type
|
||||
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this pay type?', 'wiaas' ); ?>")) {
|
||||
var name = $(this).data('name');
|
||||
$('#wiaas-pricing-rule-' + name).slideUp().remove();
|
||||
|
||||
// append new option to controls
|
||||
$(`#wiaas_pay_type_${name}`).removeClass('wiaas_hidden');
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 1) {
|
||||
$('#wiaas_package_price_controls').removeClass('wiaas_hidden');
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var minimal_services_price = parseFloat($(this).val()) || 0;
|
||||
var principal_amount = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
|
||||
if (principal_amount_input) {
|
||||
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
|
||||
}
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
|
||||
var services_contract_period = $(this).data('period');
|
||||
if (services_contract_period > 0) {
|
||||
var final_services_price = minimal_services_price * services_contract_period;
|
||||
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var value = parseFloat($(this).val());
|
||||
var period = parseFloat($(this).data('period'));
|
||||
var interestRate = 0.58;
|
||||
|
||||
|
||||
var principal_amount = calculateFinancing(interestRate, period, value);
|
||||
var minimal_services_price = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
|
||||
if (minimal_services_price_input) {
|
||||
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
|
||||
}
|
||||
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(0));
|
||||
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(0));
|
||||
});
|
||||
|
||||
/**
|
||||
* Copy of Excel's PMT function.
|
||||
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
|
||||
*
|
||||
* @param ratePerPeriod The interest rate for the loan.
|
||||
* @param numberOfPayments The total number of payments for the loan in months.
|
||||
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
|
||||
* Also known as the principal.
|
||||
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
|
||||
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
|
||||
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
|
||||
* 0 = At the end of period
|
||||
* 1 = At the beginning of the period
|
||||
* @returns {number}
|
||||
*/
|
||||
function calculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
|
||||
/*var q = 0;
|
||||
var c = 0;
|
||||
const monthlyRatePerPeriod = ratePerPeriod / 12;
|
||||
|
||||
if (monthlyRatePerPeriod !== 0.0) {
|
||||
// Interest rate exists
|
||||
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
|
||||
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
|
||||
return c.toFixed(2);
|
||||
|
||||
} else if (numberOfPayments !== 0.0) {
|
||||
// No interest rate, but number of payments exists
|
||||
return -(futureValue + presentValue) / numberOfPayments;
|
||||
}
|
||||
|
||||
return 0;*/
|
||||
const rates = {
|
||||
24 : 4.282,
|
||||
30 : 3.451,
|
||||
36 : 2.896,
|
||||
42 : 2.500,
|
||||
48 : 2.223,
|
||||
54 : 2.025,
|
||||
60 : 1.834
|
||||
};
|
||||
|
||||
const interest = rates[numberOfPayments] || 10;
|
||||
|
||||
return presentValue * (interest / 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_minimum_cost_margin',
|
||||
'name' => 'wiaas_minimum_cost_margin',
|
||||
'value' => $minimum_cost_margin,
|
||||
'label' => __( 'Minimum cost margin:', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_price_commision',
|
||||
'name' => 'wiaas_pricing_rules_commision',
|
||||
'value' => $commission,
|
||||
'label' => __( 'Commision (Percent):', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<div class="wc-metaboxes-wrapper">
|
||||
<?php
|
||||
$has_available_pay_types = false;
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
if (!isset($pricing_rule_sets[$name])) {
|
||||
$has_available_pay_types = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$class = $has_available_pay_types ? '' : 'wiaas_hidden';
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price_controls" class="toolbar toolbar-top <?php echo $class ?>">
|
||||
<select id="wiaas_pay_type" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<?php
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
?>
|
||||
<option
|
||||
value="<?php echo $name ?>"
|
||||
id="wiaas_pay_type_<?php echo $name ?>"
|
||||
class="<?php echo $class ?>"
|
||||
>
|
||||
<?php _e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button button-primary">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_package_pricing_rules" class="wc-metaboxes">
|
||||
<?php
|
||||
require 'html-package-pricing-rules-list.php';
|
||||
?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,13 +4,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();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_checkbox(
|
||||
array(
|
||||
'id' => '_wiaas_recurring_price',
|
||||
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
|
||||
'data_type' => 'price',
|
||||
'label' => __( 'Is recurring?', 'wiaas' ),
|
||||
'label' => __( $product->get_category_ids()[0], 'wiaas' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product_Additional_Info {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_product_options_general_product_data', array(__CLASS__, 'display_additional_fields'));
|
||||
add_action('woocommerce_process_product_meta', array(__CLASS__, 'save_additional_fields'));
|
||||
add_filter('woocommerce_json_search_found_products', array(__CLASS__, 'filter_product_by_country'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add Manufacturer product and Supplier product number fields to
|
||||
* Simple product general tab
|
||||
*
|
||||
*/
|
||||
public static function display_additional_fields() {
|
||||
|
||||
global $post;
|
||||
$product = wc_get_product( $post->ID );
|
||||
|
||||
if ($product->get_type() === 'simple') {
|
||||
|
||||
echo '<div class=" product_custom_field ">';
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_manufacturer_product_no',
|
||||
'label' => __('Manufacturer product number', 'woocommerce'),
|
||||
'type' => 'text'
|
||||
)
|
||||
);
|
||||
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_supplier_product_no',
|
||||
'label' => __('Supplier product number', 'woocommerce'),
|
||||
'type' => 'text'
|
||||
)
|
||||
);
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
public static function filter_product_by_country($search_results) {
|
||||
|
||||
$url = wp_get_referer();
|
||||
|
||||
if (strpos($url, 'post') === false) {
|
||||
return $search_results;
|
||||
}
|
||||
|
||||
$post_param = explode("&", parse_url($url, PHP_URL_QUERY))[0];
|
||||
$post_id = explode("=", $post_param)[1];
|
||||
$country_id = wp_get_post_terms($post_id, 'product_country', array('fields' => 'ids'))[0];
|
||||
|
||||
if (!empty($search_results)) {
|
||||
$search_result_objects = array_map('wc_get_product', array_keys($search_results));
|
||||
|
||||
foreach ($search_result_objects as $result_id => $producta) {
|
||||
if (Wiaas_Countries::get_product_country_term_id($producta) !== $country_id) {
|
||||
unset($search_results[$producta->get_id()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $search_results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Manufacturer product and Supplier product number fields to
|
||||
* Simple product meta data
|
||||
*
|
||||
*/
|
||||
public static function save_additional_fields($post_id) {
|
||||
|
||||
$manufacturer_product_no = $_POST['_manufacturer_product_no'];
|
||||
if (!empty($manufacturer_product_no))
|
||||
update_post_meta($post_id, '_manufacturer_product_no', esc_attr($manufacturer_product_no));
|
||||
|
||||
$supplier_product_no = $_POST['_supplier_product_no'];
|
||||
if (!empty($supplier_product_no))
|
||||
update_post_meta($post_id, '_supplier_product_no', esc_attr($supplier_product_no));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product_Additional_Info::init();
|
||||
@@ -3,35 +3,27 @@
|
||||
class Wiaas_Admin_Template_Selection {
|
||||
|
||||
public static function init() {
|
||||
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);
|
||||
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);
|
||||
|
||||
// Processes and saves type-specific data.
|
||||
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'validate_bundle'), 11);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders template selection meta box
|
||||
*/
|
||||
public static function create_template_meta_box() {
|
||||
public static function create_custom_meta_box() {
|
||||
add_meta_box(
|
||||
'template_product_meta_box',
|
||||
__('Choose package template <em>(optional)</em>', 'cmb'),
|
||||
'Wiaas_Admin_Template_Selection::add_template_content_meta_box',
|
||||
'Wiaas_Admin_Template_Selection::add_custom_content_meta_box',
|
||||
'product',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
public static function add_custom_content_meta_box($post) {
|
||||
|
||||
$value = get_post_meta($post->ID, '_select_template', true);
|
||||
|
||||
@@ -57,82 +49,49 @@ 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['services']);
|
||||
self::render_template_products($template_products_data['service']);
|
||||
self::render_template_products($template_products_data['installation']);
|
||||
self::render_template_products($template_products_data['software']);
|
||||
?></div><?php
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
public static function get_categories_from_templates($products_form_template) {
|
||||
|
||||
$all_template_categories = array();
|
||||
|
||||
$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']));
|
||||
$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']));
|
||||
|
||||
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 array();
|
||||
return;
|
||||
|
||||
} else {
|
||||
|
||||
$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');
|
||||
$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));
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'hardware' => $template_products_hardware,
|
||||
'services' => $template_products_services,
|
||||
'service' => $template_products_service,
|
||||
'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)) {
|
||||
|
||||
@@ -149,43 +108,90 @@ class Wiaas_Admin_Template_Selection {
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_product_categories($category_meta) {
|
||||
$category_objects = array();
|
||||
|
||||
/**
|
||||
* Save selected template
|
||||
*
|
||||
* @param $post_id WP_Post
|
||||
*/
|
||||
|
||||
function save_template_content_meta_box($post_id) {
|
||||
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) {
|
||||
$selected_template = $_POST['_select_template'];
|
||||
|
||||
WC_Product_Template::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', '');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
$template_categories_form_template = self::show_template_products($selected_template);
|
||||
$products_form_template = self::show_template_products($selected_template);
|
||||
|
||||
$missing_template_categories = array();
|
||||
$insufficient_template_category_quantities = array();
|
||||
$missing_categories = array();
|
||||
$insufficient_product_quantities = array();
|
||||
|
||||
$categories_form_template = self::get_categories_from_templates($template_categories_form_template);
|
||||
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
|
||||
|
||||
$categories_form_template = self::get_categories_from_templates($products_form_template);
|
||||
$categories_form_bundle = self::get_bundled_product_categories($bundled_items);
|
||||
$bundle_category_keys = array_keys($categories_form_bundle);
|
||||
|
||||
|
||||
if (!empty($categories_form_template)) {
|
||||
|
||||
foreach ($categories_form_template as $category) {
|
||||
@@ -194,7 +200,7 @@ class Wiaas_Admin_Template_Selection {
|
||||
|
||||
if (!in_array($template_cat_id, $bundle_category_keys)) {
|
||||
|
||||
array_push($missing_template_categories, $category->name);
|
||||
array_push($missing_categories, $category->name);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -202,25 +208,37 @@ class Wiaas_Admin_Template_Selection {
|
||||
$quantity_from_template = $category->quantity;
|
||||
|
||||
if ((int)($quantity_from_template) !== $product_from_bundle_quantity) {
|
||||
array_push($insufficient_template_category_quantities, $category->name);
|
||||
array_push($insufficient_product_quantities, $category->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$template_categories_message = implode(',', $missing_template_categories);
|
||||
$quantity_message = implode(',', $insufficient_template_category_quantities);
|
||||
$categories_message = implode(',', $missing_categories);
|
||||
$quantity_message = implode(',', $insufficient_product_quantities);
|
||||
|
||||
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($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($insufficient_template_category_quantities)) {
|
||||
if (!empty($insufficient_product_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,10 +21,6 @@ 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']);
|
||||
@@ -38,7 +34,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['services']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['service']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['installation']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['software']);
|
||||
|
||||
@@ -57,7 +53,7 @@ class Wiaas_Template_Admin_Ajax {
|
||||
check_ajax_referer('wc_bundles_add_bundled_product', 'security');
|
||||
|
||||
$loop = intval($_POST['id']);
|
||||
$template_category_id = intval($_POST['template_category_id']);
|
||||
$product_id = intval($_POST['product_id']);
|
||||
$title = $_POST['title'];
|
||||
$options = $_POST['options'];
|
||||
|
||||
@@ -74,13 +70,13 @@ class Wiaas_Template_Admin_Ajax {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding template categories search.
|
||||
*
|
||||
*/
|
||||
public static function ajax_wiaas_template_category_search() {
|
||||
|
||||
$term = wp_unslash($_GET['term']);
|
||||
$term = ($_POST['term']);
|
||||
$response = array();
|
||||
|
||||
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => 'template_category',
|
||||
'name__like' => $term
|
||||
|
||||
@@ -7,9 +7,11 @@ 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'));
|
||||
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'hide_attributes_data_panel'));
|
||||
add_action('woocommerce_process_product_meta_wiaastemplate', array(__CLASS__, 'save_wiaastemplate'));
|
||||
|
||||
// Enqueue scripts.
|
||||
@@ -33,7 +35,7 @@ class Wiaas_template {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add template product type drop down.
|
||||
* Add to product type drop down.
|
||||
*/
|
||||
function add_template_product_type($types) {
|
||||
|
||||
@@ -46,7 +48,27 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Add template product, hardware, services, installation and software tabs product tab.
|
||||
* 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.
|
||||
*/
|
||||
function custom_product_tabs($tabs) {
|
||||
|
||||
@@ -78,10 +100,6 @@ class Wiaas_template {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content do template tabs
|
||||
*/
|
||||
|
||||
public static function wiaastemplate_product_tab_content_all() {
|
||||
|
||||
self::wiaastemplate_product_tab_content('hardware');
|
||||
@@ -92,11 +110,8 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Html contents of the template options product tab.
|
||||
*
|
||||
* @param $options string main wiaas category
|
||||
* Contents of the template options product tab.
|
||||
*/
|
||||
|
||||
public static function wiaastemplate_product_tab_content($options) {
|
||||
|
||||
global $post;
|
||||
@@ -113,7 +128,7 @@ class Wiaas_template {
|
||||
|
||||
foreach ($template_items as $item) {
|
||||
|
||||
$template_category_id = $item['template_category_id'];
|
||||
$product_id = $item['template_category_id'];
|
||||
$title = $item['template_category_title'];
|
||||
$quantity = $item['quantity'];
|
||||
|
||||
@@ -127,7 +142,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'); ?>"
|
||||
multiple="multiple" data-limit="500">
|
||||
data-action="woocommerce_json_search_products" 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')); ?>
|
||||
@@ -139,7 +154,7 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Save the template categories that are bind to template.
|
||||
* Save the custom fields.
|
||||
*/
|
||||
function save_wiaastemplate($post_id) {
|
||||
|
||||
@@ -148,21 +163,14 @@ 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::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');
|
||||
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');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
public static function save_template_product_meta($post_id, $posted_template_data, $option) {
|
||||
$processed_template_data = array();
|
||||
|
||||
// Sort posted data by menu order.
|
||||
@@ -170,24 +178,24 @@ class Wiaas_template {
|
||||
|
||||
foreach ($posted_template_data as $data) {
|
||||
|
||||
$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;
|
||||
$product_id = isset($data['product_id']) ? absint($data['product_id']) : false;
|
||||
$product_title = isset($data['product_title']) ? $data['product_title'] : false;
|
||||
$quantity = isset($data['quantity']) ? absint($data['quantity']) : false;
|
||||
|
||||
|
||||
$item_data = array(
|
||||
|
||||
'template_category_id' => $template_category_id,
|
||||
'template_category_title' => trim($template_category_title),
|
||||
'template_category_id' => $product_id,
|
||||
'template_category_title' => trim($product_title),
|
||||
'quantity' => $quantity
|
||||
|
||||
);
|
||||
|
||||
$processed_template_data[$template_category_id] = $item_data;
|
||||
$processed_template_data[$product_id] = $item_data;
|
||||
|
||||
}
|
||||
|
||||
WC_Product_Template::save_template_product_meta($post_id, $option, $processed_template_data);
|
||||
update_post_meta($post_id, '_template_items_' . $option, $processed_template_data);
|
||||
}
|
||||
|
||||
public static function menu_sort_order($a, $b) {
|
||||
@@ -197,6 +205,21 @@ class Wiaas_template {
|
||||
return isset($a['menu_order']) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hide Attributes data panel.
|
||||
*/
|
||||
function hide_attributes_data_panel($tabs) {
|
||||
|
||||
$tabs['advanced']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
$tabs['shipping']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
$tabs['linked_product']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
$tabs['attribute']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
|
||||
return $tabs;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_template::init();
|
||||
|
||||
@@ -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; ?>][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; ?>" />
|
||||
?><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; ?>" />
|
||||
|
||||
</div><?php
|
||||
|
||||
|
||||
@@ -31,21 +31,15 @@ class Wiaas_Cart_API {
|
||||
'package_id' => array(
|
||||
'description' => __( 'Wiaas package ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'cl_id' => array(
|
||||
'description' => __( 'Commercial lead ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'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()),
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'options_ids' => array(
|
||||
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
|
||||
@@ -53,6 +47,7 @@ class Wiaas_Cart_API {
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
)
|
||||
),
|
||||
'addons_ids' => array(
|
||||
@@ -61,6 +56,7 @@ class Wiaas_Cart_API {
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -73,6 +69,7 @@ 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(
|
||||
@@ -89,69 +86,12 @@ 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'),
|
||||
@@ -232,18 +172,15 @@ class Wiaas_Cart_API {
|
||||
$success = Wiaas_Cart::add_package_to_cart(
|
||||
$request['package_id'],
|
||||
$request['price_id'],
|
||||
$request['cl_id'],
|
||||
$request['addons_ids'],
|
||||
$request['options_ids']
|
||||
);
|
||||
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
return wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,13 +192,11 @@ class Wiaas_Cart_API {
|
||||
|
||||
$success = Wiaas_Cart::remove_package_from_cart($request['key']);
|
||||
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
return wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,51 +207,11 @@ class Wiaas_Cart_API {
|
||||
|
||||
$success = Wiaas_Cart::update_package_quantity($request['key'], $request['quantity']);
|
||||
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
if ($success) {
|
||||
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||
}
|
||||
|
||||
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']);
|
||||
return wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
}
|
||||
|
||||
|
||||
@@ -329,10 +224,6 @@ 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,73 +17,26 @@ class Wiaas_Document_API {
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'documents', array(
|
||||
register_rest_route( self::$namespace, 'download-package-file', 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($request) {
|
||||
$document_id = $request['document_id'];
|
||||
public static function download_package_file() {
|
||||
$document_id = $_GET['document_id'];
|
||||
$package_id = $_GET['package_id'];
|
||||
|
||||
Wiaas_Document_Download::download_document($document_id);
|
||||
}
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
$file = $package->get_file($document_id);
|
||||
|
||||
if ($file) {
|
||||
WC_Download_Handler::download_file_force($package->get_file_download_path($document_id), $file->get_name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* TODO: Refactor this class so it reflects the fact that customer is an organization
|
||||
* TODO: Format should be `customer/(?P<organization_id>\d+)/user/(?P<id>\d+)
|
||||
*
|
||||
* Class Wiaas_REST_Customer_API
|
||||
*/
|
||||
|
||||
class Wiaas_REST_Customer_API {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
@@ -16,19 +9,13 @@ class Wiaas_REST_Customer_API {
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public function __construct() {
|
||||
|
||||
include_once dirname( __FILE__ ) . '/../user/class-wiaas-customer.php';
|
||||
include_once dirname( __FILE__ ) . '/helper/class-rest-helper-functions.php';
|
||||
}
|
||||
|
||||
|
||||
public static function register_routes() {
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/shops', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_customer_shops'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses', array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(__CLASS__, 'update_customer_profile_addresses'),
|
||||
@@ -67,21 +54,6 @@ class Wiaas_REST_Customer_API {
|
||||
|
||||
}
|
||||
|
||||
public static function get_customer_shops() {
|
||||
|
||||
$customer_shops = Wiaas_Customer::get_customer_shops();
|
||||
|
||||
$customer_shops = array_map(function($customer_shop) {
|
||||
return array(
|
||||
'id' => absint($customer_shop['owner_id']),
|
||||
'type' => $customer_shop['order_type'],
|
||||
'name' => wiaas_get_organization_name($customer_shop['owner_id'])
|
||||
);
|
||||
}, $customer_shops);
|
||||
|
||||
return rest_ensure_response($customer_shops);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function update_customer_profile_addresses(WP_REST_Request $request){
|
||||
|
||||
@@ -93,29 +93,7 @@ class Wiass_REST_Delivery_Process_API {
|
||||
);
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
|
||||
$data = array();
|
||||
$total = 0;
|
||||
$queries =$wpdb->queries;
|
||||
foreach ($queries as $query) {
|
||||
$data[] = array(
|
||||
$query[0],
|
||||
$query[1]
|
||||
);
|
||||
|
||||
$total += $query[1];
|
||||
}
|
||||
|
||||
global $wp_timer;
|
||||
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'data' => $queries,
|
||||
'total' => $total * 1000,
|
||||
'start' => (microtime() - $wp_timer) * 1000
|
||||
));
|
||||
return rest_ensure_response($data);
|
||||
}
|
||||
|
||||
public static function get_customer_acceptance(WP_REST_Request $request){
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements wiaas shop based search on top of woocommerce product api
|
||||
*
|
||||
* Class Wiaas_WC_Package_API_Integration
|
||||
*/
|
||||
class Wiaas_WC_Package_API_Integration {
|
||||
|
||||
/**
|
||||
* Rest base for woocommerce product search
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $wc_rest_base = '/wc/v2/products';
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
|
||||
|
||||
add_filter('rest_dispatch_request', array(__CLASS__, 'validate_package_search_request'), 10, 4);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Force wc api request to send shop id when searching packages
|
||||
*
|
||||
* @param $null
|
||||
* @param $request
|
||||
* @param $route
|
||||
* @param $handler
|
||||
*
|
||||
* @return null|WP_Error
|
||||
*/
|
||||
public static function validate_package_search_request($null, $request, $route, $handler) {
|
||||
|
||||
if (strpos($route, self::$wc_rest_base) !== false) {
|
||||
|
||||
if (empty($request['shop_id']) || ! absint($request['shop_id'])) {
|
||||
|
||||
return new WP_Error(
|
||||
'missing_shop',
|
||||
'Shop parameter is missing',
|
||||
array ( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($args['tax_query']) ){
|
||||
$args['tax_query'] = array();
|
||||
}
|
||||
|
||||
// Retrieve only packages with available package status
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => 'package_status',
|
||||
'field' => 'name',
|
||||
'terms' => Wiaas_Package_Status::AVAILABLE
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve packages that satisfy one of two:
|
||||
*
|
||||
* 1) Package has at least one visible customer specific price set (for current customer)
|
||||
* 2) Package has at least one visible default price set and not customer specific prices set (for current customer)
|
||||
*
|
||||
* This approach enables us that if package has specific prices set for current customer only those prices
|
||||
* are taken into account and default ones are ignored.
|
||||
* Only if package has no specific prices for current customer default prices are taken into account.
|
||||
*
|
||||
*/
|
||||
|
||||
$shop_id = absint($request['shop_id']);
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$default_price_search_term = '_' . $shop_id . '_default';
|
||||
$customer_visible_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_visible';
|
||||
$customer_hidden_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_hidden';
|
||||
|
||||
$args['tax_query'][] = array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'taxonomy' => '_wiaas_shop_prices',
|
||||
'terms' => $customer_visible_price_search_term,
|
||||
'field' => 'slug'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'taxonomy' => '_wiaas_shop_prices',
|
||||
'terms' => $default_price_search_term,
|
||||
'field' => 'slug'
|
||||
),
|
||||
array(
|
||||
'taxonomy' => '_wiaas_shop_prices',
|
||||
'terms' => $customer_hidden_price_search_term,
|
||||
'field' => 'slug',
|
||||
'operator' => 'NOT IN'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_WC_Package_API_Integration::init();
|
||||
@@ -22,59 +22,6 @@ 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
|
||||
*
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
<?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(
|
||||
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Access_Management
|
||||
*/
|
||||
class Wiaas_Access_Management {
|
||||
|
||||
/**
|
||||
* Handles organization and role based access management to wiaas objects (orders, products)
|
||||
*
|
||||
* Using Groups Access for achieve this
|
||||
*
|
||||
*/
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
|
||||
|
||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
$access_group = null;
|
||||
|
||||
// if product is not bundle or it not completed set it visible only for admin
|
||||
if ($product->get_type() !== 'bundle' ||
|
||||
$product->get_status() !== 'publish' ||
|
||||
empty(Wiaas_Package_Pricing::get_package_prices($product))) {
|
||||
|
||||
$access_group = Groups_Group::read_by_name('admin');
|
||||
} else {
|
||||
|
||||
$access_group = Groups_Group::read_by_name('Registered');
|
||||
}
|
||||
|
||||
if ($access_group) {
|
||||
Groups_Post_Access::update(
|
||||
array(
|
||||
'post_id' => $product->get_id(),
|
||||
'groups_read' => $access_group->group_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignees order to corresponding user organization when order is created.
|
||||
*
|
||||
* @param int $order_id
|
||||
*/
|
||||
public static function assign_order_to_organization($order_id) {
|
||||
// assign order to customer organization
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
// assign order to commercial lead organization
|
||||
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
|
||||
if ($commercial_lead_id) {
|
||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Access_Management::init();
|
||||
@@ -12,32 +12,10 @@ class Wiaas_Admin {
|
||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-admin-template-selection.php';
|
||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-products.php';
|
||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-admin-ajax.php';
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-simple-product.php';
|
||||
|
||||
// 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';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-product.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/wiaas-admin-package.css' );
|
||||
|
||||
wp_enqueue_script( 'wiaas_admin_packages', $plugin_url . '/assets/js/wiaas-admin-package.js' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin::init();
|
||||
|
||||
@@ -43,8 +43,6 @@ class Wiaas_API {
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
|
||||
|
||||
// API functions
|
||||
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
||||
|
||||
@@ -57,7 +55,7 @@ class Wiaas_API {
|
||||
'Wiaas_Document_API',
|
||||
'Wiass_REST_User_API',
|
||||
'Wiaas_REST_Customer_API',
|
||||
'Wiaas_Order_Projects_API',
|
||||
'Wiaas_Order_Projects_API'
|
||||
);
|
||||
|
||||
foreach ( $controllers as $controller ) {
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
<?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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect admin user to dashboard
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function login_redirect() {
|
||||
return admin_url('index.php') ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Authenticate current user based on roles assigned to organization
|
||||
*
|
||||
* User role will be determined in `maybe_filter_user_roles` based on his organization roles
|
||||
*
|
||||
* If this is REST API request user will be only authenticated with customer role if his organization has
|
||||
* customer role assigned to it.
|
||||
*
|
||||
* If this is backend request user will be authenticated with previously selected or first available role
|
||||
* from his organization roles.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
$user = new WP_User($user_id);
|
||||
|
||||
if (empty($user->roles)) {
|
||||
return new WP_Error('wiaas_authentication_error', 'No permissions!');
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate wiaas user on login based on roles assigned to organization
|
||||
*
|
||||
* User role will be determined in `maybe_filter_user_roles` based on his organization roles
|
||||
*
|
||||
* If this is REST API login request user will be only authenticated with customer role if his organization his
|
||||
* customer role assigned to it.
|
||||
*
|
||||
* If this is backend login request user will be authenticated with previously selected or first available role
|
||||
* from his organization roles.
|
||||
*
|
||||
* @param WP_User $user
|
||||
* @return WP_User|WP_Error
|
||||
*/
|
||||
public static function authenticate_user_on_login($user) {
|
||||
// do nothing if there is an error already,
|
||||
// user is super admin
|
||||
if (is_wp_error($user) || $user->ID === self::SUPER_ADMIN_USER_ID) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if (empty($user->roles)) {
|
||||
return new WP_Error('wiaas_authentication_error', 'No permissions!');
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Override default user roles with only his organization roles.
|
||||
*
|
||||
* If this is REST API request retrieve customer role if organization has that role.
|
||||
*
|
||||
* If this is backend request retrieve previously selected role or first available organization role with
|
||||
* backend access.
|
||||
*
|
||||
* @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') {
|
||||
|
||||
return array( array( 'administrator' => true ) );
|
||||
|
||||
// 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 array();
|
||||
}
|
||||
|
||||
// get organization roles
|
||||
$roles = wiaas_get_organization_roles($organization_id);
|
||||
|
||||
// if organization has no roles assigned to it user will have no roles
|
||||
if ( empty($roles) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* REST API access
|
||||
*/
|
||||
|
||||
// for REST API access allow only customer role for user
|
||||
if ( $is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix()) ) {
|
||||
return in_array('customer', $roles) ? array( array( 'customer' => true ) ) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* BACKEND ACCESS
|
||||
*/
|
||||
|
||||
// remove customer role
|
||||
$roles = array_diff($roles, array( 'customer'));
|
||||
|
||||
// not available backend roles for user
|
||||
if ( empty($roles) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// retrieve selected role for user
|
||||
$role = get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
|
||||
|
||||
// if user has no selected role, selected role in invalid (deleted) or organization has no selected role
|
||||
// assign first available role to user
|
||||
if ( empty($role) ||
|
||||
! wp_roles()->is_role($role) ||
|
||||
! in_array($role, $roles) ) {
|
||||
|
||||
// pick first role
|
||||
$role = $roles[0];
|
||||
update_user_meta($user_id, '_wiaas_current_user_admin_role', $role);
|
||||
}
|
||||
|
||||
return array( array ( "$role" => true ));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Authentication::init();
|
||||
@@ -12,11 +12,6 @@ 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 );
|
||||
@@ -27,83 +22,6 @@ class Wiaas_Cart {
|
||||
|
||||
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
add_action('woocommerce_checkout_create_order', array(__CLASS__, 'add_additional_order_data'), 99);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,53 +34,25 @@ class Wiaas_Cart {
|
||||
*
|
||||
* @param int $package_id Package ID of selected package
|
||||
* @param string $price_id Price ID of selected package payment
|
||||
* @param int $shop_owner_id Shop owner commercial lead ID
|
||||
* @param array $addons_ids Array of selected additional packages IDs
|
||||
* @param array $options_ids Array of selected option packages IDs
|
||||
*
|
||||
* @return bool TRUE if all packages are succesfully added to cart, FALSE otherwise
|
||||
*/
|
||||
public static function add_package_to_cart($package_id, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||
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);
|
||||
|
||||
if (empty($country)) {
|
||||
wc_add_notice('Package cannot be added do cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Add validation that only packages from the same country can be added to cart at the same time
|
||||
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
|
||||
|
||||
// TODO: Add validation that only packages from the same shop can be added to cart at the same time
|
||||
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
// Retrieve package price
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $shop_owner_id);
|
||||
|
||||
// Retrieve package price
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Initialize additional cart item data for wiaas packages
|
||||
@@ -170,19 +60,18 @@ class Wiaas_Cart {
|
||||
'_wiaas_standard_package' => true,
|
||||
'_wiaas_addon_items' => array(),
|
||||
'_wiaas_option_items' => array(),
|
||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||
'_wiaas_documents' => array()
|
||||
'_wiaas_currency' => isset($country) ? $country['currency'] : get_woocommerce_currency(),
|
||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null
|
||||
);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
// Add selected additional packages and options
|
||||
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids);
|
||||
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $addons_ids, $options_ids);
|
||||
|
||||
// Trigger calculation of total prices after additional packages are added
|
||||
WC()->cart->calculate_totals();
|
||||
@@ -190,6 +79,8 @@ class Wiaas_Cart {
|
||||
return true;
|
||||
|
||||
} catch( Exception $e) {
|
||||
|
||||
error_log($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -290,7 +181,7 @@ class Wiaas_Cart {
|
||||
* @param $cart_item
|
||||
* @param $order
|
||||
*
|
||||
* @return WC_Order_Item
|
||||
* @return array
|
||||
*/
|
||||
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'])) {
|
||||
@@ -311,6 +202,9 @@ class Wiaas_Cart {
|
||||
if (isset($cart_item['_wiaas_standard_package'])) {
|
||||
$order_item->add_meta_data( '_wiaas_standard_package', $cart_item['_wiaas_standard_package'], true );
|
||||
}
|
||||
if (isset($cart_item['_wiaas_currency'])) {
|
||||
$order_item->add_meta_data( '_wiaas_currency', $cart_item['_wiaas_currency'], true );
|
||||
}
|
||||
|
||||
// add options metadata
|
||||
if (isset($cart_item['_wiaas_option_items'])) {
|
||||
@@ -330,40 +224,6 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -388,33 +248,10 @@ class Wiaas_Cart {
|
||||
'_wiaas_option_for',
|
||||
'_wiaas_option_group_name',
|
||||
'_wiaas_standard_package',
|
||||
'_wiaas_documents',
|
||||
'_wiaas_currency',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets additional order data form cart after order is successfully created
|
||||
*
|
||||
* @param WC_Order $order
|
||||
*
|
||||
* @throws WC_Data_Exception
|
||||
*
|
||||
*/
|
||||
public static function add_additional_order_data($order) {
|
||||
|
||||
// set order currency
|
||||
$country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
|
||||
$currency = empty($country) ? get_woocommerce_currency() : $country['currency'];
|
||||
|
||||
$order->set_currency($currency);
|
||||
|
||||
// set order commercial lead
|
||||
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
||||
$shop_owner_id = absint($shop_owner_id);
|
||||
|
||||
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate total cost for cart item
|
||||
*
|
||||
@@ -482,9 +319,6 @@ class Wiaas_Cart {
|
||||
public static function get_cart_packages() {
|
||||
$items = WC()->cart->get_cart_contents();
|
||||
|
||||
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
||||
$shop_owner_id = absint($shop_owner_id);
|
||||
|
||||
$package_items = array();
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
@@ -534,8 +368,8 @@ class Wiaas_Cart {
|
||||
'package_name' => $package->get_title(),
|
||||
'quantity' => $item['quantity'],
|
||||
|
||||
'commercial_lead_id' => $shop_owner_id,
|
||||
'commercial_lead' => wiaas_get_organization_name($shop_owner_id),
|
||||
'commercial_lead_id' => 14,
|
||||
'commercial_lead' => 'Coor Service Management',
|
||||
'country' => Wiaas_Countries::get_package_country($package),
|
||||
|
||||
'are_additional_available' => true,
|
||||
@@ -567,124 +401,24 @@ 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
|
||||
*
|
||||
* @param string $package_cart_item_key
|
||||
* @param int $price_id
|
||||
* @param int $shop_owner_id
|
||||
* @param array $addons_ids
|
||||
* @param array $options_ids
|
||||
*
|
||||
* @throws Exception if any of the addons or options cannot be added to cart
|
||||
*/
|
||||
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $addons_ids, $options_ids) {
|
||||
|
||||
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||
|
||||
$addon_items_keys = array();
|
||||
$option_items_keys = array();
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
// Try adding package addons to cart
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
//Check if addon package exists
|
||||
@@ -693,13 +427,8 @@ 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'],
|
||||
$customer_id,
|
||||
$shop_owner_id
|
||||
);
|
||||
// Retrieve addon package price
|
||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $parent_item['data']);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Initialize additional cart item data for wiaas addon packages
|
||||
@@ -730,12 +459,8 @@ 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'],
|
||||
$customer_id,
|
||||
$shop_owner_id);
|
||||
// Retrieve option package price
|
||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $parent_item['data']);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Retrieve option package group name
|
||||
@@ -766,24 +491,6 @@ 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,23 +2,6 @@
|
||||
|
||||
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.
|
||||
*
|
||||
@@ -29,41 +12,49 @@ class Wiaas_Checkout {
|
||||
public static function process_checkout($data) {
|
||||
try {
|
||||
|
||||
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
|
||||
wc_set_time_limit( 0 );
|
||||
$customer = wp_get_current_user();
|
||||
|
||||
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_id = WC()->checkout()->create_order(array());
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( is_wp_error( $order_id ) ) {
|
||||
throw new Exception( $order_id->get_error_message() );
|
||||
// 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 ( ! $order ) {
|
||||
throw new Exception( __( 'Unable to create order.', 'woocommerce' ) );
|
||||
$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']);
|
||||
}
|
||||
|
||||
self::_add_wiaas_checkout_data($order, $data);
|
||||
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']);
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_checkout_order_processed', $order_id, array(), $order );
|
||||
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']);
|
||||
}
|
||||
|
||||
$order->payment_complete();
|
||||
|
||||
@@ -72,30 +63,7 @@ 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 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();
|
||||
|
||||
@@ -94,7 +94,7 @@ class Wiaas_Countries {
|
||||
register_taxonomy( 'product_country', array( 'product' ), $args );
|
||||
|
||||
foreach (self::$available_countries as $available_country) {
|
||||
wp_update_term($available_country['name'], 'product_country');
|
||||
wp_insert_term($available_country['name'], 'product_country');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,25 +114,12 @@ class Wiaas_Countries {
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_product_country($product) {
|
||||
public static function get_product_country($product) {
|
||||
$product_country = get_the_terms($product->get_id(), 'product_country');
|
||||
return is_array($product_country) && isset($product_country[0]) ?
|
||||
self::$available_countries[$product_country[0]->name] :
|
||||
null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves country term id from db for provided product
|
||||
* @param $product
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public static function get_product_country_term_id($product) {
|
||||
$product_country = get_the_terms($product->get_id(), 'product_country');
|
||||
return is_array($product_country) && isset($product_country[0]) ?
|
||||
$product_country[0]->term_id :
|
||||
null;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Countries::init();
|
||||
|
||||
@@ -8,23 +8,12 @@ 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',
|
||||
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
|
||||
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
|
||||
'201810171645700' => 'wiaas_db_update_create_default_roles',
|
||||
'201810171745700' => 'wiaas_db_import_aam_role_settings',
|
||||
'201810180145700' => 'wiaas_db_update_update_supplier_capabilities',
|
||||
'201810180245700' => 'wiaas_db_update_update_admin_capabilities',
|
||||
'201810180345700' => 'wiaas_create_role_access_groups',
|
||||
'201810180444700' => 'wiaas_db_setup_create_customer_commercial_lead_table',
|
||||
'201810180544702' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
||||
'201810180644703' => 'wiaas_db_update_add_organization_info_ui_fields',
|
||||
'201910190145700' => 'wiaas_db_update_add_general_ui_fields',
|
||||
'201910190146700' => 'wiaas_db_update_add_product_properties_ui_fields',
|
||||
'201810190644704' => 'wiaas_db_update_add_reference_ui_field'
|
||||
'20180912101010' => 'wiaas_db_setup_default_cl'
|
||||
);
|
||||
|
||||
public static function execute() {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_DB {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/db/class-wiaas-shop-db.php';
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_DB::init();
|
||||
@@ -5,21 +5,98 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Wiaas Documents
|
||||
* Implements Wiaas Document types
|
||||
*
|
||||
* 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' ));
|
||||
}
|
||||
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document.php';
|
||||
/**
|
||||
* Registers taxonomy and default values for wiaas document types
|
||||
*/
|
||||
public static function register_wiaas_document_types() {
|
||||
$labels = array(
|
||||
'name' => _x( 'Document type', 'taxonomy general name', 'wiaas' ),
|
||||
'singular_name' => _x( 'Document type', 'taxonomy singular name', 'wiaas' ),
|
||||
'menu_name' => _x( 'Document types', 'Admin menu name', 'wiaas' ),
|
||||
'search_items' => __( 'Search Document types', 'wiaas' ),
|
||||
'all_items' => __( 'All Document types', 'wiaas' ),
|
||||
'parent_item' => __( 'Parent Document type', 'wiaas' ),
|
||||
'parent_item_colon' => __( 'Parent Document type:', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit Document type', 'wiaas' ),
|
||||
'update_item' => __( 'Update Document type', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add New Document type', 'wiaas' ),
|
||||
'new_item_name' => __( 'New Document type Name', 'wiaas' ),
|
||||
);
|
||||
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-upload.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-download.php';
|
||||
register_taxonomy( 'wiaas_document_types', array( 'attachment' ), $args );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/document/wiaas-document-functions.php';
|
||||
foreach (self::$available_doc_types as $key => $available_doc_type) {
|
||||
wp_insert_term($available_doc_type['name'], 'wiaas_document_types', array(
|
||||
'slug' => $key
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class Wiaas_Order {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
||||
|
||||
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
|
||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||
|
||||
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
||||
|
||||
@@ -30,35 +30,6 @@ class Wiaas_Order {
|
||||
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update `shop_order` post type settings before creation to enable better order management for wiaas
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_order_settings($args) {
|
||||
// show orders in backend menu
|
||||
$args['show_in_menu'] = true;
|
||||
|
||||
//set icon
|
||||
$args['menu_icon'] = 'dashicons-cart';
|
||||
|
||||
// set capabilities
|
||||
$args['capabilities'] = array(
|
||||
'edit_post' => 'edit_shop_order',
|
||||
'read_post' => 'read_shop_order',
|
||||
'delete_post' => 'delete_shop_order',
|
||||
'edit_posts' => 'edit_shop_orders',
|
||||
'edit_others_posts' => 'edit_others_shop_orders',
|
||||
'publish_posts' => 'publish_shop_orders',
|
||||
'read_private_posts' => 'read_private_shop_orders',
|
||||
'create_posts' => 'create_shop_orders', // use `create_shop_orders` instead of `edit_shop_orders`
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
public static function update_new_order_comment_date($comment_data, $order_data) {
|
||||
$user = wp_get_current_user();
|
||||
|
||||
@@ -68,6 +39,16 @@ class Wiaas_Order {
|
||||
return $comment_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignees order to corresponding user organization when order is created.
|
||||
*
|
||||
* @param $order_id
|
||||
*/
|
||||
public static function assign_order_to_organization($order_id) {
|
||||
$user = wp_get_current_user();
|
||||
Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current user has access to requested order/{orderId} via woocommerce REST API.
|
||||
* Endpoint `/orders` is filtered correctly by groups, but endpoint `/orders/{orderId}` will return order even if
|
||||
@@ -263,6 +244,7 @@ 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']);
|
||||
@@ -380,16 +362,34 @@ 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
|
||||
|
||||
// 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']);
|
||||
foreach($data['line_items'] as $item){
|
||||
$product = wc_get_product($item['product_id']);
|
||||
|
||||
$product_documents = array();
|
||||
foreach ( $product->get_downloads() as $file_id => $file ) {
|
||||
$product_documents[] = array(
|
||||
'id' => $file_id,
|
||||
'name' => $file->get_name(),
|
||||
'extension' => $file->get_file_extension()
|
||||
);
|
||||
}
|
||||
|
||||
if (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;
|
||||
if (count($product_documents)){
|
||||
$data['documents'][] = array(
|
||||
'package' => array(
|
||||
'id' => $product->get_id(),
|
||||
'name' => $product->get_name()
|
||||
),
|
||||
'documents' => $product_documents
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -12,7 +12,6 @@ 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';
|
||||
|
||||
@@ -32,9 +31,6 @@ class Wiaas_Package {
|
||||
|
||||
$data = self::_append_country_info($data, $package, $request);
|
||||
|
||||
// append package reference field
|
||||
$data['reference'] = ! empty($data['tags']) ? $data['tags'][0]['name'] : '';
|
||||
|
||||
if (isset($request['id'])) {
|
||||
$data = self::_append_package_prices($data, $package, $request);
|
||||
|
||||
@@ -58,11 +54,15 @@ class Wiaas_Package {
|
||||
*/
|
||||
private static function _append_documents_info($data, $package, $request) {
|
||||
|
||||
$data['documents'] = array_map(function($doc) {
|
||||
unset($doc['url']);
|
||||
unset($doc['version']);
|
||||
return $doc;
|
||||
}, wiaas_get_standard_package_documents($package, true));
|
||||
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()));
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -96,8 +96,6 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_additional_packages($data, $package, $request) {
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = absint($request['shop_id']);
|
||||
|
||||
$data['additional_packages'] = array();
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
@@ -106,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, $customer_id, $commercial_lead_id),
|
||||
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -127,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, $customer_id, $commercial_lead_id),
|
||||
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -144,10 +142,7 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_package_prices($data, $package, $request) {
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = absint($request['shop_id']);
|
||||
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9,240 +9,233 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
*/
|
||||
class Wiaas_Pricing {
|
||||
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
|
||||
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';
|
||||
}
|
||||
const COMMERCIAL_LEAD_NAME = 'Coor Service Management';
|
||||
|
||||
/**
|
||||
* 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);
|
||||
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';
|
||||
}
|
||||
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param WC_Product_Bundle $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
|
||||
$total_cost_per_category = array();
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$total_cost_per_category = array();
|
||||
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
|
||||
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);
|
||||
/**
|
||||
* Calculates customer price for wiaas standard package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_standard_package_customer_prices($package) {
|
||||
|
||||
}
|
||||
$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);
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$customer_package_prices = array();
|
||||
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
return $customer_package_prices;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
}
|
||||
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
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);
|
||||
}
|
||||
$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);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
// PRIVATE SECTION
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
$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);
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$customer_package_prices = array();
|
||||
|
||||
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
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);
|
||||
}
|
||||
|
||||
$customer_package_prices = array();
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
// PRIVATE
|
||||
|
||||
// commercial lead did not set prices for this payment type so it must not be visible for customer
|
||||
if (empty($cl_package_extras)) {
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$package_price,
|
||||
$total_cost,
|
||||
$cl_package_extras,
|
||||
$cl_commision,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
return $is_same_company_as_cl;
|
||||
}
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$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;
|
||||
|
||||
$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'],
|
||||
$cl_package_prices = array(
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
$interest_rate = self::INTEREST_RATE;
|
||||
|
||||
if ($is_same_company_as_cl) {
|
||||
$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 ($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'];
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
|
||||
} else {
|
||||
if ($is_same_company_as_cl) {
|
||||
|
||||
$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'];
|
||||
}
|
||||
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'];
|
||||
|
||||
return $customer_package_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;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Pricing::init();
|
||||
@@ -4,71 +4,6 @@ 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__, 'manage_product_settings'));
|
||||
|
||||
add_filter('woocommerce_taxonomy_args_product_tag', array(__CLASS__, 'manage_tags_as_references'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update product type settins before it is created:
|
||||
* - Define capabilities for editing products so we can easily control read/edit/create access for them
|
||||
* - Declare fields supported by product
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_product_settings($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`
|
||||
);
|
||||
|
||||
$args['supports'] = array( 'title', 'thumbnail' );
|
||||
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide default metabox for product tags
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_tags_as_references($args) {
|
||||
// hide metabox
|
||||
$args['meta_box_cb'] = false;
|
||||
|
||||
// update labels
|
||||
$args['labels'] = array(
|
||||
'name' => __( 'Product references', 'wiaas' ),
|
||||
'singular_name' => __( 'Reference', 'wiaas' ),
|
||||
'menu_name' => _x( 'References', 'Admin menu name', 'wiaas' ),
|
||||
'search_items' => __( 'Search references', 'wiaas' ),
|
||||
'all_items' => __( 'All references', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit reference', 'wiaas' ),
|
||||
'update_item' => __( 'Update reference', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add new reference', 'wiaas' ),
|
||||
'new_item_name' => __( 'New reference name', 'wiaas' ),
|
||||
'popular_items' => __( 'Popular references', 'wiaas' ),
|
||||
'separate_items_with_commas' => __( 'Separate references with commas', 'wiaas' ),
|
||||
'add_or_remove_items' => __( 'Add or remove references', 'wiaas' ),
|
||||
'choose_from_most_used' => __( 'Choose from the most used references', 'wiaas' ),
|
||||
'not_found' => __( 'No references found', 'wiaas' ),
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements logic for multiple shops existing in one marketplace
|
||||
*
|
||||
* Every shop has its owner (organization that is commercial lead) and multiple customers (organizations)
|
||||
* assigned to it.
|
||||
*
|
||||
* Class Wiaas_Shop
|
||||
*/
|
||||
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);
|
||||
|
||||
// create new shop if organization was assigned commercial lead role
|
||||
// or remove shop if commercial lead role was removed for organization
|
||||
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'remove_deactivated_shop'));
|
||||
|
||||
add_action('wiaas_organization_deleted', array(__CLASS__, 'remove_shop'));
|
||||
}
|
||||
|
||||
public static function get_shop_customers($owner_id) {
|
||||
return Wiaas_Shop_DB::get_shop_customers($owner_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link customers to shop (this will enable them to search and order packages from this shop)
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param array $customer_ids
|
||||
*/
|
||||
public static function set_shop_customers($owner_id, $customer_ids) {
|
||||
|
||||
$current_customer_ids = wp_list_pluck(
|
||||
Wiaas_Shop_DB::get_shop_customers($owner_id),
|
||||
'customer_id');
|
||||
|
||||
// delete removed customers
|
||||
$removed_customer_ids = array_diff($current_customer_ids, $customer_ids);
|
||||
Wiaas_Shop_DB::remove_shop_customers($owner_id, $removed_customer_ids);
|
||||
|
||||
// save added customers
|
||||
$added_customer_ids = array_diff($customer_ids, $current_customer_ids);
|
||||
Wiaas_Shop_DB::add_shop_customers($owner_id, $added_customer_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve default order type for shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_default_order_type($owner_id) {
|
||||
$order_type = get_term_meta(
|
||||
$owner_id,
|
||||
'_wiaas_shop_default_order_type',
|
||||
true);
|
||||
|
||||
return empty($order_type) ? 'commercial_lead' : $order_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update default order type for shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param string $order_type
|
||||
*/
|
||||
public static function update_default_order_type($owner_id, $order_type) {
|
||||
|
||||
if (in_array($order_type, array('commercial_lead', 'reseller'))) {
|
||||
update_term_meta($owner_id, '_wiaas_shop_default_order_type', $order_type);
|
||||
}
|
||||
}
|
||||
|
||||
public static function update_shop_customer_order_type($owner_id, $customer_id, $order_type) {
|
||||
Wiaas_Shop_DB::update_shop_customer_order_type(
|
||||
$owner_id,
|
||||
$customer_id,
|
||||
$order_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove shop for organization that is no longer commercial lead
|
||||
*
|
||||
* @param int $owner_id
|
||||
*/
|
||||
public static function remove_deactivated_shop($owner_id) {
|
||||
$roles = wiaas_get_organization_roles($owner_id);
|
||||
|
||||
if (! in_array('commercial_lead', $roles)) {
|
||||
self::remove_shop($owner_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
*/
|
||||
public static function remove_shop($owner_id) {
|
||||
Wiaas_Shop_DB::remove_shop($owner_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' => false,
|
||||
'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_terms = self::_get_search_terms_from_cl_extras($owner_id, $old_cl_extras);
|
||||
|
||||
wp_remove_object_terms($package_id, $old_terms, '_wiaas_shop_prices');
|
||||
}
|
||||
|
||||
$new_terms = self::_get_search_terms_from_cl_extras($owner_id, $cl_extras);
|
||||
|
||||
// create term for every visible pricing type and link them to package so package can be queried
|
||||
wp_add_object_terms($package_id, $new_terms, '_wiaas_shop_prices');
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
/**
|
||||
* Generate search terms from cl extras
|
||||
*
|
||||
* For default prices search term
|
||||
* `_{owner_id}_default` will be generated if all set prices are visible
|
||||
*
|
||||
* For every customer entry search term
|
||||
* `_{owner_id}_customer_{customer_id}_visible` will be generated if any of the prices is visible or
|
||||
* `_{owner_id}_customer_{customer_id}_hidden` if all prices are hidden`
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param array $cl_extras
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_search_terms_from_cl_extras($owner_id, $cl_extras) {
|
||||
// determine if extras are visible grouped by customer and default settings
|
||||
$cl_extras_per_customer = array();
|
||||
$cl_extra_default = false;
|
||||
|
||||
foreach ($cl_extras as $cl_extra_type => $cl_extra) {
|
||||
// is default
|
||||
if (strpos($cl_extra_type, '_default') !== false) {
|
||||
// determine if default cl extra is visible
|
||||
$cl_extra_default = $cl_extra_default || $cl_extra['visible'];
|
||||
}
|
||||
// is customer specific
|
||||
if (strpos($cl_extra_type, '_customer_') !== false) {
|
||||
$customer_id = absint(explode('_customer_', $cl_extra_type)[1]);
|
||||
// determine if customer cl extra is visible
|
||||
$cl_extras_per_customer[$customer_id] = $cl_extras_per_customer[$customer_id] || $cl_extra['visible'];
|
||||
}
|
||||
}
|
||||
|
||||
$terms = array();
|
||||
|
||||
if ($cl_extra_default) {
|
||||
$terms[] = '_' . $owner_id . '_default';
|
||||
}
|
||||
|
||||
foreach ($cl_extras_per_customer as $customer_id => $visible) {
|
||||
|
||||
$terms[] = '_' . $owner_id . '_customer_' . $customer_id . '_' .
|
||||
($visible ? 'visible' : 'hidden');
|
||||
}
|
||||
|
||||
return $terms;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Shop::init();
|
||||
@@ -21,7 +21,6 @@ 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,9 +33,7 @@ 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-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';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-functions.php';
|
||||
|
||||
$pending_db_updates = Wiaas_DB_Update::get_pending_db_updates();
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,86 +0,0 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbf694106e34",
|
||||
"title": "General",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bc0965a35406",
|
||||
"label": "Type",
|
||||
"name": "_wiaas_product_type",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"simple": "Simple",
|
||||
"bundle": "Bundle",
|
||||
"wiaastemplate": "Template"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 0,
|
||||
"ui": 1,
|
||||
"ajax": 0,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbf899bba1af",
|
||||
"label": "Country",
|
||||
"name": "_wiaas_product_country",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": [
|
||||
[
|
||||
{
|
||||
"field": "field_5bc0965a35406",
|
||||
"operator": "!=",
|
||||
"value": "wiaastemplate"
|
||||
}
|
||||
]
|
||||
],
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_country",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_type",
|
||||
"operator": "==",
|
||||
"value": "product"
|
||||
},
|
||||
{
|
||||
"param": "post_status",
|
||||
"operator": "==",
|
||||
"value": "_wiaas_no_country"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "acf_after_title",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -1,120 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bc49631c35a4",
|
||||
"label": "Linked Customers",
|
||||
"name": "_wiaas_organization_customers",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": [
|
||||
[
|
||||
{
|
||||
"field": "field_5bbe559d66d17",
|
||||
"operator": "==contains",
|
||||
"value": "commercial_lead"
|
||||
}
|
||||
]
|
||||
],
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "wiaas-user-organization",
|
||||
"field_type": "multi_select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 0,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"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": ""
|
||||
}
|
||||
]
|
||||
@@ -1,113 +0,0 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bc864b78434b",
|
||||
"title": "Product properties",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bc8653baeafb",
|
||||
"label": "Supplier",
|
||||
"name": "supplier",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "supplier",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
},
|
||||
{
|
||||
"key": "field_5bc86761aeafc",
|
||||
"label": "Unit",
|
||||
"name": "unit",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "wiaas_units",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
},
|
||||
{
|
||||
"key": "field_5bc867c3aeafd",
|
||||
"label": "Product category",
|
||||
"name": "category",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_cat",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
},
|
||||
{
|
||||
"key": "field_5bc8743b099a8",
|
||||
"label": "Template category",
|
||||
"name": "template_category",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "template_category",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_taxonomy",
|
||||
"operator": "==",
|
||||
"value": "product_type:simple"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "acf_after_title",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -1,52 +0,0 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bc845c001de4",
|
||||
"title": "Package Reference",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bc845dc7eed5",
|
||||
"label": "Reference",
|
||||
"name": "_wiaas_package_reference",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "product_tag",
|
||||
"field_type": "select",
|
||||
"allow_null": 0,
|
||||
"add_term": 1,
|
||||
"save_terms": 1,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "post_type",
|
||||
"operator": "==",
|
||||
"value": "product"
|
||||
},
|
||||
{
|
||||
"param": "post_taxonomy",
|
||||
"operator": "==",
|
||||
"value": "product_type:bundle"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "acf_after_title",
|
||||
"style": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -1,52 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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
|
||||
|
||||
/**
|
||||
* General Wiaas DB updates
|
||||
* Wiaas DB updates
|
||||
*
|
||||
* General functions for updating wiaas database to latest version
|
||||
* Functions for updating database to latest version
|
||||
*/
|
||||
|
||||
|
||||
@@ -78,6 +78,16 @@ 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() );
|
||||
|
||||
@@ -113,36 +123,6 @@ function wiaas_db_setup_exclusive_taxonomies() {
|
||||
));
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
}
|
||||
|
||||
function wiaas_db_setup_create_customer_commercial_lead_table() {
|
||||
global $wpdb;
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
|
||||
$sql = "
|
||||
CREATE TABLE {$wpdb->prefix}wiaas_shop_customer_relationships (
|
||||
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`customer_id` bigint(20) unsigned NOT NULL,
|
||||
`shop_owner_id` bigint(20) unsigned NOT NULL,
|
||||
`order_type` varchar(44) NOT NULL default '',
|
||||
PRIMARY KEY (`ID`),
|
||||
KEY `relationship` (`customer_id`, `shop_owner_id`),
|
||||
KEY `order_type` (`order_type`)
|
||||
) COLLATE {$wpdb->collate};
|
||||
";
|
||||
|
||||
dbDelta( $sql );
|
||||
function wiaas_db_setup_default_cl() {
|
||||
wp_insert_term(Wiaas_Pricing::COMMERCIAL_LEAD_NAME, Wiaas_User_Organization::TAXONOMY_NAME);
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
<?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',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'supplier',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'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', 'view_admin_dashboard' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'read' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'upload_files' );
|
||||
|
||||
// enable commercial leads to see Products tab
|
||||
wp_roles()->add_cap( 'commercial_lead', 'edit_products' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'edit_others_products' );
|
||||
// enable commercial leads to set extra prices on products
|
||||
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_products' );
|
||||
|
||||
// enable commercial leads to see Orders tab
|
||||
wp_roles()->add_cap( 'commercial_lead', 'edit_shop_orders' );
|
||||
|
||||
// enable commercial leads to se Customers tab
|
||||
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_customers' );
|
||||
}
|
||||
|
||||
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',
|
||||
));
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?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 );
|
||||
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_reference_ui_field() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-reference.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_general_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-general.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_product_properties_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-product-properties.json' );
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
|
||||
// private helper function
|
||||
|
||||
function _wiaas_import_field_group($json) {
|
||||
// vars
|
||||
$ids = array();
|
||||
$keys = array();
|
||||
|
||||
|
||||
// populate keys
|
||||
foreach( $json as $field_group ) {
|
||||
|
||||
// append key
|
||||
$keys[] = $field_group['key'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
// look for existing ids
|
||||
foreach( $keys as $key ) {
|
||||
|
||||
// attempt find ID
|
||||
$field_group = _acf_get_field_group_by_key( $key );
|
||||
|
||||
|
||||
// bail early if no field group
|
||||
if( !$field_group ) continue;
|
||||
|
||||
|
||||
// append
|
||||
$ids[ $key ] = $field_group['ID'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
// enable local
|
||||
acf_enable_local();
|
||||
|
||||
|
||||
// reset local (JSON class has already included .json field groups which may conflict)
|
||||
acf_reset_local();
|
||||
|
||||
|
||||
// add local field groups
|
||||
foreach( $json as $field_group ) {
|
||||
|
||||
// add field group
|
||||
acf_add_local_field_group( $field_group );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// loop over keys
|
||||
foreach( $keys as $key ) {
|
||||
|
||||
// vars
|
||||
$field_group = acf_get_local_field_group( $key );
|
||||
|
||||
|
||||
// attempt get id
|
||||
$id = acf_maybe_get( $ids, $key );
|
||||
|
||||
if( $id ) {
|
||||
|
||||
$field_group['ID'] = $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// append fields
|
||||
if( acf_have_local_fields($key) ) {
|
||||
|
||||
$field_group['fields'] = acf_get_local_fields( $key );
|
||||
|
||||
}
|
||||
|
||||
|
||||
// import
|
||||
acf_import_field_group( $field_group );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Shop_DB {
|
||||
|
||||
/**
|
||||
* Inserts new customer for shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param array $customer_ids
|
||||
*/
|
||||
public static function add_shop_customers($owner_id, $customer_ids) {
|
||||
global $wpdb;
|
||||
|
||||
foreach ($customer_ids as $customer_id) {
|
||||
$wpdb->insert( $wpdb->prefix . 'wiaas_shop_customer_relationships',
|
||||
array(
|
||||
'customer_id' => $customer_id,
|
||||
'shop_owner_id' => $owner_id,
|
||||
'order_type' => Wiaas_Shop::get_default_order_type($owner_id)
|
||||
),
|
||||
array( '%d', '%d', '%s')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates order type for customer in shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param int $customer_id
|
||||
* @param string $order_type
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public static function update_shop_customer_order_type($owner_id, $customer_id, $order_type) {
|
||||
global $wpdb;
|
||||
|
||||
$results = $wpdb->update(
|
||||
$wpdb->prefix . 'wiaas_shop_customer_relationships',
|
||||
array( 'order_type' => $order_type ),
|
||||
array(
|
||||
'customer_id' => $customer_id,
|
||||
'shop_owner_id' => $owner_id,
|
||||
),
|
||||
array( '%s' ),
|
||||
array( '%d', '%d' )
|
||||
);
|
||||
|
||||
if (false === $results) {
|
||||
return new WP_Error('cannot_update_order_type', __( 'Could not update order type.', 'wiaas' ), array( 'status' => 400 ));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes customer from shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param array $customer_ids
|
||||
*/
|
||||
public static function remove_shop_customers($owner_id, $customer_ids) {
|
||||
|
||||
if (empty($customer_ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$customer_ids = array_map('absint', $customer_ids);
|
||||
$customer_ids = implode(',', $customer_ids);
|
||||
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->prefix}wiaas_shop_customer_relationships
|
||||
WHERE shop_owner_id = %d AND customer_id IN (%s)",
|
||||
$owner_id,
|
||||
$customer_ids )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves array of customers assigned to shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
*
|
||||
* @return array {
|
||||
* @type int customer_id
|
||||
* @type string order_typr
|
||||
* }
|
||||
*/
|
||||
public static function get_shop_customers($owner_id) {
|
||||
|
||||
if ($owner_id === 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$results = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT customer_id, order_type
|
||||
FROM {$wpdb->prefix}wiaas_shop_customer_relationships
|
||||
WHERE shop_owner_id = %d",
|
||||
$owner_id )
|
||||
);
|
||||
|
||||
if ( empty( $results ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$customers = array_map(function($result_row) {
|
||||
return array(
|
||||
'customer_id' => $result_row->customer_id,
|
||||
'order_type' => $result_row->order_type
|
||||
);
|
||||
}, $results);
|
||||
|
||||
return $customers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves array of shops that are assigned to customer
|
||||
*
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return array {
|
||||
* @type int owner_id
|
||||
* @type string order_type
|
||||
* }
|
||||
*/
|
||||
public static function get_customer_shops($customer_id) {
|
||||
global $wpdb;
|
||||
|
||||
$results = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT customer_id, shop_owner_id, order_type
|
||||
FROM {$wpdb->prefix}wiaas_shop_customer_relationships
|
||||
WHERE customer_id = %d",
|
||||
$customer_id )
|
||||
);
|
||||
|
||||
if (empty($results)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$shops = array_map(function($result_row) {
|
||||
return array(
|
||||
'owner_id' => $result_row->shop_owner_id,
|
||||
'order_type' => $result_row->order_type
|
||||
);
|
||||
}, $results);
|
||||
|
||||
return $shops;
|
||||
}
|
||||
|
||||
public static function remove_shop($owner_id) {
|
||||
global $wpdb;
|
||||
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"DELETE FROM {$wpdb->prefix}wiaas_shop_customer_relationships
|
||||
WHERE shop_owner_id = %d",
|
||||
$owner_id )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
<?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();
|
||||
@@ -1,88 +0,0 @@
|
||||
<?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();
|
||||
@@ -1,413 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
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' ),
|
||||
'show_in_rest' => false,
|
||||
'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) {
|
||||
// if (! has_term($available_doc_type['name'], 'wiaas_doc_type')) {
|
||||
// wp_insert_term($available_doc_type['name'], 'wiaas_doc_type', array(
|
||||
// 'slug' => $key
|
||||
// ));
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Document::init();
|
||||
@@ -1,190 +0,0 @@
|
||||
<?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);
|
||||
}
|
||||
@@ -55,21 +55,23 @@ class Wiaas_Order_Project {
|
||||
public static function get_available_order_projects() {
|
||||
$all_terms = get_terms(array(
|
||||
'taxonomy' => 'shop_order_project',
|
||||
'hide_empty' => false,
|
||||
'meta_key' => '_wiaas_is_available',
|
||||
'meta_value' => 'yes'
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
if (is_wp_error($all_terms)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array_map(function($term) {
|
||||
return array(
|
||||
'id' => $term->term_id,
|
||||
'name' => $term->name
|
||||
);
|
||||
}, $all_terms);
|
||||
foreach ($all_terms as $term) {
|
||||
if (self::is_order_project_available($term->term_id)) {
|
||||
$available_terms[] = array(
|
||||
'id' => $term->term_id,
|
||||
'name' => $term->name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $available_terms;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -49,16 +49,6 @@ 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,24 +81,6 @@ 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
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
<?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) {
|
||||
if (! has_term($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();
|
||||
@@ -54,7 +54,7 @@ class Wiaas_Package_Type {
|
||||
$types = apply_filters('wiaas_package_types', array('standard'));
|
||||
|
||||
foreach ($types as $type) {
|
||||
wp_update_term($type, 'package_type');
|
||||
wp_insert_term($type, 'package_type');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,14 +88,4 @@ 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']);
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,26 @@ class Wiaas_Package_Pricing {
|
||||
);
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_update_product', array(__CLASS__, 'on_product_update' ), 10, 1 );
|
||||
|
||||
add_filter('woocommerce_bundle_price_html', array( __CLASS__, 'get_package_price_html' ), 10, 2);
|
||||
}
|
||||
|
||||
public static function get_package_price_html($price_html, $package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
|
||||
$recurring_price = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
if ($product_price['is_recurring']) {
|
||||
$recurring_price += $product_price['price'] * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
|
||||
$price_html = 'Fixed: ' . $price_html . ' and ' . $recurring_price . ' / month';
|
||||
|
||||
return $price_html;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,8 +101,8 @@ 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);
|
||||
public static function get_package_minimum_cost_margin($package){
|
||||
return self::_get_package_minimum_cost_margin($package);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,48 +110,21 @@ class Wiaas_Package_Pricing {
|
||||
* @param $package
|
||||
* @param $pricing_rules
|
||||
*/
|
||||
public static function set_package_prices($package, $pricing_rules, $commision, $max_cost_margin) {
|
||||
public static function set_package_prices($package, $pricing_rules, $commision, $minimum_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);
|
||||
$package->update_meta_data('_package_minimum_cost_margin', $minimum_cost_margin, true);
|
||||
} else {
|
||||
$package->delete_meta_data( '_wiaas_pricing_rules' );
|
||||
}
|
||||
$package->save_meta_data();
|
||||
|
||||
self::_validate_package($package);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
$pricing_rules = $package->get_meta( '_wiaas_pricing_rules' );
|
||||
|
||||
if (empty($pricing_rules)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$commision = self::_get_package_pricing_commision($package);
|
||||
|
||||
$prices = array();
|
||||
@@ -154,16 +145,6 @@ 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;
|
||||
@@ -179,24 +160,14 @@ 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);
|
||||
private static function _get_package_minimum_cost_margin($package) {
|
||||
$minimum_cost_margin = $package->get_meta( '_package_minimum_cost_margin', true);
|
||||
|
||||
if (!isset($max_cost_margin) || $max_cost_margin === '') {
|
||||
if (!isset($minimum_cost_margin) || $minimum_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);
|
||||
}
|
||||
return (float) $minimum_cost_margin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,80 +48,4 @@ function wiaas_get_recurrent_price_mortage($principal_amount, $pay_period, $marg
|
||||
function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
|
||||
$total_gain = $fixed_price + $principal_amount;
|
||||
return $total_gain - $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_hardware_procurement_cost($package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
|
||||
if (Wiaas_Product_Category::get_category($product) === 'hardware') {
|
||||
$total_cost += Wiaas_Pricing::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
|
||||
return $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_software_procurement_cost($package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
if (Wiaas_Product_Category::is_hardware($bundled_item->product)) {
|
||||
$total_cost += Wiaas_Pricing::get_product_total_cost($bundled_item->product) * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
|
||||
return $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_installation_procurement_cost($package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
if (Wiaas_Product_Category::is_installation($bundled_item->product)) {
|
||||
$installation_cost = Wiaas_Pricing::get_product_total_cost($bundled_item->product);
|
||||
$total_cost = $total_cost > $installation_cost ? $total_cost : $installation_cost;
|
||||
}
|
||||
}
|
||||
|
||||
return $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_one_time_services_procurement_cost($package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
if (Wiaas_Product_Category::is_service($bundled_item->product)) {
|
||||
|
||||
$price = Wiaas_Product_Pricing::get_product_price($bundled_item->product);
|
||||
if (! $price['is_recurring']) {
|
||||
$total_cost += Wiaas_Pricing::get_product_total_cost($bundled_item->product) * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $total_cost;
|
||||
}
|
||||
|
||||
function wiaas_get_package_recurring_services_procurement_cost($package) {
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
$total_cost = 0;
|
||||
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
if (Wiaas_Product_Category::is_service($bundled_item->product)) {
|
||||
|
||||
$price = Wiaas_Product_Pricing::get_product_price($bundled_item->product);
|
||||
if ( $price['is_recurring']) {
|
||||
$total_cost += $price['price'] * $bundled_item->get_quantity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $total_cost;
|
||||
}
|
||||
@@ -46,9 +46,7 @@ class Wiaas_Product_Category {
|
||||
public static function register_product_categories() {
|
||||
|
||||
foreach (self::$available_product_categories as $key => $available_product_category) {
|
||||
if (! has_term_meta($key)) {
|
||||
wp_update_term($key, 'product_cat');
|
||||
}
|
||||
wp_insert_term($key, 'product_cat');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,26 +83,6 @@ class Wiaas_Product_Category {
|
||||
return self::_get_product_category_type($product) === 'service';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if provided product is hardware
|
||||
* @param $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_hardware($product) {
|
||||
return self::_get_product_category_type($product) === 'hardware';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if provided product is software
|
||||
* @param $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_software($product) {
|
||||
return self::_get_product_category_type($product) === 'software';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// PRIVATE
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?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,
|
||||
'meta_box_cb' => false,
|
||||
'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();
|
||||
@@ -41,7 +41,6 @@ class Wiaas_Template_Category {
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'meta_box_cb' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'template_category' ),
|
||||
);
|
||||
|
||||
@@ -27,108 +27,7 @@ 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,17 +13,14 @@ class Wiaas_Customer {
|
||||
|
||||
public static function get_customer_info($customer_id){
|
||||
$user = get_userdata($customer_id);
|
||||
|
||||
$organization_id = wiaas_get_user_organization_id($customer_id);
|
||||
|
||||
$result = array(
|
||||
'id' => $customer_id,
|
||||
'company_id' => $organization_id,
|
||||
'company_id' => self::get_customer_company_id($customer_id),
|
||||
'is_company_admin' => self::get_customer_company_admin_status($customer_id),
|
||||
'mail' => $user->user_email,
|
||||
'name' => $user->first_name . ' ' . $user->last_name,
|
||||
'phone' => self::get_customer_phone_number($customer_id),
|
||||
'company_name' => wiaas_get_organization_name($organization_id),
|
||||
'company_name' => self::get_customer_company_name($customer_id),
|
||||
'vat_code' => self::get_customer_vat_code($customer_id),
|
||||
'billing_addresses' => self::get_customer_billing_addresses($customer_id),
|
||||
'profile_addresses' => self::get_customer_profile_addresses($customer_id),
|
||||
@@ -33,18 +30,6 @@ class Wiaas_Customer {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve available shops for customer
|
||||
*
|
||||
* @return array of available shops for customer
|
||||
*/
|
||||
public static function get_customer_shops() {
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
return Wiaas_Shop_DB::get_customer_shops($customer_id);
|
||||
}
|
||||
|
||||
public static function get_customer_profile_addresses($customer_id){
|
||||
return get_user_meta($customer_id, 'profile_addresses', true) ?: [];
|
||||
}
|
||||
@@ -95,6 +80,10 @@ class Wiaas_Customer {
|
||||
return get_user_meta($customer_id, 'company_name', true) ?: '';
|
||||
}
|
||||
|
||||
public static function get_customer_company_id($customer_id){
|
||||
return 0; //TODO: don't hardocde this
|
||||
}
|
||||
|
||||
public static function get_customer_company_admin_status($customer_id){
|
||||
return 1; //TODO: don't hardcode this
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
'plural' => __('Organizations', 'wiaas'),
|
||||
'exclusive' => true,
|
||||
'public' => true,
|
||||
'show_in_rest' => false,
|
||||
'show_in_rest' => true,
|
||||
'rest_base' => 'organization'
|
||||
);
|
||||
$labels = array();
|
||||
$caps = array();
|
||||
@@ -31,28 +32,13 @@ 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( 'delete_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_deleted' ));
|
||||
|
||||
add_action('acf/save_post', array(__CLASS__, 'on_organization_roles_maybe_updated'), 20);
|
||||
|
||||
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
|
||||
@@ -64,8 +50,6 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
*/
|
||||
public static function on_organization_added($organization_id) {
|
||||
self::_create_organization_access_group($organization_id);
|
||||
|
||||
do_action('wiaas_organization_created', $organization_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,39 +62,9 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
if ($taxonomy === self::TAXONOMY_NAME) {
|
||||
$organization_id = $term_id;
|
||||
self::_remove_organization_access_group($organization_id);
|
||||
|
||||
do_action('wiaas_organization_will_be_deleted', $organization_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes corresponding acces group when organization term is deleted
|
||||
*
|
||||
* @param $organization_id id of the organization term
|
||||
*/
|
||||
public static function on_organization_deleted($organization_id) {
|
||||
do_action('wiaas_organization_deleted', $organization_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id acf object id for which data has been updated,
|
||||
* for organization it will be in format `term_{$organization_id}`
|
||||
*/
|
||||
public static function on_organization_roles_maybe_updated($id) {
|
||||
if ($_POST['taxonomy'] === self::TAXONOMY_NAME) {
|
||||
$roles = get_field('_wiaas_organization_roles', $id);
|
||||
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
if ($id) {
|
||||
do_action('wiaas_organization_roles_updated', $id, $roles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds user to corresponding access groups when he is assigned to organization.
|
||||
* User will also be added to child organizations access groups.
|
||||
@@ -124,7 +78,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);
|
||||
}
|
||||
}
|
||||
@@ -141,7 +95,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);
|
||||
}
|
||||
}
|
||||
@@ -152,13 +106,13 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
* @param null $user_id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_user_organization_id($user_id = null) {
|
||||
public static function get_user_organization($user_id = null) {
|
||||
if (!isset($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
$user = wp_get_current_user();
|
||||
$user_id = $user->ID;
|
||||
}
|
||||
$organization_id = get_user_meta($user_id, '_wiaas_organization_id', true);
|
||||
|
||||
return empty($organization_id) ? null : (int) $organization_id;
|
||||
$terms = wp_get_object_terms($user_id, self::TAXONOMY_NAME);
|
||||
return $terms[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,10 +121,11 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
* to access order.
|
||||
*
|
||||
* @param $post_id - custom post id (product, order, ...)
|
||||
* @param $organization_id
|
||||
* @param $user_id
|
||||
*/
|
||||
public static function assign_post_to_organization($post_id, $organization_id) {
|
||||
self::_assign_post_to_organization( $post_id, $organization_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);
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +177,7 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
|
||||
private static function _assign_post_to_organization($post_id, $organization_id) {
|
||||
if (class_exists('Groups_Post_Access')) {
|
||||
$access_group_id = self::_get_organization_access_group_id($organization_id);
|
||||
Groups_Post_Access::create( array( 'post_id' => $post_id, 'group_id' => $access_group_id ) );
|
||||
Groups_Post_Access::update( array( 'post_id' => $post_id, 'groups_read' => [$access_group_id] ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,4 +240,73 @@ 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}";
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
<?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());
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements available wiaas countries
|
||||
*
|
||||
* Class Wiaas_Measurement_Units
|
||||
*/
|
||||
class Wiaas_Measurement_Units {
|
||||
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_measurement_units_taxonomy'));
|
||||
}
|
||||
|
||||
private static $available_units = array(
|
||||
'Piece' => array(
|
||||
'id' => 1,
|
||||
'name' => 'piece',
|
||||
'unit' => 'piece',
|
||||
),
|
||||
'Meter' => array(
|
||||
'id' => 1,
|
||||
'name' => 'meter',
|
||||
'unit' => 'm',
|
||||
),
|
||||
'Square' => array(
|
||||
'id' => 1,
|
||||
'name' => 'square_meter',
|
||||
'unit' => 'm2',
|
||||
),
|
||||
'Centimeter' => array(
|
||||
'id' => 1,
|
||||
'name' => 'centimeter',
|
||||
'unit' => 'cm',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers product taxonomy for avaiable countries
|
||||
*/
|
||||
public static function register_measurement_units_taxonomy() {
|
||||
|
||||
$labels = array(
|
||||
'name' => _x('Unit', 'taxonomy general name', 'wiaas'),
|
||||
'singular_name' => _x('Unit', 'taxonomy singular name', 'wiaas'),
|
||||
'menu_name' => _x('Unit', 'Admin menu name', 'wiaas'),
|
||||
'search_items' => __('Search Units', 'wiaas'),
|
||||
'all_items' => __('All Units', 'wiaas'),
|
||||
'parent_item' => __('Parent Unit', 'wiaas'),
|
||||
'parent_item_colon' => __('Parent Unit:', 'wiaas'),
|
||||
'edit_item' => __('Edit Unit', 'wiaas'),
|
||||
'update_item' => __('Update Unit', 'wiaas'),
|
||||
'add_new_item' => __('Add New Unit', 'wiaas'),
|
||||
'new_item_name' => __('New Unit Name', 'wiaas'),
|
||||
);
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'label' => __('Units', 'wiaas'),
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'meta_box_cb' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => array('slug' => 'wiaas_units'),
|
||||
);
|
||||
|
||||
register_taxonomy('wiaas_units', array('product'), $args);
|
||||
|
||||
foreach (self::$available_units as $available_unit) {
|
||||
wp_update_term($available_unit['unit'], 'wiaas_units');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Measurement_Units::init();
|
||||
@@ -37,6 +37,7 @@ 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'
|
||||
@@ -64,5 +65,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-general.php';
|
||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php';
|
||||
}
|
||||
|
||||
@@ -517,40 +517,38 @@ class Wiass_REST_Customer_Api_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @covers Wiass_REST_Customer_API::update_customer_company_info
|
||||
*
|
||||
* TODO: Fix this test to handle company info correctly
|
||||
*/
|
||||
// function test_update_customer_company_info() {
|
||||
// wp_set_current_user(1);
|
||||
//
|
||||
// $request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/company-info');
|
||||
// $request->set_body_params(array(
|
||||
// 'company_name' => 'Saburly',
|
||||
// 'vat_code' => '123'
|
||||
// ));
|
||||
// $response = $this->server->dispatch( $request );
|
||||
//
|
||||
// $this->assertNotNull($response);
|
||||
// $this->assertInstanceOf('WP_REST_Response',$response);
|
||||
// $this->assertFalse($response->is_error());
|
||||
// $this->assertEquals($response->get_status(), 200);
|
||||
//
|
||||
// $data = $response->get_data();
|
||||
//
|
||||
// $this->assertArrayHasKey('data', $data);
|
||||
// $this->assertArrayHasKey('messages', $data);
|
||||
//
|
||||
// $profile_info = $data['data'];
|
||||
// $messages = $data['messages'][0];
|
||||
//
|
||||
// $this->assertArrayHasKey('company_name', $profile_info);
|
||||
// $this->assertArrayHasKey('vat_code', $profile_info);
|
||||
// $this->assertEquals($profile_info['company_name'], 'Saburly');
|
||||
// $this->assertEquals($profile_info['vat_code'], '123');
|
||||
//
|
||||
// $this->assertArrayHasKey('message', $messages);
|
||||
// $this->assertEquals($messages['message'], 'COMPANY_UPDATED');
|
||||
// }
|
||||
function test_update_customer_company_info() {
|
||||
wp_set_current_user(1);
|
||||
|
||||
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/company-info');
|
||||
$request->set_body_params(array(
|
||||
'company_name' => 'Saburly',
|
||||
'vat_code' => '123'
|
||||
));
|
||||
$response = $this->server->dispatch( $request );
|
||||
|
||||
$this->assertNotNull($response);
|
||||
$this->assertInstanceOf('WP_REST_Response',$response);
|
||||
$this->assertFalse($response->is_error());
|
||||
$this->assertEquals($response->get_status(), 200);
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertArrayHasKey('data', $data);
|
||||
$this->assertArrayHasKey('messages', $data);
|
||||
|
||||
$profile_info = $data['data'];
|
||||
$messages = $data['messages'][0];
|
||||
|
||||
$this->assertArrayHasKey('company_name', $profile_info);
|
||||
$this->assertArrayHasKey('vat_code', $profile_info);
|
||||
$this->assertEquals($profile_info['company_name'], 'Saburly');
|
||||
$this->assertEquals($profile_info['vat_code'], '123');
|
||||
|
||||
$this->assertArrayHasKey('message', $messages);
|
||||
$this->assertEquals($messages['message'], 'COMPANY_UPDATED');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
<?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);
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user