Compare commits
181 Commits
commercial
...
forms-filt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b688e8a5e | ||
|
|
95d162578f | ||
|
|
798ad20534 | ||
|
|
61ff7dbc60 | ||
|
|
09fc3f8018 | ||
|
|
217dfb1889 | ||
|
|
8d954469ee | ||
|
|
68c760a426 | ||
|
|
35854d1367 | ||
|
|
3db4b71c3f | ||
|
|
3df6397280 | ||
|
|
e548e2a31c | ||
|
|
3d37a88247 | ||
|
|
30e5d594ad | ||
|
|
dd93677def | ||
|
|
4de01d93d1 | ||
|
|
2fdae06a59 | ||
|
|
d0533b3d6e | ||
|
|
35e670fa52 | ||
|
|
f56377f606 | ||
|
|
95a9fd2110 | ||
|
|
752df56d4a | ||
|
|
e1594f3a7f | ||
|
|
4f97df5b45 | ||
|
|
ef5cf00983 | ||
|
|
ca0fed674f | ||
|
|
fb66d56d9c | ||
|
|
a07c0e4584 | ||
|
|
3708c9fb30 | ||
|
|
c630452d0b | ||
|
|
a62de78172 | ||
|
|
14550d2ea9 | ||
|
|
56c171df3e | ||
|
|
337f031705 | ||
|
|
b7be6fde42 | ||
|
|
6c656a0b26 | ||
|
|
c4d539f549 | ||
|
|
0ba27b2f1d | ||
|
|
e6b372f5d0 | ||
|
|
16b51c87bb | ||
|
|
47b2214a99 | ||
|
|
c7bf4e8c03 | ||
|
|
15db815d01 | ||
|
|
c555571607 | ||
|
|
a1997a813d | ||
|
|
a77a97b922 | ||
|
|
99c203b920 | ||
|
|
053675b478 | ||
|
|
f34ce98655 | ||
|
|
6ef9936403 | ||
|
|
e0060dd69d | ||
|
|
d6528e75cf | ||
|
|
c9b04dac1e | ||
|
|
09b5779056 | ||
|
|
fcbddcb22a | ||
|
|
dd53584d20 | ||
|
|
c23e570399 | ||
|
|
f5e9aa7495 | ||
|
|
aef8347df3 | ||
|
|
75141b6bd1 | ||
|
|
e2952a240c | ||
|
|
afa370f403 | ||
|
|
b02f0881d3 | ||
|
|
0d62e7da4b | ||
|
|
3dcef84709 | ||
|
|
0600bbee9f | ||
|
|
75a574279b | ||
|
|
9e599617c4 | ||
|
|
bc310ed738 | ||
|
|
5d872a33da | ||
|
|
cedd4bf9e9 | ||
|
|
4e8b04fa8d | ||
|
|
1d097eda6f | ||
|
|
b7e4f7f49b | ||
|
|
5e55d296e5 | ||
|
|
27795387df | ||
|
|
3011c49474 | ||
|
|
0b54ce54f8 | ||
|
|
a6640548ef | ||
|
|
e8a3668c25 | ||
|
|
388f7df8a8 | ||
|
|
8d4f75cc41 | ||
|
|
24e8515b30 | ||
|
|
01b35dbac5 | ||
|
|
93e17817dc | ||
|
|
2a3f2f8245 | ||
|
|
a059f4b83d | ||
|
|
c08c393b2d | ||
|
|
f8e3cc5875 | ||
|
|
3af91a71d7 | ||
|
|
8eeb3b9927 | ||
|
|
3e4324546b | ||
|
|
b3ba1889b6 | ||
|
|
9e4ee644a0 | ||
|
|
d6c5a36e94 | ||
|
|
e6b6f6c136 | ||
|
|
9956a94c7c | ||
|
|
f8dd5f1d9f | ||
|
|
1f03563d2e | ||
|
|
9aa3b3d044 | ||
|
|
dbddcd47d3 | ||
|
|
b91341c5df | ||
|
|
69c74d9340 | ||
|
|
1ae60eb6eb | ||
|
|
00076b89fd | ||
|
|
26f997abbc | ||
|
|
cdbefc7ef0 | ||
|
|
8ffa5ddd3a | ||
|
|
4b0fc6c61d | ||
|
|
3d16d5027b | ||
|
|
165eb808b8 | ||
|
|
281f71d853 | ||
|
|
1a33593cbe | ||
|
|
46e2259359 | ||
|
|
26353f0d80 | ||
|
|
683cc68bb7 | ||
|
|
308c836460 | ||
|
|
5aca4e8572 | ||
|
|
51cb2af438 | ||
|
|
d2ce84b3fb | ||
|
|
bc39a69b7a | ||
|
|
f5766cda99 | ||
|
|
45090fa05f | ||
|
|
42c9f07195 | ||
|
|
06e7461245 | ||
|
|
0926030133 | ||
|
|
a94afea151 | ||
|
|
ef020f57e5 | ||
|
|
892571b179 | ||
|
|
1b5b8e2595 | ||
|
|
0b4243e368 | ||
|
|
d1a6d1a4d8 | ||
|
|
59e60bef4d | ||
|
|
e524e6d0d5 | ||
|
|
29ccb136d0 | ||
|
|
e41b643fc5 | ||
|
|
aec480d110 | ||
|
|
b0e6cbd9b2 | ||
|
|
e1589ee561 | ||
|
|
66452eee86 | ||
|
|
18f40d9403 | ||
|
|
69773c77a7 | ||
|
|
e3869e720b | ||
|
|
00999122a2 | ||
|
|
09aac81276 | ||
|
|
790d24a1f6 | ||
|
|
3d6f15dd4f | ||
|
|
5570cf7f91 | ||
|
|
e420953c39 | ||
|
|
21fafc5a43 | ||
|
|
87f408125d | ||
|
|
37916e4931 | ||
|
|
a07b3fb7d9 | ||
|
|
f76e102bf3 | ||
|
|
5a6f876c69 | ||
|
|
9b5cc3a978 | ||
|
|
038b622eca | ||
|
|
e4ed26de7d | ||
|
|
094a7bd56c | ||
|
|
67dc8d7d69 | ||
|
|
3ccea1804e | ||
|
|
315ac70484 | ||
|
|
c4cddf8ace | ||
|
|
00e853ae6b | ||
|
|
071c549726 | ||
|
|
d22ea58568 | ||
|
|
d3c280548b | ||
|
|
1ed7310994 | ||
|
|
76e9b10235 | ||
|
|
6b0dd0b5a9 | ||
|
|
6d65a5f30c | ||
|
|
c8ed5f7ff8 | ||
|
|
49281f02be | ||
|
|
b7ab761a25 | ||
|
|
0238f9140e | ||
|
|
4d13ee40bc | ||
|
|
6c27afabfc | ||
|
|
755fc75ae9 | ||
|
|
ecde654ae9 | ||
|
|
8769606a4b | ||
|
|
afab22a30b |
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
||||
# Added to prevent permission problems when building without using super user privileges
|
||||
|
||||
./database/volume
|
||||
./docker/backend/uploads
|
||||
./log/backend
|
||||
./log/frontend
|
||||
@@ -18,6 +18,9 @@ ARG WP_SECURE_AUTH_SALT
|
||||
ARG WP_LOGGED_IN_SALT
|
||||
ARG WP_NONCE_SALT
|
||||
ARG WP_JWT_AUTH_SECRET_KEY
|
||||
ARG WP_SENDGRID_API_KEY
|
||||
ARG WP_SENDGRID_FROM_EMAIL
|
||||
ARG WP_SENDGRID_FROM_NAME
|
||||
|
||||
ENV WP_ENV ${WP_ENV}
|
||||
ENV WP_HOME ${API_URL}
|
||||
@@ -37,9 +40,13 @@ 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 WP_SENDGRID_API_KEY ${WP_SENDGRID_API_KEY}
|
||||
ENV WP_SENDGRID_FROM_EMAIL ${WP_SENDGRID_FROM_EMAIL}
|
||||
ENV WP_SENDGRID_FROM_NAME ${WP_SENDGRID_FROM_NAME}
|
||||
|
||||
ENV WIAAS_CUSTOMER_INTERFACE ${WIAAS_CUSTOMER_INTERFACE}
|
||||
|
||||
RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo
|
||||
RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo libpng-dev
|
||||
|
||||
COPY docker/php/composer.phar /usr/local/bin/composer
|
||||
RUN chmod 755 /usr/local/bin/composer
|
||||
@@ -50,8 +57,9 @@ RUN chmod +x /usr/local/bin/wp
|
||||
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 ssl
|
||||
RUN docker-php-ext-install pdo pdo_mysql mysqli opcache gd zip mbstring
|
||||
RUN a2enmod rewrite
|
||||
COPY docker/php/000-default.conf /etc/apache2/sites-available
|
||||
|
||||
COPY backend /home/wiaas/backend
|
||||
|
||||
@@ -59,13 +67,17 @@ WORKDIR /home/wiaas/backend/
|
||||
RUN composer install --no-dev
|
||||
|
||||
WORKDIR /home/wiaas
|
||||
RUN rm -rf backend/app/uploads
|
||||
RUN cp -r backend/* /var/www/html/
|
||||
|
||||
WORKDIR home
|
||||
RUN rm -rf wiaas
|
||||
|
||||
WORKDIR /var/www/html
|
||||
RUN ln -s ../html api
|
||||
|
||||
COPY docker/php/.htaccess /var/www/html/
|
||||
COPY docker/php/.htaccess /var/www/html/
|
||||
COPY docker/backend/TaC.pdf /var/www/html/
|
||||
|
||||
RUN chown -R www-data:www-data /var/www/html
|
||||
|
||||
|
||||
@@ -15,3 +15,50 @@
|
||||
#createuser .acf-taxonomy-field, #your-profile .acf-taxonomy-field {
|
||||
width: 25em;
|
||||
}
|
||||
|
||||
.wc-order-preview footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.gravityflow-discussion-item{
|
||||
margin-bottom:10px;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.gravityflow-dicussion-item-name {
|
||||
color:black;
|
||||
font-weight:bold;
|
||||
}
|
||||
|
||||
.gravityflow-dicussion-item-date {
|
||||
color: #9b9b9b;
|
||||
margin-left:8px;
|
||||
font-size:90%;
|
||||
}
|
||||
|
||||
.rtl .gravityflow-dicussion-item-date {
|
||||
margin-right:8px;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.gravityflow-dicussion-item-toggle-display {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.rtl .gravityflow-dicussion-item-toggle-display {
|
||||
float: left;
|
||||
}
|
||||
|
||||
@media print {
|
||||
.gravityflow-dicussion-item-hidden {
|
||||
display:block !important;
|
||||
}
|
||||
|
||||
.gravityflow-dicussion-item-toggle-display {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.gravityflow-dicussion-item-value {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
@@ -4,4 +4,8 @@
|
||||
|
||||
#menu-posts-product .wp-submenu li:last-child {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.woocommerce-BlankState .button {
|
||||
display: none !important
|
||||
}
|
||||
@@ -30,19 +30,9 @@
|
||||
}
|
||||
|
||||
#wiaas_package_pricing_rules > .wiaas-pricing-rule {
|
||||
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;
|
||||
border:1px #dfdfdf solid;
|
||||
background-color:#fff;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
#wiaas_package_pricing_rules > .wiaas-pricing-rule .section {
|
||||
@@ -133,4 +123,12 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.wc-order-preview-address {
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
$('.wiaas_delivery_step_nav').click(function (e) {
|
||||
var action = $(this).data('step');
|
||||
|
||||
$('#wiaas_delivery_process_navigation_action').val(action);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,150 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
57
backend/app/plugins/wiaas/assets/js/wiaas-admin-package.js
Normal file
57
backend/app/plugins/wiaas/assets/js/wiaas-admin-package.js
Normal file
@@ -0,0 +1,57 @@
|
||||
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');
|
||||
|
||||
|
||||
$( '.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: element.data('search-nonce')
|
||||
} ).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: element.data('link-nonce'),
|
||||
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();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
jQuery(document).ready(function($) {
|
||||
$( document.body )
|
||||
.on( 'wc_backbone_modal_loaded', function () {
|
||||
$(".wc-order-preview-address").remove();
|
||||
} );
|
||||
|
||||
});
|
||||
14
backend/app/plugins/wiaas/assets/js/wiaas-form-editor.js
Normal file
14
backend/app/plugins/wiaas/assets/js/wiaas-form-editor.js
Normal file
@@ -0,0 +1,14 @@
|
||||
jQuery(document).bind('gform_load_field_settings', function (event, field, form) {
|
||||
|
||||
var isBundleDoc = field.type === 'wiaas_order_bundle_document';
|
||||
|
||||
var isOrderDoc = field.type === 'wiaas_order_document';
|
||||
|
||||
if (isBundleDoc || isOrderDoc) {
|
||||
|
||||
jQuery('#wiaas-doc-type-filter').val(field.wiaasDocTypeFilter);
|
||||
}
|
||||
|
||||
jQuery('#wiaas-installation-organization-filter').prop('checked', !!field.wiaasOnlyInstallationOrg);
|
||||
|
||||
});
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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();
|
||||
@@ -0,0 +1,126 @@
|
||||
<?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();
|
||||
@@ -60,8 +60,6 @@ class Wiaas_Admin_CL_Packages {
|
||||
|
||||
if ($screen->id === 'admin_page_wiaas-cl-product') {
|
||||
|
||||
error_log('set parent');
|
||||
|
||||
$parent_file = 'edit.php?post_type=product';
|
||||
}
|
||||
}
|
||||
@@ -150,6 +148,7 @@ class Wiaas_Admin_CL_Packages {
|
||||
|
||||
$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'];
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
<?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>
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_Supplier_Orders
|
||||
*/
|
||||
class Wiaas_Admin_Supplier_Orders {
|
||||
|
||||
/**
|
||||
* Displays list of orders from supplier
|
||||
*
|
||||
* 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 suppliershould 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 supplier
|
||||
*
|
||||
* @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 simple products from this supplier on order preview
|
||||
*
|
||||
* @param $order_items
|
||||
* @param $order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_order_items_for_order_preview($order_items, $order) {
|
||||
|
||||
$user_organisation_id = Wiaas_User_Organization::get_user_organization_id(wp_get_current_user()->ID);
|
||||
|
||||
$items = array();
|
||||
|
||||
foreach ($order_items as $key => $order_item) {
|
||||
|
||||
$product = wc_get_product($order_item->get_product_id());
|
||||
|
||||
if ($product->get_type() == 'simple') {
|
||||
|
||||
$supplier_organisation_id = Wiaas_Product_Supplier
|
||||
::get_supplier_organisation_id_from_product($order_item->get_product_id());
|
||||
|
||||
if ($supplier_organisation_id === $user_organisation_id) {
|
||||
$items[$key] = $order_item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override default table columns so only supplier 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' );
|
||||
|
||||
return $show_columns;
|
||||
}
|
||||
|
||||
|
||||
/** Append supplier 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 supplier 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_Supplier_Orders::init();
|
||||
@@ -13,14 +13,19 @@ class Wiaas_Admin_CL {
|
||||
|
||||
public static function init_admin_cl() {
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
$role = $user->roles[0];
|
||||
$role = $current_user->roles[0];
|
||||
|
||||
if ($role === 'commercial_lead') {
|
||||
$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 );
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Countries {
|
||||
|
||||
public static function init() {
|
||||
|
||||
// Add countries fields to countries list
|
||||
add_filter( 'manage_edit-product_country_columns', array( __CLASS__, 'update_list_headers' ) );
|
||||
add_filter( 'manage_product_country_custom_column', array( __CLASS__, 'update_list_column_content' ), 10, 3 );
|
||||
|
||||
// Validate country settings
|
||||
add_filter('acf/load_field/name=_wiaas_country_code', array(__CLASS__, 'populate_country_codes'));
|
||||
add_filter('acf/load_field/name=_wiaas_country_currency', array(__CLASS__, 'populate_country_currencies'));
|
||||
}
|
||||
|
||||
public static function update_list_headers($columns) {
|
||||
$columns['wiaas_code'] = __( 'Code', 'wiaas' );
|
||||
|
||||
$columns['wiaas_vat'] = __('VAT', 'wiaas');
|
||||
|
||||
$columns['wiaas_currency'] = __('Currency', 'wiaas');
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public static function update_list_column_content($columns, $column, $id) {
|
||||
|
||||
if ($column === 'wiaas_code') {
|
||||
|
||||
$code = get_term_meta($id, '_wiaas_country_code', true);
|
||||
$columns .= '<span>'. $code . '</span>';
|
||||
}
|
||||
|
||||
if ($column === 'wiaas_vat') {
|
||||
|
||||
$vat = get_term_meta($id, '_wiaas_country_vat', true);
|
||||
$columns .= '<span>'. $vat . '</span>';
|
||||
}
|
||||
|
||||
if ($column === 'wiaas_currency') {
|
||||
|
||||
$currency = get_term_meta($id, '_wiaas_country_currency', true);
|
||||
$columns .= '<span>'. $currency . '</span>';
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public static function populate_country_codes($field) {
|
||||
$countries_list = Wiaas_Countries::get_country_choices();
|
||||
|
||||
$countries_choices = array();
|
||||
foreach ($countries_list as $code => $name) {
|
||||
|
||||
$countries_choices[$code] = $code . ' - ' . $name;
|
||||
}
|
||||
|
||||
$field['choices'] = $countries_choices;
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public static function populate_country_currencies($field) {
|
||||
|
||||
$field['choices'] = Wiaas_Countries::get_currency_choices();
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Countries::init();
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Delivery_Process {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/wiaas-admin-delivery-process-ajax.php';
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-flow.php';
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-order.php';
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-list.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_delivery_process', $plugin_url . '/assets/js/wiaas-admin-delivery-process.js' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Delivery_Process::init();
|
||||
@@ -3,10 +3,6 @@
|
||||
class Wiaas_Admin_Order_Projects {
|
||||
|
||||
public static function init() {
|
||||
// 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' ) );
|
||||
@@ -19,31 +15,20 @@ class Wiaas_Admin_Order_Projects {
|
||||
// Save is available field when creating and editing
|
||||
add_action( 'created_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
|
||||
add_action( 'edit_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
|
||||
|
||||
add_action( 'load-term.php', array( __CLASS__, 'admin_menu_highlight' ) );
|
||||
add_action( 'load-edit-tags.php', array( __CLASS__, 'admin_menu_highlight' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin submenu page for order projects
|
||||
* Highlighting orders menu when shop orders page selected
|
||||
*/
|
||||
public static function add_admin_page() {
|
||||
add_submenu_page( 'woocommerce',
|
||||
esc_html__( 'Order projects', 'wiaas' ),
|
||||
esc_html__( 'Order projects', 'wiaas' ),
|
||||
'manage_woocommerce',
|
||||
'edit-tags.php?taxonomy=shop_order_project'
|
||||
);
|
||||
}
|
||||
public static function admin_menu_highlight() {
|
||||
global $plugin_page;
|
||||
|
||||
/**
|
||||
* 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';
|
||||
if ( isset( $_GET['taxonomy'] ) && ( $_GET['taxonomy'] === 'shop_order_project' ) ) {
|
||||
$plugin_page = 'edit.php?post_type=shop_order';
|
||||
}
|
||||
return $parent_file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,8 +14,17 @@ class Wiaas_Admin_Organization {
|
||||
|
||||
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'), 11);
|
||||
|
||||
// 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() {
|
||||
@@ -26,6 +35,65 @@ class Wiaas_Admin_Organization {
|
||||
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));
|
||||
|
||||
$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
|
||||
@@ -158,7 +226,7 @@ class Wiaas_Admin_Organization {
|
||||
// get current user
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
update_user_meta($current_user->ID, '_wiaas_current_user_admin_role', $role->name);
|
||||
update_user_meta($current_user->ID, '_wiaas_admin_role', $role->name);
|
||||
|
||||
// switch user role
|
||||
$current_user->set_role($role->name);
|
||||
|
||||
@@ -10,6 +10,42 @@ class Wiaas_Admin_Package {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-linked-packages.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-package-types.php';
|
||||
|
||||
add_action( 'manage_product_posts_columns', array( __CLASS__, 'manage_list_table_products_columns' ), 999, 2 );
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ), 999);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
unset($tabs['inventory']);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('acf/save_post', array(__CLASS__, 'save_initial_product_country_and_type'), 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__, '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=group', array(__CLASS__, 'render_choose_button_for_new_product'), 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 render_choose_button_for_new_product($field) {
|
||||
|
||||
if ($field['_name'] === '_wiaas_product_general') {
|
||||
?>
|
||||
<div id="submitpost" style="padding: 20px 0;">
|
||||
<input style="float:right;" name="publish" id="publish" class="button button-large button-primary" type="submit" value="Choose"/>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function 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 === '_wiaas_no_country') {
|
||||
|
||||
remove_meta_box('woocommerce-product-data', 'product', 'normal');
|
||||
remove_meta_box('slugdiv', 'product', 'normal');
|
||||
remove_meta_box('postexcerpt', 'product', 'normal');
|
||||
remove_meta_box('template_product_meta_box', 'product', 'normal');
|
||||
|
||||
remove_meta_box('submitdiv', 'product', 'side');
|
||||
|
||||
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('wiaas_upload_and_link_document', 'product', 'side');
|
||||
remove_meta_box('tagsdiv-product_country', '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('product_catdiv', 'product', 'side');
|
||||
|
||||
// Always hide
|
||||
remove_meta_box('tagsdiv-product_country', '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 save_initial_product_country_and_type($post_id) {
|
||||
|
||||
global $post;
|
||||
|
||||
if ($post->post_type !== 'product') {
|
||||
return;
|
||||
}
|
||||
|
||||
$general = get_field('_wiaas_product_general', $post_id);
|
||||
|
||||
$country = $general['_wiaas_product_country'];
|
||||
$type = $general['_wiaas_product_type'];
|
||||
|
||||
/**
|
||||
* If type is missing set status to no country
|
||||
*
|
||||
* If this is not template product type and country is missing set status to no country
|
||||
*
|
||||
*/
|
||||
if (empty($type) || ( empty($country) && $type !== 'wiaastemplate' )) {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => '_wiaas_no_country'
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Country and type are selected for simple and bundle products so
|
||||
* link them
|
||||
*/
|
||||
|
||||
wp_set_object_terms($post_id, $type, 'product_type', true);
|
||||
|
||||
if ($type !== 'wiaastemplate') {
|
||||
wp_set_object_terms($post_id, $country, 'product_country', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* If product had no country status change it to draft status
|
||||
*/
|
||||
|
||||
if ($post->post_status === '_wiaas_no_country') {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'draft'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product::init();
|
||||
@@ -0,0 +1,13 @@
|
||||
<?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();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
class Wiaas_Admin_Supplier {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('init', array(__CLASS__, 'init_admin_supplier'));
|
||||
}
|
||||
|
||||
public static function init_admin_supplier() {
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
$role = $current_user->roles[0];
|
||||
|
||||
$is_supplier = $role === 'supplier';
|
||||
|
||||
if ($is_supplier) {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-supplier/class-wiaas-admin-supplier-orders.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-supplier', $plugin_url . '/assets/js/wiaas-admin-supplier.js' );
|
||||
|
||||
wp_enqueue_style( 'wiaas-admin-supplier', $plugin_url . '/assets/css/wiaas-admin-supplier.css' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Supplier::init();
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Profile {
|
||||
|
||||
public static function init() {
|
||||
add_filter( 'user_contactmethods', array(__CLASS__, 'modify_user_contact_methods') );
|
||||
|
||||
add_action( 'user_profile_update_errors', array(__CLASS__, 'crf_user_profile_update_errors'), 10, 3 );
|
||||
|
||||
}
|
||||
|
||||
public static function crf_user_profile_update_errors( $errors, $update, $user ) {
|
||||
|
||||
$phone = $_POST['phone'];
|
||||
|
||||
if (!Wiaas_Validation::is_phone($phone)){
|
||||
$errors->add('phone_error', __( '<strong>ERROR</strong>: Enter valid phone number.', 'crf' ));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static function modify_user_contact_methods($user_contact){
|
||||
$user_contact['phone'] = __( 'Phone number' );
|
||||
|
||||
return $user_contact;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Profile::init();
|
||||
@@ -0,0 +1,437 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Order_Process_Flow {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'gravityflow_entry_detail', array( __CLASS__, 'display_process_steps_details' ), 10, 3 );
|
||||
|
||||
//add_action( 'gravityflow_title_entry_detail', array( __CLASS__, 'process_title' ), 10, 3 );
|
||||
|
||||
add_action('gravityflow_entry_detail', array(__CLASS__, 'add_delivery_dates_box'), 9, 3);
|
||||
|
||||
add_action('gravityflow_entry_detail', array(__CLASS__, 'maybe_display_delivery_process_navigation'), 9, 3);
|
||||
|
||||
add_action('gravityflow_workflow_detail_sidebar', array(__CLASS__, 'render_procurement_order_download_link'), 10, 3);
|
||||
|
||||
add_filter('gravityflow_admin_action_feedback', array(__CLASS__, 'maybe_process_admin_step_change_action'), 10, 4);
|
||||
|
||||
add_filter('gravityflow_admin_actions_workflow_detail', array(__CLASS__, 'filter_workflow_admin_actions'), 10, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter workflow admin actions
|
||||
*
|
||||
* @param $admin_actions
|
||||
* @param $current_step
|
||||
* @param $steps
|
||||
* @param $form
|
||||
* @param $entry
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_workflow_admin_actions($admin_actions, $current_step, $steps, $form, $entry) {
|
||||
|
||||
$allowed_actions = array();
|
||||
|
||||
// allow basic admin actions for step action workflow
|
||||
if (Wiaas_Delivery_Process_Action::is_action_form($form)) {
|
||||
|
||||
$allowed_actions = array( 'cancel_workflow', 'restart_workflow', 'restart_step');
|
||||
}
|
||||
|
||||
$filtered_admin_actions = array();
|
||||
|
||||
foreach ( $admin_actions as $admin_action ) {
|
||||
|
||||
if (in_array($admin_action['value'], $allowed_actions)) {
|
||||
$filtered_admin_actions[] = $admin_action;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered_admin_actions;
|
||||
}
|
||||
|
||||
public static function render_procurement_order_download_link($form, $entry, $current_step) {
|
||||
|
||||
if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) ||
|
||||
empty( $current_step ) ||
|
||||
Wiaas_Delivery_Process_Action::is_action_form($form) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<h3 class="hndle">
|
||||
<?php esc_html_e('Procurement report', 'wiaas') ?>
|
||||
</h3>
|
||||
<div style="padding: 10px;">
|
||||
<a
|
||||
id="wiaas_download_procurement_order_btn"
|
||||
href="<?php echo admin_url() . '?wiaas-procurement-order-id=' . $order_id ?>"
|
||||
download
|
||||
class="button"
|
||||
>
|
||||
<span><?php esc_html_e('Download procurement report', 'wiaas') ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
public static function add_delivery_dates_box($form, $entry, $current_step) {
|
||||
|
||||
if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) ||
|
||||
empty( $current_step ) || Wiaas_Delivery_Process_Action::is_action_form($form) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$workflow_api = new Gravity_Flow_API($form['id']);
|
||||
$steps = $workflow_api->get_steps();
|
||||
|
||||
/**
|
||||
* Disable if:
|
||||
* - actions for customer config validation is not done
|
||||
* - action for customer acceptance is active or completed
|
||||
*/
|
||||
$is_disabled = false;
|
||||
foreach ($steps as $step) {
|
||||
|
||||
if (Wiaas_Delivery_Process_Action::process_step_has_customer_validate_questionnaires_action($step) &&
|
||||
$step->get_status() !== 'complete') {
|
||||
|
||||
$is_disabled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Wiaas_Delivery_Process_Action::process_step_has_customer_acceptance_action($step) &&
|
||||
($step->get_id() === $current_step->get_id() || $step->get_status() === 'complete')) {
|
||||
|
||||
$is_disabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
|
||||
$suppliers = Wiaas_Order::get_suppliers($order_id);
|
||||
$final_estimated_date = Wiaas_Order::get_final_estimated_date($order_id);
|
||||
$final_confirmed_date = Wiaas_Order::get_final_confirmed_date($order_id);
|
||||
$earliest_installation_date = Wiaas_Order::get_earliest_installation_date($order_id);
|
||||
|
||||
require 'views/html-order-suppliers-delivery-dates.php';
|
||||
}
|
||||
|
||||
public static function maybe_process_admin_step_change_action($feedback, $admin_action, $form, $entry) {
|
||||
|
||||
$admin_action = rgpost( 'wiaas_delivery_process_navigation_action' );
|
||||
|
||||
if ($admin_action === 'complete') {
|
||||
|
||||
$api = new Gravity_Flow_API( $form['id'] );
|
||||
|
||||
$current_step = $api->get_current_step($entry);
|
||||
|
||||
if ( $current_step ) {
|
||||
$current_step->purge_assignees();
|
||||
$current_step->update_step_status( 'complete' );
|
||||
}
|
||||
|
||||
$api->process_workflow($entry['id']);
|
||||
|
||||
$feedback = esc_html__( 'Workflow Complete', 'wiaas' );
|
||||
|
||||
return $feedback;
|
||||
}
|
||||
|
||||
list( $base_admin_action, $action_id ) = rgexplode( '|', $admin_action, 2 );
|
||||
|
||||
if ( $base_admin_action == 'send_to_step' ) {
|
||||
$step_id = $action_id;
|
||||
$api = new Gravity_Flow_API( $form['id'] );
|
||||
$api->send_to_step( $entry, $step_id );
|
||||
$entry = GFAPI::get_entry( $entry['id'] );
|
||||
$new_step = $api->get_current_step( $entry );
|
||||
$feedback = $new_step ?
|
||||
sprintf( esc_html__( 'Sent to step: %s', 'wiaas' ), $new_step->get_name() ) :
|
||||
esc_html__( 'Workflow Complete', 'wiaas' );
|
||||
}
|
||||
|
||||
return $feedback;
|
||||
}
|
||||
|
||||
public static function maybe_display_delivery_process_navigation($form, $entry, $current_step) {
|
||||
|
||||
if(! GFAPI::current_user_can_any( 'gravityflow_workflow_detail_admin_actions' ) ||
|
||||
empty( $current_step ) ||
|
||||
Wiaas_Delivery_Process_Action::is_action_form($form) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$steps = gravity_flow()->get_steps($form['id'], $entry);
|
||||
|
||||
// get next step id
|
||||
$next_step = gravity_flow()->get_next_step($current_step, $entry, $form);
|
||||
$next_step_id = empty($next_step) ? null : $next_step->get_id();
|
||||
|
||||
// get previous step id
|
||||
foreach ($steps as $step) {
|
||||
|
||||
$next = gravity_flow()->get_next_step($step, $entry, $form);
|
||||
if ($next && $next->get_id() === $current_step->get_id()) {
|
||||
$previous_step = $step;
|
||||
}
|
||||
}
|
||||
$previous_step_id = empty($previous_step) ? null : $previous_step->get_id();
|
||||
|
||||
// bail out if none exist
|
||||
if ( empty($next_step_id) && empty($previous_step_id) ) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @reference Gravity_Flow::maybe_process_admin_action for used field names
|
||||
* which are being checked there
|
||||
*
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<div style="padding:10px; height:40px">
|
||||
|
||||
<input id="wiaas_delivery_process_navigation_action" type="hidden" name="wiaas_delivery_process_navigation_action">
|
||||
<input type="hidden" name="_gravityflow_admin_action" value="1">
|
||||
|
||||
<input
|
||||
data-step="<?php echo empty($next_step_id) ? 'complete' : 'send_to_step|'.$next_step_id ?>"
|
||||
type="submit"
|
||||
class="button button-primary wiaas_delivery_step_nav"
|
||||
style="float:right; margin-left: 20px;"
|
||||
value="<?php echo empty($next_step_id) ? 'COMPLETE' : 'NEXT STEP' ?>"
|
||||
>
|
||||
|
||||
<input
|
||||
data-step="send_to_step|<?php esc_attr_e($previous_step_id, 'wiaas') ?>"
|
||||
type="submit"
|
||||
<?php disabled(empty($previous_step_id), true, true) ?>
|
||||
class="button button-primary wiaas_delivery_step_nav"
|
||||
style="float:right;" value="PREV STEP">
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function display_process_steps_details($form, $entry, $current_step) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
if ($delivery_settings['delivery_form_type'] === 'action') {
|
||||
return;
|
||||
}
|
||||
|
||||
// get process order ID
|
||||
$order_id = absint($entry['wiaas_delivery_order_id']);
|
||||
|
||||
if (empty($order_id)) {
|
||||
|
||||
$order_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order') )[0];
|
||||
|
||||
if ( ! empty($order_field)) {
|
||||
|
||||
$order_id = $entry[$order_field->id];
|
||||
}
|
||||
}
|
||||
|
||||
// display process steps
|
||||
|
||||
$workflow_api = new Gravity_Flow_API($form['id']);
|
||||
|
||||
$steps = $workflow_api->get_steps();
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<h3>
|
||||
<i class="fa fa-circle" style="font-size: 22px; margin-right: 10px;color: #34C388; "></i>
|
||||
<span>Order placed </span>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="postbox">
|
||||
<h3>
|
||||
<i class="fa fa-circle" style="font-size: 22px; margin-right: 10px;color: #34C388; "></i>
|
||||
<span> Assign process </span>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
foreach ($steps as $index => $step) {
|
||||
|
||||
if (! $step->is_active()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_step_completed = $step->get_status() === 'complete' || $step->get_status() === 'approved';
|
||||
$is_current_step = $current_step && $step->get_id() === $current_step->get_id();
|
||||
|
||||
if ($is_current_step) {
|
||||
$style = 'color: #FD8049;';
|
||||
} else if ($is_step_completed) {
|
||||
$style = 'color: #34C388;';
|
||||
} else {
|
||||
$style = 'opacity: 0.5; color: #CCC;';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
|
||||
<h3>
|
||||
<i class="fa fa-circle" style="font-size: 22px; margin-right: 10px; <?php esc_attr_e($style, 'wiaas') ?>"></i>
|
||||
<span><?php esc_html_e($step->get_name(), 'wiaas') ?></span>
|
||||
</h3>
|
||||
|
||||
<?php
|
||||
Gravity_Flow_Entry_Detail::maybe_show_instructions(true, true, $current_step, $form, $entry);
|
||||
|
||||
$action_form = GFAPI::get_form( $step->target_form_id );
|
||||
|
||||
if (empty($action_form)) {
|
||||
|
||||
echo '</div>';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$page_size = 20;
|
||||
$search_criteria = array(
|
||||
'status' => 'active',
|
||||
'field_filters' => array(
|
||||
array( 'key' => 'wiaas_delivery_process_id',
|
||||
'value' => $entry['id']
|
||||
),
|
||||
),
|
||||
);
|
||||
$sorting = array( 'key' => 'date_created', 'direction' => 'DESC' );
|
||||
$paging = array( 'offset' => 0, 'page_size' => $page_size );
|
||||
|
||||
$entries = GFAPI::get_entries( $action_form['id'], $search_criteria, $sorting, $paging );
|
||||
|
||||
if (empty($entries)) {
|
||||
|
||||
echo '</div>';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="submitbox" style="padding: 10px;">
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<?php
|
||||
echo '<br><br><br>';
|
||||
|
||||
|
||||
foreach ($entries as $action_entry) {
|
||||
self::_display_step_action_entry($action_form, $action_entry);
|
||||
}
|
||||
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
?>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private static function _display_step_action_entry($action_form, $action_entry) {
|
||||
$workflow_api = new Gravity_Flow_API($action_entry['form_id']);
|
||||
|
||||
$current_action_step = $workflow_api->get_current_step($action_entry);
|
||||
|
||||
$entry_url = add_query_arg( array(
|
||||
'page' => 'gravityflow-inbox',
|
||||
'view' => 'entry',
|
||||
'id' => $action_entry['form_id'],
|
||||
'lid' => $action_entry['id']
|
||||
), admin_url() );
|
||||
|
||||
|
||||
?>
|
||||
<table>
|
||||
|
||||
<?php
|
||||
foreach ($action_form['fields'] as $field) {
|
||||
|
||||
if ($field->type === 'wiaas_order') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($field->type === 'workflow_discussion') {
|
||||
|
||||
echo '<tr style="padding: 20px;"><td colspan="2">' . $field->format_discussion_value($action_entry[$field->id]) . '</td></tr>';
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $field->get_value_entry_detail($action_entry[$field->id]);
|
||||
$label = $field->get_field_label(false, $action_entry[$field->id]);
|
||||
|
||||
echo '<tr>' .
|
||||
'<td><strong>' . $label . ' : </strong></td>' .
|
||||
'<td>' . $value . '</td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2" style="text-transform: uppercase;font-size: 11px; letter-spacing: 0.4px; margin:10px;">
|
||||
<strong>
|
||||
|
||||
<?php
|
||||
|
||||
echo empty($current_action_step) ?
|
||||
$workflow_api->get_status($action_entry) :
|
||||
$current_action_step->get_status_label($current_action_step->get_status()) . ': ' . $current_action_step->get_name();;
|
||||
|
||||
echo '<a target="_blank" href="' . $entry_url . '">' .
|
||||
' <i class="fa fa-external-link" style="font-size: 16px;"></i>' .
|
||||
'</a>';
|
||||
|
||||
?>
|
||||
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
?>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Order_Process_Flow::init();
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Delivery_Process_List {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('gform_form_list_columns', array( __CLASS__, 'filter_gform_form_list_columns' ));
|
||||
|
||||
add_filter('gform_form_list_forms', array( __CLASS__, 'filter_gform_form_list_forms' ), 10, 6);
|
||||
|
||||
add_filter('gform_form_actions', array( __CLASS__, 'filter_gform_form_actions' ), 10, 2);
|
||||
|
||||
add_action('gform_form_list_column_wiaas_country', array( __CLASS__, 'render_gform_form_list_wiaas_country_column' ));
|
||||
|
||||
add_action('gform_form_list_column_wiaas_actions', array( __CLASS__, 'render_gform_form_list_wiaas_actions_column' ));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide not needed columns for delivery process list
|
||||
* Add country column
|
||||
* Add actions column
|
||||
*
|
||||
* @param array $columns
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filter_gform_form_list_columns($columns) {
|
||||
|
||||
unset($columns['entry_count']);
|
||||
unset($columns['conversion']);
|
||||
unset($columns['view_count']);
|
||||
|
||||
$columns['wiaas_country'] = esc_html__( 'Country', 'wiaas' );
|
||||
$columns['wiaas_actions'] = esc_html__( 'Actions', 'wiaas' );
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter delivery process forms list with search query by title and country
|
||||
* @param array $forms
|
||||
* @param string $search_query
|
||||
* @param bool $active
|
||||
* @param string $sort_column
|
||||
* @param string $sort_direction
|
||||
* @param bool $trash
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_gform_form_list_forms($forms, $search_query, $active, $sort_column, $sort_direction, $trash) {
|
||||
|
||||
$forms = GFFormsModel::get_forms( $active, $sort_column, $sort_direction, $trash );
|
||||
|
||||
if ( ! rgblank( $search_query ) ) {
|
||||
|
||||
$filtered_forms = array();
|
||||
$search_query = strtolower($search_query);
|
||||
|
||||
// filter forms
|
||||
foreach ($forms as $form) {
|
||||
|
||||
$form_details = GFAPI::get_form( $form->id );
|
||||
|
||||
$title = strtolower($form_details['title']);
|
||||
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
$country_code = ! empty($delivery_settings) ? $delivery_settings['delivery_country'] : '';
|
||||
$country_name = Wiaas_Countries::get_available_country_name_by_code($country_code);
|
||||
$country_name = strtolower($country_name);
|
||||
|
||||
if (strpos($title, $search_query) !== false || strpos($country_code, $search_query) !== false ||
|
||||
strpos($country_name, $search_query) !== false) {
|
||||
$filtered_forms[] = $form;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered_forms;
|
||||
}
|
||||
|
||||
return $forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove unused actions and add workflow action for delivery forms list
|
||||
*
|
||||
* @param array $actions
|
||||
* @param int $form_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filter_gform_form_actions($actions, $form_id) {
|
||||
unset($actions['entries']);
|
||||
unset($actions['preview']);
|
||||
unset($actions['edit']);
|
||||
|
||||
$actions['wiaas_workflow'] = array(
|
||||
'label' => __( 'Workflow', 'wiaas' ),
|
||||
'short_label' => esc_html__( 'Workflow', 'wiaas' ),
|
||||
'title' => __( 'Edit workflow', 'wiaas' ),
|
||||
'url' => '?page=gf_edit_forms&view=settings&id=' . $form_id . '&subview=gravityflow',
|
||||
'priority' => 1000,
|
||||
);
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render country column for delivery process forms list
|
||||
*
|
||||
* @param mixed $form
|
||||
*/
|
||||
public static function render_gform_form_list_wiaas_country_column($form) {
|
||||
|
||||
$form_details = GFAPI::get_form($form->id);
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
|
||||
$country_code = ! empty($delivery_settings) ? $delivery_settings['delivery_country'] : '';
|
||||
|
||||
$country_name = Wiaas_Countries::get_available_country_name_by_code($country_code);
|
||||
|
||||
echo '<strong>' . esc_html_e($country_name) . '</strong>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render actions column for delivery process forms list
|
||||
* @param mixed $form
|
||||
*/
|
||||
public static function render_gform_form_list_wiaas_actions_column($form) {
|
||||
|
||||
$form_details = GFAPI::get_form($form->id);
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
|
||||
$form_type = ! empty($delivery_settings) ? $delivery_settings['delivery_form_type'] : '';
|
||||
|
||||
?>
|
||||
<a href="<?php echo '?page=gf_edit_forms&view=settings&id=' . $form->id . '&subview=gravityflow' ?>">Workflow</a>
|
||||
<?php
|
||||
|
||||
if ($form_type !== 'action') {
|
||||
|
||||
?>
|
||||
<span style="margin: 0 10px; opacity: 0.3;"> | </span>
|
||||
<a href="<?php echo '?page=gf_edit_forms&view=settings&id=' . $form->id . '&subview=wiaas_delivery_process' ?>">Change Country</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Delivery_Process_List::init();
|
||||
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class Wiaas_Admin_Delivery_Process_Order {
|
||||
|
||||
public static function init() {
|
||||
|
||||
if (isset($_GET['wiaas-procurement-order-id'])) {
|
||||
|
||||
add_action('admin_init', array(__CLASS__, 'download_procurement_order'));
|
||||
}
|
||||
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'add_delivery_process_metabox'), 100 );
|
||||
|
||||
add_action('woocommerce_process_shop_order_meta', array(__CLASS__, 'maybe_assign_delivery_process'), 999);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign delivery process for order
|
||||
*
|
||||
* @param int $order_id
|
||||
*/
|
||||
public static function maybe_assign_delivery_process($order_id) {
|
||||
|
||||
if (! empty($_POST['wiaas_order_delivery_process_id'])) {
|
||||
|
||||
$process_id = absint($_POST['wiaas_order_delivery_process_id']);
|
||||
|
||||
Wiaas_Delivery_Process::create_delivery_process_for_order($order_id, $process_id);
|
||||
}
|
||||
}
|
||||
|
||||
public static function add_delivery_process_metabox() {
|
||||
|
||||
add_meta_box(
|
||||
'order_delivery_process_meta_box',
|
||||
__('Delivery Process', 'cmb'),
|
||||
array(__CLASS__, 'order_delivery_process_meta_box'),
|
||||
'shop_order',
|
||||
'side',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
public static function order_delivery_process_meta_box() {
|
||||
|
||||
global $post;
|
||||
|
||||
$order_id = $post->ID;
|
||||
|
||||
$process_entry = Wiaas_Delivery_Process::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if ( empty($process_entry) ) {
|
||||
|
||||
$country_code = Wiaas_Order::get_order_country_code($order_id);
|
||||
|
||||
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country($country_code);
|
||||
|
||||
?>
|
||||
<div>
|
||||
<select name="wiaas_order_delivery_process_id" style="width: 100%;">
|
||||
<option value="" disabled selected>Assign process to order ... </option>
|
||||
<?php
|
||||
foreach($list_of_delivery_processes as $index => $process){
|
||||
echo '<option value=' . $process['id'] . '>' . $process['title'] . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button type="submit" class="button" style="margin-top: 10px;">Assign</button>
|
||||
</div>
|
||||
<?php
|
||||
} else{
|
||||
|
||||
$entry_url = add_query_arg( array(
|
||||
'page' => 'gravityflow-inbox',
|
||||
'view' => 'entry',
|
||||
'id' => $process_entry['form_id'],
|
||||
'lid' => $process_entry['id']
|
||||
), admin_url() );
|
||||
|
||||
?>
|
||||
<a href="<?php esc_attr_e($entry_url, 'wiaas') ?>"> Delivery Process </a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download procurement order report
|
||||
*
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*
|
||||
*/
|
||||
public static function download_procurement_order() {
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
$order_id = $_GET['wiaas-procurement-order-id'];
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
if (! $order) {
|
||||
wp_die( __( 'Invalid order.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
|
||||
}
|
||||
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
$organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||
$customer_organization_info = wiaas_get_organization_info($organization_id);
|
||||
|
||||
$delivery_address = $order->get_shipping_address_1() . ',' .
|
||||
$order->get_shipping_city() . ',' .
|
||||
$order->get_shipping_country() . ',' .
|
||||
$order->get_shipping_postcode();
|
||||
$billing_address = $order->get_billing_address_1() . ',' .
|
||||
$order->get_billing_city() . ',' .
|
||||
$order->get_billing_country() . ',' .
|
||||
$order->get_billing_postcode();
|
||||
|
||||
$order_procurement_info = wiaas_get_order_procurement_info($order->get_id());
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$spreadsheet->getProperties()->setCreator("RICOH")
|
||||
->setLastModifiedBy("Ricoh Dash")
|
||||
->setTitle("Order Procurement Report")
|
||||
->setSubject("Order Procurement Report")
|
||||
->setDescription("Order Procurement Report")
|
||||
->setKeywords("office 2007 openxml php order procurement")
|
||||
->setCategory("Procurement report file");
|
||||
|
||||
$spreadsheet->setActiveSheetIndex(0);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->setTitle('Order procurement');
|
||||
|
||||
$sheet->setCellValue('A1', 'Customer details');
|
||||
$sheet->setCellValue('A2', 'Name');
|
||||
$sheet->setCellValue('A3', 'Invoice address');
|
||||
$sheet->setCellValue('A4', 'Invoice Full Name');
|
||||
$sheet->setCellValue('A5', 'Invoice Email');
|
||||
$sheet->setCellValue('A6', 'VAT Number');
|
||||
|
||||
$sheet->setCellValue('B2', ! empty($customer_organization_info) ? $customer_organization_info['name'] : '');
|
||||
$sheet->setCellValue('B3', $billing_address);
|
||||
$sheet->setCellValue('B4', $order->get_formatted_billing_full_name());
|
||||
$sheet->setCellValue('B5', $order->get_billing_email());
|
||||
$sheet->setCellValue('B6', ! empty($customer_organization_info) ? $customer_organization_info['vat_code'] : '');
|
||||
|
||||
$sheet->getStyle('A1')->getFont()->setBold(true);
|
||||
|
||||
$sheet->setCellValue('A9', 'OrderDetails');
|
||||
$sheet->setCellValue('A10', 'Order number');
|
||||
$sheet->setCellValue('A11', 'Project number');
|
||||
$sheet->setCellValue('A12', 'Delivery addres');
|
||||
$sheet->setCellValue('A13', 'Delivery Full Name');
|
||||
$sheet->setCellValue('A14', 'Reference');
|
||||
$sheet->setCellValue('B10', $order->get_order_number());
|
||||
$sheet->setCellValue('B11', Wiaas_Order_Project::get_project_name_for_order($order->get_id()) );
|
||||
$sheet->setCellValue('B12', $delivery_address);
|
||||
$sheet->setCellValue('B13', $order->get_formatted_shipping_full_name());
|
||||
$sheet->setCellValue('B14', $order->get_meta('_wiaas_reference'));
|
||||
|
||||
$sheet->getStyle('A9')->getFont()->setBold(true);
|
||||
|
||||
$row = 14;
|
||||
|
||||
foreach ($order_procurement_info as $category => $products) {
|
||||
|
||||
$col = 1; $row += 2;
|
||||
|
||||
$sheet->getColumnDimensionByColumn($col)->setAutoSize(true);
|
||||
$sheet->getStyleByColumnAndRow($col, $row)->getFont()->setBold(true);
|
||||
|
||||
$sheet->setCellValueByColumnAndRow($col, $row, ucfirst(strtolower($category)));
|
||||
|
||||
$row += 2;
|
||||
|
||||
if (! empty($products)) {
|
||||
|
||||
$product_columns = array_keys($products[0]);
|
||||
|
||||
foreach ($product_columns as $product_column_index => $product_column) {
|
||||
|
||||
$sheet->getColumnDimensionByColumn($product_column_index + 1)->setAutoSize(true);
|
||||
$sheet->getStyleByColumnAndRow($product_column_index + 1, $row)->getFont()->setBold(true);
|
||||
$sheet->setCellValueByColumnAndRow($product_column_index + 1, $row, $product_column);
|
||||
}
|
||||
}
|
||||
|
||||
$row += 1;
|
||||
foreach ($products as $product) {
|
||||
|
||||
$product_values = array_values($product);
|
||||
foreach ($product_values as $product_value_index => $product_value) {
|
||||
|
||||
$sheet->setCellValueByColumnAndRow($product_value_index + 1, $row, $product_value);
|
||||
}
|
||||
$row += 1;
|
||||
}
|
||||
}
|
||||
|
||||
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
header('Content-Disposition: attachment;filename="Procurement Report '.$order->get_order_number().'.xlsx"');
|
||||
header('Cache-Control: max-age=0');
|
||||
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$writer->save('php://output');
|
||||
|
||||
exit;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Delivery_Process_Order::init();
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<p class="form-field form-field-wide">
|
||||
<label for="estimated-delivery-date">Estimated delivery date:</label>
|
||||
<input id="estimated-delivery-date" name="estimated-delivery-date"
|
||||
type="date" value="<?php echo $order_estimated_delivery_date ? date("Y-m-d", $order_estimated_delivery_date) : ""; ?>"
|
||||
onChange="onOrderEstimatedDeliveryDateChange(this.value)"/>
|
||||
</p>
|
||||
|
||||
<script type="text/javascript">
|
||||
function onOrderEstimatedDeliveryDateChange(date) {
|
||||
var timestamp = parseInt((new Date(date).getTime() / 1000).toFixed(0));
|
||||
|
||||
if (isNaN(timestamp)){
|
||||
timestamp = '';
|
||||
}
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_save_estimated_date_for_order',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_estimated_date_for_order" ) ?>',
|
||||
order: '<?php echo $order_id ?>',
|
||||
date: timestamp
|
||||
};
|
||||
|
||||
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||
$.post(ajaxurl, data, function(response) {
|
||||
if (response.success){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(response.data[0].message);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div style="margin-top: -20px;">
|
||||
<table class="widefat" disabled="disabled">
|
||||
<tr style="background: #EAF2FA;">
|
||||
<th align="left"><strong>Suppliers</strong></th>
|
||||
<th align="left"><strong>Estimated date</strong></th>
|
||||
<th align="left"><strong>Confirmed date</strong></th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($suppliers as $supplier){
|
||||
echo '<tr style="background: #f5f5f5;"><td><strong>' . $supplier['name'] . '</strong></td>';
|
||||
|
||||
$estimated_date = $supplier['estimated_date'] ? date("Y-m-d", $supplier['estimated_date']) : "";
|
||||
$confirmed_date = $supplier['confirmed_date'] ? date("Y-m-d", $supplier['confirmed_date']) : "";
|
||||
|
||||
?>
|
||||
<td>
|
||||
<input
|
||||
id=<?php echo 'estimate-date-' . $supplier['id'] ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
type="date"
|
||||
onChange="onEstimatedDeliveryDateChange(<?php echo $supplier['id'] ?>, this.value)"
|
||||
value="<?php echo $estimated_date ?>" />
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<input
|
||||
id=<?php echo 'confirmed-date-' . $supplier['id'] ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
type="date" onChange="onConfirmedDeliveryDateChange(<?php echo $supplier['id'] ?>, this.value)"
|
||||
value="<?php echo $confirmed_date ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<span>Tracking:</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
foreach($supplier['tracking_info'] as $index => $tracking_info){
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<input id=<?php echo 'supplier_' . $supplier['id'] . '_tracking_num_' . $index ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
placeholder="Tracking number" value="<?php echo $tracking_info['number'] ?>" />
|
||||
<input id=<?php echo 'supplier_' . $supplier['id'] . '_tracking_url_' . $index ?>
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
placeholder="Tracking URL" value="<?php echo $tracking_info['url'] ?>" />
|
||||
<input
|
||||
type="button"
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
class="button"
|
||||
onClick="saveTrackingInfo(event, <?php echo $supplier['id'] . ',' . $index ?>)"
|
||||
value="SAVE">
|
||||
<input
|
||||
type="button"
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
class="button"
|
||||
onClick="deleteTrackingInfo(event, <?php echo $supplier['id'] . ',' . $index ?>)" value="REMOVE"
|
||||
>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<input
|
||||
type="button"
|
||||
<?php disabled($is_disabled, true, true) ?>
|
||||
class="button"
|
||||
id=<?php echo $supplier['id'] ?> onClick="addAdditionalTrackingInfo(event)"
|
||||
value="Add new tracking info">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td><h4>Final dates : </h4></td>
|
||||
<td><h4><?php echo $final_estimated_date ? date('Y-m-d', $final_estimated_date) : '-' ?></h4></td>
|
||||
<td><h4><?php echo $final_confirmed_date ? date('Y-m-d', $final_confirmed_date) : '-' ?></h4></td>
|
||||
</tr>
|
||||
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td><h4>Earliest installation date : </h4></td>
|
||||
<td colspan="2">
|
||||
<h4><?php echo $earliest_installation_date ? date('Y-m-d', $earliest_installation_date) : '-' ?></h4>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function onEstimatedDeliveryDateChange(supplierID, date) {
|
||||
var timestamp = parseInt((new Date(date).getTime() / 1000).toFixed(0));
|
||||
|
||||
if (isNaN(timestamp)){
|
||||
timestamp = '';
|
||||
}
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_save_estimated_date_for_supplier',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_estimated_date_for_supplier" ) ?>',
|
||||
order: '<?php echo $order_id ?>',
|
||||
supplier: supplierID,
|
||||
date: timestamp
|
||||
|
||||
};
|
||||
|
||||
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||
jQuery.post(ajaxurl, data, function(response) {
|
||||
if (response.success){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(response.data[0].message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onConfirmedDeliveryDateChange(supplierID, date) {
|
||||
var timestamp = parseInt((new Date(date).getTime() / 1000).toFixed(0));
|
||||
|
||||
if (isNaN(timestamp)){
|
||||
timestamp = '';
|
||||
}
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_save_confirmed_date_for_supplier',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_confirmed_date_for_supplier" ) ?>',
|
||||
order: '<?php echo $order_id ?>',
|
||||
supplier: supplierID,
|
||||
date: timestamp
|
||||
};
|
||||
|
||||
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||
jQuery.post(ajaxurl, data, function(response) {
|
||||
if (response.success){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(response.data[0].message);
|
||||
}
|
||||
});
|
||||
}
|
||||
function addAdditionalTrackingInfo(e){
|
||||
e.preventDefault();
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_add_additional_tracking_info_for_supplier_in_order',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_add_additional_tracking_info_for_supplier_in_order" ) ?>',
|
||||
order: '<?php echo $order_id ?>',
|
||||
supplier: e.target.id
|
||||
|
||||
};
|
||||
|
||||
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||
jQuery.post(ajaxurl, data, function(response) {
|
||||
if (response.success){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(response.data[0].message);
|
||||
}
|
||||
});
|
||||
}
|
||||
function saveTrackingInfo(e, supplierID, index){
|
||||
e.preventDefault();
|
||||
|
||||
var tracking_num = document.getElementById('supplier_' + supplierID + '_tracking_num_' + index).value;
|
||||
var tracking_url = document.getElementById('supplier_' + supplierID + '_tracking_url_' + index).value;
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_save_tracking_info',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_save_tracking_info" ) ?>',
|
||||
order: '<?php echo $order_id ?>',
|
||||
supplier: supplierID,
|
||||
index: index,
|
||||
tracking_num: tracking_num,
|
||||
tracking_url: tracking_url
|
||||
};
|
||||
|
||||
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||
jQuery.post(ajaxurl, data, function(response) {
|
||||
if (response.success){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(response.data[0].message);
|
||||
}
|
||||
});
|
||||
}
|
||||
function deleteTrackingInfo(e, supplierID, index){
|
||||
e.preventDefault();
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_delete_tracking_info',
|
||||
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_delete_tracking_info" ) ?>',
|
||||
order: '<?php echo $order_id ?>',
|
||||
supplier: supplierID,
|
||||
index: index
|
||||
};
|
||||
|
||||
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
||||
jQuery.post(ajaxurl, data, function(response) {
|
||||
if (response.success){
|
||||
location.reload();
|
||||
}else{
|
||||
alert(response.data[0].message);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wp_ajax_wiaas_add_additional_tracking_info_for_supplier_in_order', 'wiaas_ajax_add_additional_tracking_info_for_supplier_in_order' );
|
||||
add_action( 'wp_ajax_wiaas_save_tracking_info', 'wiaas_ajax_save_tracking_info');
|
||||
add_action( 'wp_ajax_wiaas_delete_tracking_info', 'wiaas_ajax_delete_tracking_info');
|
||||
add_action( 'wp_ajax_wiaas_save_estimated_date_for_supplier', 'wiaas_ajax_save_estimated_date_for_supplier');
|
||||
add_action( 'wp_ajax_wiaas_save_confirmed_date_for_supplier', 'wiaas_ajax_save_confirmed_date_for_supplier');
|
||||
add_action( 'wp_ajax_wiaas_save_estimated_date_for_order', 'wiaas_ajax_save_estimated_date_for_order');
|
||||
|
||||
/**
|
||||
* Adds additional tracking info for supplier in order
|
||||
*/
|
||||
function wiaas_ajax_add_additional_tracking_info_for_supplier_in_order(){
|
||||
check_ajax_referer('wiaas_add_additional_tracking_info_for_supplier_in_order');
|
||||
$error = new WP_Error('-1', 'Failed to add additional tracking info');
|
||||
|
||||
if (!isset($_POST['order']) || !isset($_POST['supplier'])){
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
$order_id = intval( $_POST['order'] );
|
||||
$supplier_id = intval( $_POST['supplier'] );
|
||||
|
||||
if (Wiaas_Order::add_additional_tracking_info($order_id, $supplier_id)){
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
|
||||
function wiaas_ajax_save_tracking_info(){
|
||||
check_ajax_referer('wiaas_save_tracking_info');
|
||||
$error = new WP_Error('-1', 'Failed to save tracking info');
|
||||
|
||||
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['index'])
|
||||
|| !isset($_POST['tracking_num']) || !isset($_POST['tracking_url'])){
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
$order_id = intval( $_POST['order'] );
|
||||
$supplier_id = intval( $_POST['supplier'] );
|
||||
$index = intval($_POST['index']);
|
||||
$tracking_num = $_POST['tracking_num'];
|
||||
$tracking_url = $_POST['tracking_url'];
|
||||
|
||||
if (Wiaas_Order::save_tracking_info($order_id, $supplier_id, $index, $tracking_num, $tracking_url)){
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
|
||||
function wiaas_ajax_delete_tracking_info(){
|
||||
check_ajax_referer('wiaas_delete_tracking_info');
|
||||
$error = new WP_Error('-1', 'Failed to save tracking info');
|
||||
|
||||
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['index'])){
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
$order_id = intval( $_POST['order'] );
|
||||
$supplier_id = intval( $_POST['supplier'] );
|
||||
$index = intval($_POST['index']);
|
||||
|
||||
if (Wiaas_Order::delete_tracking_info($order_id, $supplier_id, $index)){
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
|
||||
function wiaas_ajax_save_estimated_date_for_supplier(){
|
||||
check_ajax_referer('wiaas_save_estimated_date_for_supplier');
|
||||
$error = new WP_Error('-1', 'Failed to save estimated date');
|
||||
|
||||
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['date'])){
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
$order_id = intval( $_POST['order'] );
|
||||
$supplier_id = intval( $_POST['supplier'] );
|
||||
$date = intval($_POST['date']);
|
||||
|
||||
if (Wiaas_Order::save_estimated_date($order_id, $supplier_id, $date)){
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
|
||||
function wiaas_ajax_save_confirmed_date_for_supplier(){
|
||||
check_ajax_referer('wiaas_save_confirmed_date_for_supplier');
|
||||
$error = new WP_Error('-1', 'Failed to save confirmed date');
|
||||
|
||||
if (!isset($_POST['order']) || !isset($_POST['supplier']) || !isset($_POST['date'])){
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
$order_id = intval( $_POST['order'] );
|
||||
$supplier_id = intval( $_POST['supplier'] );
|
||||
$date = intval($_POST['date']);
|
||||
|
||||
if (Wiaas_Order::save_confirmed_date($order_id, $supplier_id, $date)){
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
|
||||
function wiaas_ajax_save_estimated_date_for_order(){
|
||||
check_ajax_referer('wiaas_save_estimated_date_for_order');
|
||||
$error = new WP_Error('-1', 'Failed to save global estimated date for order');
|
||||
|
||||
if (!isset($_POST['order']) || !isset($_POST['date'])){
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
$order_id = intval( $_POST['order'] );
|
||||
$date = intval($_POST['date']);
|
||||
|
||||
if (Wiaas_Order::save_order_estimated_date($order_id, $date)){
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
wp_send_json_error($error);
|
||||
}
|
||||
@@ -152,18 +152,29 @@ $insert_new_document = $post->post_type !== 'wiaas_doc';
|
||||
|
||||
response = response.response;
|
||||
|
||||
var infoContainer = jQuery('#wiaas_upload_info');
|
||||
|
||||
if (response.substring(0, 6) === 'ERROR:') {
|
||||
jQuery('#wiaas_upload_errors').html('<span class="text-danger">' +
|
||||
'<i class="fa fa-exclamation-triangle"></i>' +
|
||||
infoContainer.html('<span style="color: darkred;">' +
|
||||
'<i class="dashicons dashicons-warning"></i>' +
|
||||
' ' + response.substring(6, response.length) +
|
||||
'</span>');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
infoContainer.html('<span style="color: darkgreen;">' +
|
||||
'<i class="dashicons dashicons-yes"></i>' +
|
||||
' ' + 'Document uploaded and linked' +
|
||||
'</span>');
|
||||
|
||||
<?php
|
||||
if ($insert_new_document) {
|
||||
?>
|
||||
$('#wiaas_attached_documents').find('tbody').append(response);
|
||||
|
||||
$('.wiaas_documents_tab a').click();
|
||||
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
@@ -252,7 +263,8 @@ $insert_new_document = $post->post_type !== 'wiaas_doc';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_upload_errors" style="color: darkred;">
|
||||
<div id="wiaas_upload_info">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -8,62 +8,17 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
?>
|
||||
|
||||
<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"/>
|
||||
<input
|
||||
type="text"
|
||||
data-target="wiaas_attached_documents"
|
||||
data-search-nonce="<?php echo wp_create_nonce('wiaas_json_search_documents') ?>"
|
||||
data-link-nonce="<?php echo wp_create_nonce('wiaas_link_document') ?>"
|
||||
class="wiaas-search-documents"
|
||||
/>
|
||||
</p>
|
||||
</div>
|
||||
<div class="options_group">
|
||||
|
||||
@@ -11,12 +11,49 @@ class Wiaas_Admin_Package_Pricing {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
|
||||
add_action( 'admin_menu', array(__CLASS__, 'add_package_pricing_editor_page') );
|
||||
|
||||
add_action( 'wp_ajax_create_empty_pricing_rule', array(__CLASS__, 'create_empty_pricing_rule') );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
|
||||
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) {
|
||||
|
||||
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-package_price_editor&id=' . absint( $package->get_id() ) );
|
||||
|
||||
return '<a class="button button-link" href="' . esc_url($edit_link) .'" target="_blank">Edit price<a>';
|
||||
}
|
||||
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,48 +69,87 @@ class Wiaas_Admin_Package_Pricing {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers wiaas pricing tab for package data
|
||||
* @param $tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
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
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderes wiaas pricing tab content for package
|
||||
*/
|
||||
public static function package_data_panel() {
|
||||
public static function package_pricing_editor() {
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
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);
|
||||
$max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
|
||||
|
||||
include 'views/html-package-pricing.php';
|
||||
// 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';
|
||||
}
|
||||
|
||||
|
||||
// PRIVATE HELPERS
|
||||
|
||||
/**
|
||||
* Saves posted package pricing rules
|
||||
* @param $post_id
|
||||
* @param $post
|
||||
* Save posted package pricing information
|
||||
*
|
||||
* @param int $package_id
|
||||
*/
|
||||
public function process_meta_box( $post_id, $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;
|
||||
}
|
||||
|
||||
Wiaas_Package_Pricing::set_package_prices(
|
||||
wc_get_product( $post_id ),
|
||||
$_POST['wiaas_pricing_rules'],
|
||||
$_POST['wiaas_pricing_rules_commision'],
|
||||
$_POST['wiaas_max_cost_margin']);
|
||||
wc_get_product( $package_id ),
|
||||
$pricing_rules,
|
||||
$commission,
|
||||
$max_cost_margin);
|
||||
|
||||
Wiaas_Access_Management::maybe_handle_product_access($package_id, get_post($package_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
<?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_product_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>
|
||||
@@ -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">
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule form-field">
|
||||
<div class="section">
|
||||
<h4 class="first"><?php echo $pay_type['title']; ?>
|
||||
<a href="#" data-name="<?php echo $name; ?>"
|
||||
|
||||
@@ -1,223 +0,0 @@
|
||||
<?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_max_cost_margin',
|
||||
'name' => 'wiaas_max_cost_margin',
|
||||
'value' => $max_cost_margin,
|
||||
'label' => __( 'Max cost margin:', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
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,29 +4,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
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').attr('class','wiaas_show_if_simple');
|
||||
|
||||
$('body').on('woocommerce-product-type-change', function (event, select_val) {
|
||||
|
||||
if ('simple' === select_val) {
|
||||
$('.wiaas_show_if_simple').show();
|
||||
} else {
|
||||
$('.wiaas_show_if_simple').hide();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_checkbox(
|
||||
array(
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<?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>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method filters search results by template country
|
||||
* In addition it adds template category to label of every product
|
||||
*
|
||||
* @param $search_results array provided by filter
|
||||
* @return mixed array of filtered search results
|
||||
*/
|
||||
|
||||
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 => $product_form_search) {
|
||||
if (Wiaas_Countries::get_product_country_term_id($product_form_search) !== $country_id) {
|
||||
unset($search_results[$product_form_search->get_id()]);
|
||||
} else {
|
||||
$template_category = wp_get_object_terms($product_form_search->get_id(), 'template_category', array('fields' => 'names'));
|
||||
if(!empty($template_category)){
|
||||
$search_results[$product_form_search->get_id()] = $search_results[$product_form_search->get_id()].' ['.$template_category[0].']';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -56,10 +56,16 @@ class Wiaas_Admin_Template_Selection {
|
||||
<div id="wiaas_selected_template_items_container"><?php
|
||||
$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['installation']);
|
||||
self::render_template_products($template_products_data['software']);
|
||||
$product = wc_get_product( $post->ID );
|
||||
if ($product->get_type() == 'bundle') {
|
||||
$bundled_items = $product->get_bundled_items('view');
|
||||
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
|
||||
|
||||
self::render_template_products($template_products_data['hardware'], $categories_form_bundle);
|
||||
self::render_template_products($template_products_data['services'], $categories_form_bundle);
|
||||
self::render_template_products($template_products_data['installation'], $categories_form_bundle);
|
||||
self::render_template_products($template_products_data['software'], $categories_form_bundle);
|
||||
}
|
||||
?></div><?php
|
||||
|
||||
}
|
||||
@@ -132,17 +138,22 @@ class Wiaas_Admin_Template_Selection {
|
||||
* Render html of template categories
|
||||
*
|
||||
* @param $template_products array containing template category information
|
||||
* @param $categories_form_bundle
|
||||
*/
|
||||
public static function render_template_products($template_products) {
|
||||
public static function render_template_products($template_products, $categories_form_bundle = array()) {
|
||||
|
||||
if (!empty($template_products)) {
|
||||
|
||||
|
||||
foreach ($template_products as $item) {
|
||||
|
||||
$connected_product = $categories_form_bundle[$item['template_category_id']] ?
|
||||
$categories_form_bundle[$item['template_category_id']]->product_name : '';
|
||||
|
||||
$product_id = $item['template_category_id'];
|
||||
$title = $item['template_category_title'];
|
||||
$quantity = $item['quantity'];
|
||||
|
||||
$connected_product_name = $connected_product;
|
||||
include('views/html-wiaas-template-selection.php');
|
||||
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ class Wiaas_Template_Admin_Ajax {
|
||||
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => 'template_category',
|
||||
'name__like' => $term
|
||||
'name__like' => $term,
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
foreach ($terms as $t) {
|
||||
|
||||
@@ -10,7 +10,6 @@ class Wiaas_template {
|
||||
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.
|
||||
@@ -198,21 +197,6 @@ class Wiaas_template {
|
||||
return isset($a['menu_order']) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hide default WC_Product data panels.
|
||||
*/
|
||||
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();
|
||||
|
||||
@@ -9,5 +9,6 @@ if (!defined('ABSPATH')) {
|
||||
<h3>
|
||||
<strong class="item-title"><?php echo $title; ?></strong>
|
||||
<strong class="item-title">[<?php echo $quantity; ?>]</strong>
|
||||
<strong class="item-title">[<?php echo $connected_product_name; ?>]</strong>
|
||||
</h3>
|
||||
</div><?php
|
||||
|
||||
@@ -31,12 +31,20 @@ 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',
|
||||
),
|
||||
'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',
|
||||
),
|
||||
'options_ids' => array(
|
||||
@@ -210,7 +218,6 @@ class Wiaas_Cart_API {
|
||||
public static function get_cart_items() {
|
||||
return rest_ensure_response(array(
|
||||
'items' => Wiaas_Cart::get_cart_packages(),
|
||||
'raw' => WC()->cart->get_cart_contents(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -225,6 +232,7 @@ 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']
|
||||
);
|
||||
|
||||
@@ -5,7 +5,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This is temporary implemetation and will probably be changed during work on pending wiaas cart task
|
||||
* Class Wiaas_Document_API
|
||||
*/
|
||||
class Wiaas_Document_API {
|
||||
@@ -30,30 +29,26 @@ class Wiaas_Document_API {
|
||||
)
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'documents/order/(?P<id>\d+)/(?P<type>[\w-]+)', array(
|
||||
register_rest_route( self::$namespace, 'order/(?P<id>\d+)/item/(?P<item_id>\d+)/document/(?P<key>[\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'),
|
||||
'callback' => array(__CLASS__, 'download_order_item_document'),
|
||||
'args' => array(
|
||||
'item_id' => array(
|
||||
'description' => __( 'Package Order Item ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
'required' => true
|
||||
),
|
||||
'document_key' => array(
|
||||
'key' => array(
|
||||
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
@@ -62,6 +57,29 @@ class Wiaas_Document_API {
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
register_rest_route(self::$namespace, 'order/(?P<id>\d+)/document/(?P<key>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Order ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'callback' => array(__CLASS__, 'download_order_other_document'),
|
||||
'args' => array(
|
||||
'key' => array(
|
||||
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'required' => true
|
||||
),
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,14 +94,23 @@ class Wiaas_Document_API {
|
||||
}
|
||||
|
||||
/**
|
||||
* Download order document
|
||||
* Download order item document
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_order_document($request) {
|
||||
public static function download_order_item_document($request) {
|
||||
Wiaas_Document_Download::download_order_item_document(
|
||||
$request['id'],
|
||||
$request['item_id'],
|
||||
$request['type'],
|
||||
$request['document_key']);
|
||||
$request['key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download order document
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_order_other_document($request) {
|
||||
Wiaas_Document_Download::download_order_other_document($request['id'], $request['key']);
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Package_API {
|
||||
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
|
||||
}
|
||||
|
||||
public static function register_routes() {
|
||||
// TODO: Handle this when assigment of customer to commercial lead is done
|
||||
register_rest_route( self::$namespace, '/commercial-leads', array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array(__CLASS__, 'get_customer_commercial_leads'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
}
|
||||
|
||||
// TODO: Handle this when assigment of customer to commercial lead is done
|
||||
public static function get_customer_commercial_leads() {
|
||||
$commercial_leads = array();
|
||||
|
||||
foreach (wiaas_get_commercial_leads() as $id => $name) {
|
||||
$commercial_leads[] = array(
|
||||
'id' => $id,
|
||||
'name' => $name
|
||||
);
|
||||
}
|
||||
|
||||
return rest_ensure_response($commercial_leads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter woocommerce REST API query so only valid wiaas packages are returned to the customer
|
||||
*
|
||||
* @param $args
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filter_packages($args, $request) {
|
||||
|
||||
if ( empty($query['tax_query']) ){
|
||||
$query['tax_query'] = array();
|
||||
}
|
||||
|
||||
// Retrieve only packages with available package status
|
||||
$query['tax_query'][] = array(
|
||||
'taxonomy' => 'package_status',
|
||||
'field' => 'name',
|
||||
'terms' => Wiaas_Package_Status::AVAILABLE
|
||||
);
|
||||
|
||||
|
||||
$commercial_lead_id = absint($request['cl_id']);
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
$price_search_terms = array();
|
||||
foreach ($pay_types as $pay_type) {
|
||||
$price_search_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_default';
|
||||
$price_search_terms[] = '_' . $commercial_lead_id . '_' . $pay_type . '_customer_' . $customer_id;
|
||||
}
|
||||
|
||||
$args['tax_query'][] = array(
|
||||
'taxonomy' => '_wiaas_shop_prices',
|
||||
'terms' => $price_search_terms,
|
||||
'field' => 'slug'
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_API::init();
|
||||
@@ -1,5 +1,12 @@
|
||||
<?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.
|
||||
@@ -9,13 +16,19 @@ 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'),
|
||||
@@ -54,6 +67,21 @@ 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' => $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){
|
||||
@@ -120,6 +148,10 @@ class Wiaas_REST_Customer_API {
|
||||
return wiaas_api_notice('ADD_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
if (!Wiaas_Validation::is_phone($phone)){
|
||||
return wiaas_api_notice('INVALID_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
};
|
||||
|
||||
if (!Wiaas_Customer::update_customer_profile_info($customer_id, $first_name, $last_name, $phone)){
|
||||
return wiaas_api_notice('PROFILE_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
@@ -26,28 +26,44 @@ class Wiass_REST_Delivery_Process_API {
|
||||
*/
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
private static $rest_base = 'delivery';
|
||||
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'next-delivery-steps', array(
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/next-actions', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_next_actions_for_user'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer-acceptance/(?P<entry_id>\d+)', array(
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-acceptance', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_customer_acceptance'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer-acceptance/(?P<entry_id>\d+)', array(
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-acceptance', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(__CLASS__, 'submit_customer_acceptance'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer-acceptance/(?P<entry_id>\d+)/upload-file' , array(
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-acceptance/upload' , array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(__CLASS__, 'upload_file'),
|
||||
'callback' => array(__CLASS__, 'upload_customer_acceptance'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-questionnaires', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_customer_questionnaires'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-questionnaires/upload/(?P<action_entry_id>\d+)', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(__CLASS__, 'upload_customer_questionnaire'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
}
|
||||
@@ -61,14 +77,6 @@ class Wiass_REST_Delivery_Process_API {
|
||||
'value' => 'pending',
|
||||
);
|
||||
|
||||
$user_roles = gravity_flow()->get_user_roles();
|
||||
foreach ( $user_roles as $user_role ) {
|
||||
$field_filters[] = array(
|
||||
'key' => 'workflow_role_' . $user_role,
|
||||
'value' => 'pending',
|
||||
);
|
||||
}
|
||||
|
||||
$field_filters['mode'] = 'any';
|
||||
|
||||
$search_criteria = array();
|
||||
@@ -77,10 +85,11 @@ class Wiass_REST_Delivery_Process_API {
|
||||
|
||||
$form_ids = gravity_flow()->get_workflow_form_ids();
|
||||
|
||||
$total_count = 7;
|
||||
|
||||
|
||||
$entries = GFAPI::get_entries( $form_ids, $search_criteria, null, null, $total_count );
|
||||
$entries = GFAPI::get_entries(
|
||||
$form_ids,
|
||||
$search_criteria,
|
||||
null,
|
||||
null);
|
||||
|
||||
$data = array();
|
||||
foreach ($entries as $entry) {
|
||||
@@ -96,175 +105,73 @@ class Wiass_REST_Delivery_Process_API {
|
||||
return rest_ensure_response($data);
|
||||
}
|
||||
|
||||
public static function get_customer_acceptance(WP_REST_Request $request){
|
||||
$entry = GFAPI::get_entry($request['entry_id']);
|
||||
if (is_wp_error($entry)){
|
||||
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
|
||||
}
|
||||
public function get_customer_questionnaires(WP_REST_Request $request) {
|
||||
|
||||
$acceptance_documents = array();
|
||||
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
|
||||
$order_id = absint($request['order_id']);
|
||||
|
||||
foreach($uploaded_files as $file_url){
|
||||
//example of decoded url :
|
||||
//http://localhost/wp/index.php?gf-download=2018/08/rokovi-1535378841.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534
|
||||
|
||||
$decoded_url = urldecode($file_url);
|
||||
$url_parts = explode('?', $decoded_url);
|
||||
$file_name_base_parts = explode('&', $url_parts[1]);
|
||||
$file_name_parts = explode('/', $file_name_base_parts[0]);
|
||||
$file_name_with_extension_parts = explode('.', $file_name_parts[2]);
|
||||
$data = Wiaas_Delivery_Process::get_customer_questionnaires_data($order_id);
|
||||
|
||||
$acceptance_documents_entry = array(
|
||||
'name' => $file_name_with_extension_parts[0],
|
||||
'extension' => $file_name_with_extension_parts[1],
|
||||
'url' => $file_url
|
||||
);
|
||||
array_push($acceptance_documents, $acceptance_documents_entry);
|
||||
}
|
||||
|
||||
$acceptance_status = 0;
|
||||
if ($entry[self::ACCEPTANCE_STATUS_FIELD_ID]){
|
||||
$acceptance_status = ($entry[self::ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1;
|
||||
}
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'documents' => $acceptance_documents,
|
||||
'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
|
||||
'status' => $acceptance_status,
|
||||
'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
|
||||
));
|
||||
return rest_ensure_response($data);
|
||||
}
|
||||
|
||||
public static function submit_customer_acceptance(WP_REST_Request $request){
|
||||
$entry = GFAPI::get_entry($request['entry_id']);
|
||||
if (is_wp_error($entry)){
|
||||
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
|
||||
}
|
||||
public function upload_customer_questionnaire(WP_REST_Request $request) {
|
||||
|
||||
$status = $request['actionType'];
|
||||
$reason = $request['declineReason'];
|
||||
$order_id = absint($request['order_id']);
|
||||
|
||||
$action_entry_id = absint($request['action_entry_id']);
|
||||
|
||||
Wiaas_Delivery_Process::upload_customer_questionnaire($order_id, $action_entry_id);
|
||||
|
||||
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
|
||||
}
|
||||
|
||||
public static function get_customer_acceptance(WP_REST_Request $request){
|
||||
|
||||
$order_id = absint($request['order_id']);
|
||||
|
||||
$data = Wiaas_Delivery_Process::get_customer_acceptance_data($order_id);
|
||||
|
||||
return rest_ensure_response($data);
|
||||
}
|
||||
|
||||
public static function submit_customer_acceptance(WP_REST_Request $request) {
|
||||
|
||||
$status = $request['action_type'];
|
||||
$reason = $request['decline_reason'];
|
||||
|
||||
if (!in_array($status, self::ACCEPTABLE_STATUS)){
|
||||
return wiaas_api_notice('ACCEPTANCE_STATUS_MISSING', 'error');
|
||||
}
|
||||
|
||||
$installation_declined = ($status === self::DECLINE_STATUS_LABEL);
|
||||
|
||||
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
|
||||
|
||||
if ($installation_declined && $reason === ''){
|
||||
return wiaas_api_notice('DECLINE_REASON_EMPTY', 'error');
|
||||
}
|
||||
|
||||
if (!$installation_declined && (count($uploaded_files)===0)){
|
||||
|
||||
$order_id = $request['order_id'];
|
||||
|
||||
if (! $installation_declined && ! Wiaas_Delivery_Process::is_customer_acceptance_uploaded($order_id)) {
|
||||
return wiaas_api_notice('ACCEPTANCE_NOT_UPLOADED', 'error');
|
||||
}
|
||||
|
||||
$entry[self::DECLINE_REASON_FIELD_ID] = $reason;
|
||||
$entry[self::ACCEPTANCE_STATUS_FIELD_ID] = $status;
|
||||
|
||||
if (!GFAPI::update_entry( $entry )){
|
||||
return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
|
||||
}
|
||||
|
||||
//Check if step is already completed, to not submit again
|
||||
$gf_api = new Gravity_Flow_API($entry['form_id']);
|
||||
$current_step = $gf_api->get_current_step($entry);
|
||||
if ($current_step->get_name() !== self::USER_INPUT_STEP_NAME){
|
||||
return wiaas_api_notice('ACCEPTANCE_STATUS_UPDATED', 'success');
|
||||
}
|
||||
|
||||
if ( $current_step ) {
|
||||
$current_step->purge_assignees();
|
||||
$current_step->update_step_status( 'complete' );
|
||||
}
|
||||
$entry_id = $entry['id'];
|
||||
$new_step_id = $current_step->get_id() + 1;
|
||||
$new_step = $gf_api->get_step( $new_step_id, $entry );
|
||||
$feedback = sprintf( esc_html__( 'Sent to step: %s', 'gravityflow' ), $new_step->get_name() );
|
||||
$gf_api->add_timeline_note( $entry_id, $feedback );
|
||||
$gf_api->log_activity( 'workflow', 'sent_to_step', $gf_api->form_id, $entry_id, $step_id );
|
||||
gform_update_meta( $entry_id, 'workflow_final_status', 'pending' );
|
||||
$new_step->start();
|
||||
$gf_api->process_workflow( $entry_id );
|
||||
|
||||
Wiaas_Delivery_Process::update_customer_acceptance_status($order_id, $status, $reason);
|
||||
|
||||
if ($installation_declined){
|
||||
return wiaas_api_notice('INSTALLATION_DECLINED', 'success');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
|
||||
}
|
||||
|
||||
public static function upload_file(WP_REST_Request $request){
|
||||
$files = $request->get_file_params();
|
||||
if (!$files[self::FILE_KEY_NAME]){
|
||||
return wiaas_api_notice('NO_FILES_UPLOADED', 'error');
|
||||
}
|
||||
public static function upload_customer_acceptance(WP_REST_Request $request){
|
||||
|
||||
$entry = GFAPI::get_entry($request['entry_id']);
|
||||
if (is_wp_error($entry)){
|
||||
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
|
||||
}
|
||||
$order_id = $request['order_id'];
|
||||
|
||||
$form = GFAPI::get_form($entry['form_id']);
|
||||
$form_upload_path = GFFormsModel::get_upload_path( $form['id'] );
|
||||
$success = Wiaas_Delivery_Process::upload_customer_acceptance_document($order_id);
|
||||
|
||||
$target_path = $form_upload_path . '/' . date('Y') . '/' . date('m') . '/';
|
||||
wp_mkdir_p( $target_path );
|
||||
GFCommon::recursive_add_index_file( $target_path );
|
||||
|
||||
$upload_file_field = GFAPI::get_field($form['id'], self::UPLOADED_FILES_FIELD_ID);
|
||||
$file_name = sanitize_file_name($files[self::FILE_KEY_NAME]['name']);
|
||||
$file_path_details = pathinfo($file_name);
|
||||
|
||||
if ( GFCommon::file_name_has_disallowed_extension( $file_name ) ) {
|
||||
return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
|
||||
}
|
||||
$allowed_extensions = ! empty( $upload_file_field->allowedExtensions ) ? GFCommon::clean_extensions( explode( ',', strtolower( $upload_file_field->allowedExtensions ) ) ) : array();
|
||||
if ( ! empty( $allowed_extensions ) ) {
|
||||
if ( ! GFCommon::match_file_extension( $file_name, $allowed_extensions ) ) {
|
||||
return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
$new_file_name = $file_path_details['filename'] . '-' . time() . '.' . $file_path_details['extension'];
|
||||
|
||||
// Bypasses security checks when running unit tests.
|
||||
if ( defined( 'WP_TEST_IN_PROGRESS' ) && WP_TEST_IN_PROGRESS ) {
|
||||
return wiaas_api_notice('FILE_UPLOADED', 'success');
|
||||
}
|
||||
|
||||
if ( move_uploaded_file($files[self::FILE_KEY_NAME]['tmp_name'], $target_path . $new_file_name ) ) {
|
||||
GFFormsModel::set_permissions( $target_path . $new_file_name );
|
||||
} else {
|
||||
return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
|
||||
}
|
||||
|
||||
//Extract path relative to the root
|
||||
//Last 6 strings (excluding last empty) are path relative to the root
|
||||
$path_parts = explode('/', $target_path);
|
||||
|
||||
$relative_path = '';
|
||||
$i = count($path_parts) - self::PATH_PARTS_TO_EXTRACT;
|
||||
while($i < count($path_parts)-1){
|
||||
$relative_path = $relative_path . $path_parts[$i] . '/';
|
||||
$i++;
|
||||
}
|
||||
|
||||
$file_url = self::BASE_NAME . $relative_path . $new_file_name;
|
||||
$url_for_download = $upload_file_field->get_download_url($file_url);
|
||||
|
||||
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
|
||||
|
||||
if ($uploaded_files === NULL){
|
||||
$uploaded_files = [];
|
||||
}
|
||||
array_push($uploaded_files, $url_for_download);
|
||||
|
||||
$entry[self::UPLOADED_FILES_FIELD_ID] = json_encode($uploaded_files);
|
||||
|
||||
if (GFAPI::update_entry( $entry )) {
|
||||
if ($success) {
|
||||
return wiaas_api_notice('FILE_UPLOADED','success');
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class Wiass_REST_User_API {
|
||||
}
|
||||
|
||||
public static function get_countries(){
|
||||
$countries = Wiaas_Countries::get_list_of_countries();
|
||||
$countries = Wiaas_Countries::get_available_countries();
|
||||
|
||||
return rest_ensure_response($countries);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Support_Api {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
private static $rest_base = 'support';
|
||||
|
||||
|
||||
public static function register_routes() {
|
||||
|
||||
register_rest_route(self::$namespace, self::$rest_base . '/send-support-email', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(__CLASS__, 'send_support_email'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __('Order ID.', 'wiaas'),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'support_text' => array(
|
||||
'description' => __('Email text.', 'wiaas'),
|
||||
'type' => 'string',
|
||||
'required' => true
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send support email and save massage to order notes
|
||||
*
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function send_support_email($request) {
|
||||
|
||||
$order_id = $request['id'];
|
||||
$message = $request['support_text'];
|
||||
$order = wc_get_order($order_id);
|
||||
$customer_id = $order->get_customer_id();
|
||||
$customer = get_user_by('id', $customer_id);
|
||||
|
||||
|
||||
$mailer = WC()->mailer();
|
||||
|
||||
$recipient = WIAAS_SUPPORT_EMAIL;
|
||||
$subject = __('Customer: '.$customer->get('first_name').', '.''.$customer->get('last_name').' needs support for order number: ' .$order->get_order_number());
|
||||
|
||||
$headers = array();
|
||||
$success = $mailer->send( $recipient, $subject, $message, $headers );
|
||||
|
||||
if ($success) {
|
||||
wc_create_order_note($order_id , $message, true );
|
||||
return wiaas_api_notice('EMAIL_SENT', 'success');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('EMAIL_NOT_SENT', 'failed');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?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();
|
||||
@@ -1,10 +1,23 @@
|
||||
<?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' ));
|
||||
add_action('woocommerce_payment_complete', array( __CLASS__, 'assign_order_to_suppliers'),20,1 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -22,30 +35,68 @@ class Wiaas_Access_Management {
|
||||
|
||||
$product = wc_get_product($post_id);
|
||||
|
||||
$admin_access_group = Groups_Group::read_by_name('admin');
|
||||
$access_group = null;
|
||||
|
||||
$access_group_ids = array();
|
||||
// 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))) {
|
||||
|
||||
if ($admin_access_group) {
|
||||
$access_group_ids[] = $admin_access_group->group_id;
|
||||
$access_group = Groups_Group::read_by_name('admin');
|
||||
} else {
|
||||
|
||||
$access_group = Groups_Group::read_by_name('Registered');
|
||||
}
|
||||
|
||||
// allow commercial lead to see published bundle products
|
||||
$cl_access_group = Groups_Group::read_by_name('commercial_lead');
|
||||
|
||||
if ($product->get_type() === 'bundle' &&
|
||||
$product->get_status() === 'publish' &&
|
||||
$cl_access_group) {
|
||||
$access_group_ids[] = $cl_access_group->group_id;
|
||||
if ($access_group) {
|
||||
Groups_Post_Access::update(
|
||||
array(
|
||||
'post_id' => $product->get_id(),
|
||||
'groups_read' => $access_group->group_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Groups_Post_Access::update(
|
||||
array(
|
||||
'post_id' => $product->get_id(),
|
||||
'groups_read' => $access_group_ids
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignees order to supplier organizations extracted from ordered items when order payment is complete.
|
||||
*
|
||||
* @param int $order_id
|
||||
*/
|
||||
public static function assign_order_to_suppliers($order_id){
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$product_from_order = $order->get_items('line_item');
|
||||
|
||||
foreach ($product_from_order as $product_item) {
|
||||
|
||||
$supplier_organisation_id = Wiaas_Product_Supplier
|
||||
::get_supplier_organisation_id_from_product($product_item->get_product_id());
|
||||
|
||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $supplier_organisation_id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Access_Management::init();
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Wiaas_Admin {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin/class-wiaas-admin-package.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/class-wiaas-admin-pricing.php';
|
||||
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';
|
||||
@@ -19,9 +17,21 @@ class Wiaas_Admin {
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
|
||||
// Admin organization interface
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
|
||||
// Admin order delivery process
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-product.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-supplier.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-user-profile.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-countries.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
}
|
||||
|
||||
@@ -30,7 +40,10 @@ class Wiaas_Admin {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
|
||||
wp_enqueue_style( 'wiaas_admin_packages', $plugin_url . '/assets/css/package.css' );
|
||||
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ class Wiaas_API {
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-package-api.php';
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc-package-api-integration.php';
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-support-api.php';
|
||||
|
||||
// API functions
|
||||
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
||||
@@ -58,7 +59,7 @@ class Wiaas_API {
|
||||
'Wiass_REST_User_API',
|
||||
'Wiaas_REST_Customer_API',
|
||||
'Wiaas_Order_Projects_API',
|
||||
'Wiaas_Package_API'
|
||||
'Wiaas_Support_Api',
|
||||
);
|
||||
|
||||
foreach ( $controllers as $controller ) {
|
||||
|
||||
@@ -9,192 +9,177 @@
|
||||
*/
|
||||
class Wiaas_Authentication {
|
||||
|
||||
const SUPER_ADMIN_USER_ID = 1;
|
||||
const SUPER_ADMIN_USER_ID = 1;
|
||||
|
||||
public static function init() {
|
||||
// authenticate current user
|
||||
add_action('determine_current_user', array(__CLASS__, 'authenticate_current_user'), 999);
|
||||
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);
|
||||
// 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);
|
||||
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'authenticate_rest_user_on_login'), 999, 2);
|
||||
|
||||
// redirect to dashboard after login
|
||||
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ) );
|
||||
// redirect to dashboard after login
|
||||
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ) );
|
||||
}
|
||||
|
||||
// add role selector to login form
|
||||
add_action('login_form', array(__CLASS__, 'pick_role_on_login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect admin user to dashboard
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function login_redirect() {
|
||||
return admin_url('index.php') ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add role selector to login form
|
||||
*/
|
||||
public static function pick_role_on_login() {
|
||||
?>
|
||||
<p>
|
||||
<label for="user_role"><?php esc_html_e( 'Role' , 'wiaas'); ?><br />
|
||||
<select id="user_role" class="input" name="role">
|
||||
<option value="administrator"><?php esc_html_e('Administrator', 'wiaas') ?></option>
|
||||
<option value="supplier"><?php esc_html_e('Supplier', 'wiaas') ?></option>
|
||||
<option value="commercial_lead"><?php esc_html_e('Commercial Lead', 'wiaas') ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
/**
|
||||
* Authenticate current user based on roles assigned to organization
|
||||
*
|
||||
* If this is non admin request successfully validate user if he can have customer role.
|
||||
*
|
||||
* If this is admin panel request successfully validate user if has admin panel role selected
|
||||
* and also he still can have that role (role was not removed from his customer organization)
|
||||
*
|
||||
* @param int|false $user_id
|
||||
* @return int|false|WP_Error
|
||||
*/
|
||||
public static function authenticate_current_user($user_id) {
|
||||
// do nothing if user not authenticated, user is super admin or this is REST API request
|
||||
if (! $user_id || (int) $user_id === self::SUPER_ADMIN_USER_ID) {
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
|
||||
global $current_user;
|
||||
|
||||
$role = $is_rest_api ?
|
||||
'customer' :
|
||||
get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
|
||||
if (empty($current_user)) {
|
||||
|
||||
$result = self::_can_user_have_role($user_id, $role, $is_rest_api);
|
||||
$current_user = new WP_User($user_id);
|
||||
}
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
return false;
|
||||
}
|
||||
$rest_api_slug = rest_get_url_prefix();
|
||||
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
if ($valid_api_uri) {
|
||||
//for non admin request check if user has customer role
|
||||
$role = 'customer';
|
||||
} else {
|
||||
// for admin panel request check if user has selected role
|
||||
$role = get_user_meta($user_id, '_wiaas_admin_role', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate wiaas user on login based on roles assigned to organization
|
||||
*
|
||||
* @param WP_User $user
|
||||
* @return WP_User|WP_Error
|
||||
*/
|
||||
public static function authenticate_user_on_login($user) {
|
||||
// check if rest request
|
||||
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
|
||||
// do nothing if there is an error already,
|
||||
// user is super admin or
|
||||
// this is rest request
|
||||
if (is_wp_error($user) || $user->ID === 1 || $is_rest_api) {
|
||||
return $user;
|
||||
}
|
||||
if ( empty($role) || ! user_can($user_id, 'wiaas_' . $role)) {
|
||||
// not available roles for user
|
||||
$current_user->set_role('');
|
||||
|
||||
if (empty($_POST['role'])) {
|
||||
return new WP_Error('error', 'You must selected role to login!');
|
||||
}
|
||||
return new WP_Error('wiaas_authentication_error', 'No set permissions!', array(
|
||||
'status' => 403,
|
||||
));
|
||||
}
|
||||
|
||||
// get selected role
|
||||
$requested_role = sanitize_key($_POST['role']);
|
||||
// authenticate valid admin panel user
|
||||
$current_user->set_role($role);
|
||||
|
||||
// validate can user have requested role
|
||||
$result = self::_can_user_have_role($user->ID, $requested_role, false);
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
// if user organization has no requested role prevent access
|
||||
if (is_wp_error($result)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// remember role for user and continue
|
||||
update_user_meta($user->ID, '_wiaas_current_user_admin_role', $requested_role);
|
||||
|
||||
return $user;
|
||||
}
|
||||
/**
|
||||
* Authenticate wiaas user on login based on roles assigned to organization
|
||||
*
|
||||
* If this is non admin panel request authenticate user if he can be customer.
|
||||
*
|
||||
* If this is admin panel 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Filters user roles retrieval so that selected user role is retrieved for admin panel
|
||||
* and customer role is retrieved for JSON API request
|
||||
*
|
||||
* @param $null
|
||||
* @param int $user_id
|
||||
* @param string $meta_key
|
||||
* @return array|null
|
||||
*/
|
||||
public static function maybe_filter_user_roles($null, $user_id, $meta_key) {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
if ($user_id !== 0 && $user_id !== self::SUPER_ADMIN_USER_ID && $meta_key === $wpdb->get_blog_prefix() . 'capabilities') {
|
||||
|
||||
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
|
||||
|
||||
$role = $is_rest_api ?
|
||||
'customer' :
|
||||
get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
|
||||
|
||||
return array( array ( "$role" => true ));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
$rest_api_slug = rest_get_url_prefix();
|
||||
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
|
||||
|
||||
|
||||
/**
|
||||
* CUSTOMER API AUTHENTICATION
|
||||
*/
|
||||
// validate customer user login
|
||||
if ($valid_api_uri) {
|
||||
|
||||
// PRIVATE
|
||||
$role = user_can($user->ID, 'wiaas_customer') ? 'customer' : '';
|
||||
$user->set_role($role);
|
||||
|
||||
/**
|
||||
* Determines if user can have requested role based on his organization roles
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string $user_role
|
||||
* @param bool $is_rest_api
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
private static function _can_user_have_role($user_id, $user_role, $is_rest_api) {
|
||||
// check if role valid for access
|
||||
if (! wp_roles()->is_role($user_role)) {
|
||||
return new WP_Error('error', 'Role is not valid!');
|
||||
}
|
||||
return empty($role) ?
|
||||
new WP_Error('wiaas_authentication_error', 'No Customer permissions!', array(
|
||||
'status' => 403,
|
||||
)) :
|
||||
$user;
|
||||
}
|
||||
|
||||
// only customer role can access API
|
||||
if ($is_rest_api && $user_role !== 'customer') {
|
||||
return new WP_Error('error', 'No access!');
|
||||
}
|
||||
/**
|
||||
* ADMIN PANEL AUTHENTICATION
|
||||
*/
|
||||
|
||||
// customer role cannot access admin backend
|
||||
if (! $is_rest_api && $user_role === 'customer') {
|
||||
return new WP_Error('error', 'No access!');
|
||||
}
|
||||
// retrieve selected role for user
|
||||
$role = get_user_meta($user->ID, '_wiaas_admin_role', true);
|
||||
// if user has selected role then use it
|
||||
if (! empty($role) && user_can($user->ID, 'wiaas_' . $role)) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
// import organization functions (during user authentication it is not yet loaded)
|
||||
require_once dirname( __FILE__ ) . '/user/wiaas-organization-functions.php';
|
||||
// user does not have selected role so try to assign one in order of access
|
||||
if (user_can($user->ID, 'wiaas_administrator')) {
|
||||
$role = 'administrator';
|
||||
} else if (user_can($user->ID, 'wiaas_commercial_lead')) {
|
||||
$role = 'commercial_lead';
|
||||
} else if (user_can($user->ID, 'wiaas_supplier')) {
|
||||
$role = 'supplier';
|
||||
}
|
||||
|
||||
// get user organization
|
||||
$organization_id = wiaas_get_user_organization_id($user_id);
|
||||
if (empty($role)) {
|
||||
return new WP_Error('wiaas_authentication_error', 'No permissions!', array(
|
||||
'status' => 403,
|
||||
));
|
||||
}
|
||||
|
||||
// validate if user has organization
|
||||
if (empty( $organization_id)) {
|
||||
return new WP_Error('error', 'Account not completed!');
|
||||
}
|
||||
// get organization roles
|
||||
$roles = wiaas_get_organization_roles($organization_id);
|
||||
update_user_meta($user->ID, '_wiaas_admin_role', $role);
|
||||
|
||||
// validate if user has organization roles
|
||||
if (!in_array($user_role, $roles)) {
|
||||
return new WP_Error( 'error', 'Your account is not authorized for requested role. Please contact us for help.' );
|
||||
}
|
||||
$user->set_role($role);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* validate that successfully logged in rest api user can be customer
|
||||
*
|
||||
* @param array $data
|
||||
* @param WP_User $user
|
||||
* @return array | WP_Error
|
||||
*
|
||||
*/
|
||||
|
||||
public static function authenticate_rest_user_on_login($data, $user) {
|
||||
// if admin do nothing
|
||||
if ($user->ID === self::SUPER_ADMIN_USER_ID) {
|
||||
return $data;
|
||||
}
|
||||
$role = user_can($user->ID, 'wiaas_customer') ? 'customer' : '';
|
||||
$user->set_role($role);
|
||||
|
||||
return empty($role) ?
|
||||
new WP_Error('wiaas_authentication_error', 'No Customer permissions!', array(
|
||||
'status' => 403,
|
||||
)) :
|
||||
$data;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Authentication::init();
|
||||
|
||||
@@ -26,6 +26,20 @@ class Wiaas_Cart {
|
||||
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||
|
||||
add_action('woocommerce_checkout_create_order', array(__CLASS__, 'add_additional_order_data'), 99);
|
||||
|
||||
add_action('woocommerce_set_cart_cookies', array(__CLASS__, 'do_not_set_cart_cookies'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not set cart cookies
|
||||
*/
|
||||
public static function do_not_set_cart_cookies() {
|
||||
if ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) {
|
||||
wc_setcookie( 'woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS );
|
||||
wc_setcookie( 'woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,12 +128,13 @@ 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, $addons_ids, $options_ids) {
|
||||
public static function add_package_to_cart($package_id, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||
// try adding package to cart
|
||||
try {
|
||||
// Check if package is in cart
|
||||
@@ -137,19 +152,53 @@ class Wiaas_Cart {
|
||||
|
||||
//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');
|
||||
wc_add_notice('Package cannot be purchased at the moment!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve package country
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
if (empty($country)) {
|
||||
wc_add_notice('Package cannot be added do cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate that order contains only stuff from single commercial lead / reseller / shop owner
|
||||
if ( ! WC()->cart->is_empty() ) {
|
||||
|
||||
$current_shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
||||
|
||||
if (absint($shop_owner_id) !== absint($current_shop_owner_id)) {
|
||||
|
||||
wc_add_notice('Only packages from one catalogue can be purchased at the same time!', 'error');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
|
||||
}
|
||||
|
||||
// Validate that order contains only items for single country
|
||||
if ( ! WC()->cart->is_empty() ) {
|
||||
|
||||
$current_country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
|
||||
|
||||
if ($country !== $current_country) {
|
||||
|
||||
wc_add_notice('Only packages from one country can be purchased at the same time!', 'error');
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
|
||||
}
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
|
||||
// Retrieve package price
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $shop_owner_id);
|
||||
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Initialize additional cart item data for wiaas packages
|
||||
@@ -157,7 +206,6 @@ class Wiaas_Cart {
|
||||
'_wiaas_standard_package' => true,
|
||||
'_wiaas_addon_items' => array(),
|
||||
'_wiaas_option_items' => array(),
|
||||
'_wiaas_currency' => isset($country) ? $country['currency'] : get_woocommerce_currency(),
|
||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||
'_wiaas_documents' => array()
|
||||
);
|
||||
@@ -170,7 +218,7 @@ class Wiaas_Cart {
|
||||
}
|
||||
|
||||
// Add selected additional packages and options
|
||||
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $addons_ids, $options_ids);
|
||||
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids);
|
||||
|
||||
// Trigger calculation of total prices after additional packages are added
|
||||
WC()->cart->calculate_totals();
|
||||
@@ -224,6 +272,10 @@ class Wiaas_Cart {
|
||||
* @return bool
|
||||
*/
|
||||
public static function update_package_quantity($package_cart_item_key, $new_quantity) {
|
||||
if ($new_quantity > 65000){
|
||||
return false;
|
||||
}
|
||||
|
||||
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||
|
||||
if (!$cart_item) {
|
||||
@@ -270,8 +322,12 @@ class Wiaas_Cart {
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist used payment type information for package in corresponding order line item.
|
||||
* Also for standard package type list of addons and options will be saved.
|
||||
* Persist additional metadata for every order item
|
||||
* This includes:
|
||||
*
|
||||
* 1. payment info
|
||||
* 2. relation info for addons and options
|
||||
* 3. prices for simple products
|
||||
*
|
||||
* @param $order_item
|
||||
* @param $cart_item_key
|
||||
@@ -281,7 +337,11 @@ class Wiaas_Cart {
|
||||
* @return WC_Order_Item
|
||||
*/
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
|
||||
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
|
||||
|
||||
$is_bundle_item = wc_pb_is_bundle_container_cart_item($cart_item);
|
||||
$is_bundled_item = wc_pb_is_bundled_cart_item($cart_item);
|
||||
|
||||
if ($is_bundle_item && isset($cart_item['_wiaas_payment'])) {
|
||||
|
||||
$payment = $cart_item['_wiaas_payment'];
|
||||
|
||||
@@ -299,9 +359,6 @@ 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'])) {
|
||||
@@ -353,6 +410,36 @@ class Wiaas_Cart {
|
||||
$order_item->add_meta_data( '_wiaas_documents', $item_documents, true );
|
||||
}
|
||||
|
||||
// save simple product information that needs to be available later on
|
||||
// even if this data is changed or removed from product at that time
|
||||
if($is_bundled_item) {
|
||||
|
||||
$product = wc_get_product($cart_item['product_id']);
|
||||
|
||||
$order_item->add_meta_data('_wiaas_category', Wiaas_Product_Category::get_category($product), true);
|
||||
|
||||
$order_item->add_meta_data('_wiaas_manufacturer_product_no', $product->get_meta('_manufacturer_product_no'), true);
|
||||
$order_item->add_meta_data('_wiaas_supplier_product_no', $product->get_meta('_supplier_product_no'), true);
|
||||
|
||||
// get supplier
|
||||
if ($supplier_organization_id = Wiaas_Product_Supplier::get_supplier_organisation_id_from_product($cart_item['product_id'])) {
|
||||
|
||||
$order_item->add_meta_data('_wiaas_supplier_organization_id', $supplier_organization_id, true);
|
||||
}
|
||||
|
||||
// save bundled product item total cost (price x period)
|
||||
$product_price = Wiaas_Pricing::get_product_total_cost($product);
|
||||
$order_item->add_meta_data('_wiaas_product_price', $product_price, true);
|
||||
}
|
||||
|
||||
// save number of days before earliest installation for bundles
|
||||
if ($is_bundle_item) {
|
||||
$order_item->add_meta_data(
|
||||
'_wiaas_earliest_installation_additional_days',
|
||||
Wiaas_Package::get_earliest_installation_additional_days($cart_item['product_id']),
|
||||
true);
|
||||
}
|
||||
|
||||
|
||||
return $order_item;
|
||||
}
|
||||
@@ -379,11 +466,121 @@ class Wiaas_Cart {
|
||||
'_wiaas_option_for',
|
||||
'_wiaas_option_group_name',
|
||||
'_wiaas_standard_package',
|
||||
'_wiaas_currency',
|
||||
'_wiaas_documents'
|
||||
'_wiaas_documents',
|
||||
'_wiaas_category',
|
||||
'_wiaas_manufacturer_product_no',
|
||||
'_wiaas_supplier_product_no',
|
||||
'_wiaas_supplier_organization_id',
|
||||
'_wiaas_product_price',
|
||||
'_wiaas_earliest_installation_additional_days',
|
||||
'_wiaas_installation',
|
||||
'_wiaas_installation_date'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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->add_meta_data('_wiaas_country_code', $country['code']);
|
||||
|
||||
$order->set_currency($currency);
|
||||
|
||||
// get 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);
|
||||
|
||||
// save commercial lead info in case it gets deleted
|
||||
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
||||
$commercial_lead_organization_info = wiaas_get_organization_info($shop_owner_id);
|
||||
$order->add_meta_data('_wiaas_commercial_lead_info', $commercial_lead_organization_info);
|
||||
|
||||
// save customer organization info in case it gets deleted
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
$customer_organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||
$order->add_meta_data('_wiaas_customer_id', $customer_organization_id);
|
||||
$customer_organization_info = wiaas_get_organization_info($customer_organization_id);
|
||||
$order->add_meta_data('_wiaas_customer_info', $customer_organization_info);
|
||||
|
||||
|
||||
|
||||
// add supplier organizations information to order in case supplier organizations are deleted
|
||||
// save installation suppliers separately
|
||||
$suppliers_info = array();
|
||||
$installation_suppliers_info = array();
|
||||
|
||||
$items = $order->get_items('line_item');
|
||||
|
||||
foreach($items as $item) {
|
||||
|
||||
$supplier_organization_id = $item['wiaas_supplier_organization_id'];
|
||||
|
||||
if (! empty($supplier_organization_id) && $item['wiaas_category'] !== 'installation' &&
|
||||
empty($suppliers_info[$supplier_organization_id]) ) {
|
||||
|
||||
$suppliers_info[$supplier_organization_id] = array(
|
||||
'id' => $supplier_organization_id,
|
||||
'estimated_delivery_date' => null,
|
||||
'confirmed_delivery_date' => null,
|
||||
'tracking_info' => array(),
|
||||
);
|
||||
|
||||
$supplier_organization_info = wiaas_get_organization_info($supplier_organization_id);
|
||||
foreach ($supplier_organization_info as $key => $info) {
|
||||
$suppliers_info[$supplier_organization_id][$key] = $info;
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($supplier_organization_id) && $item['wiaas_category'] === 'installation' &&
|
||||
empty($installation_suppliers_info[$supplier_organization_id]) ) {
|
||||
|
||||
$installation_suppliers_info[$supplier_organization_id] = array(
|
||||
'id' => $supplier_organization_id,
|
||||
);
|
||||
|
||||
$supplier_organization_info = wiaas_get_organization_info($supplier_organization_id);
|
||||
foreach ($supplier_organization_info as $key => $info) {
|
||||
$installation_suppliers_info[$supplier_organization_id][$key] = $info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$order->add_meta_data('_wiaas_delivery_suppliers', $suppliers_info, true);
|
||||
$order->add_meta_data('_wiaas_installation_suppliers', $installation_suppliers_info, true);
|
||||
|
||||
// add additional date fields to order
|
||||
$order->add_meta_data('_wiaas_estimated_delivery_date', null, true);
|
||||
$order->add_meta_data('_wiaas_final_estimated_delivery_date', null, true);
|
||||
$order->add_meta_data('_wiaas_final_confirmed_delivery_date', null, true);
|
||||
$order->add_meta_data('_wiaas_earliest_installation_date', null, true);
|
||||
|
||||
// calculate number of days before earlier installation for whole order
|
||||
$earliest_installation_additional_days = 0;
|
||||
$items = $order->get_items('line_item');
|
||||
|
||||
foreach($items as $item) {
|
||||
|
||||
if (! empty($item['_wiaas_earliest_installation_additional_days'])) {
|
||||
|
||||
$additional_days = absint($item['_wiaas_earliest_installation_additional_days']);
|
||||
$earliest_installation_additional_days = max($additional_days, $earliest_installation_additional_days);
|
||||
}
|
||||
}
|
||||
|
||||
$order->add_meta_data('_wiaas_order_additional_days_prior_installation', $earliest_installation_additional_days, true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate total cost for cart item
|
||||
*
|
||||
@@ -451,6 +648,9 @@ 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) {
|
||||
@@ -500,8 +700,8 @@ class Wiaas_Cart {
|
||||
'package_name' => $package->get_title(),
|
||||
'quantity' => $item['quantity'],
|
||||
|
||||
'commercial_lead_id' => 14,
|
||||
'commercial_lead' => 'Coor Service Management',
|
||||
'commercial_lead_id' => $shop_owner_id,
|
||||
'commercial_lead' => wiaas_get_organization_name($shop_owner_id),
|
||||
'country' => Wiaas_Countries::get_package_country($package),
|
||||
|
||||
'are_additional_available' => true,
|
||||
@@ -542,6 +742,7 @@ class Wiaas_Cart {
|
||||
|
||||
$documents_ids = array();
|
||||
|
||||
// Retrieve all document ids attached to cart content
|
||||
foreach ($items as $key => $item) {
|
||||
if (!isset($item['_wiaas_standard_package'])) {
|
||||
continue;
|
||||
@@ -559,16 +760,19 @@ class Wiaas_Cart {
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve all customer visible template documents attached to cart content
|
||||
$q = new WP_Query();
|
||||
$retrieved_items = $q->query(array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'wiaas_doc',
|
||||
'post__in' => array_keys($documents_ids),
|
||||
'meta_key' => '_wiaas_doc_visible',
|
||||
'meta_value' => 'yes', // visible to customer
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wiaas_doc_type',
|
||||
'field' => 'slug',
|
||||
'terms' => array_keys(self::$cart_doc_types),
|
||||
'terms' => array_keys(self::$cart_doc_types), // templates only
|
||||
)
|
||||
)
|
||||
));
|
||||
@@ -636,21 +840,20 @@ class Wiaas_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, $addons_ids, $options_ids) {
|
||||
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||
|
||||
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||
|
||||
$addon_items_keys = array();
|
||||
$option_items_keys = array();
|
||||
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
|
||||
// Try adding package addons to cart
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
@@ -665,7 +868,7 @@ class Wiaas_Cart {
|
||||
$addon_package,
|
||||
$parent_item['data'],
|
||||
$customer_id,
|
||||
$commercial_lead_id
|
||||
$shop_owner_id
|
||||
);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
@@ -702,7 +905,7 @@ class Wiaas_Cart {
|
||||
$option_package,
|
||||
$parent_item['data'],
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
$shop_owner_id);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Retrieve option package group name
|
||||
|
||||
@@ -65,7 +65,8 @@ class Wiaas_Checkout {
|
||||
|
||||
do_action( 'woocommerce_checkout_order_processed', $order_id, array(), $order );
|
||||
|
||||
$order->payment_complete();
|
||||
//Change order status from default 'Pending payment' to open (custom wiaas status)
|
||||
$order->update_status('open');
|
||||
|
||||
WC()->cart->empty_cart( true );
|
||||
|
||||
@@ -83,14 +84,6 @@ class Wiaas_Checkout {
|
||||
* @param array $data
|
||||
*/
|
||||
private static function _add_wiaas_checkout_data($order, $data) {
|
||||
// save currency
|
||||
$line_items = $order->get_items();
|
||||
foreach ($line_items as $line_item) {
|
||||
if (isset($line_item['wiaas_currency'])) {
|
||||
$order->set_currency($line_item['wiaas_currency']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// save additional wiaas order info
|
||||
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
|
||||
@@ -102,6 +95,7 @@ class Wiaas_Checkout {
|
||||
if (isset($data['project_id'])) {
|
||||
Wiaas_Order_Project::set_project_for_order($order->get_id(), $data['project_id']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,28 +12,19 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class Wiaas_Countries {
|
||||
|
||||
/**
|
||||
* Available countries for wiaas
|
||||
* Default available countries for wiaas
|
||||
* @var array
|
||||
*/
|
||||
private static $available_countries = array(
|
||||
'Sweden' => array(
|
||||
'id' => 1,
|
||||
'name' => 'Sweden',
|
||||
'code' => 'se',
|
||||
private static $default_countries = array(
|
||||
'se' => array(
|
||||
'vat' => 9 ,
|
||||
'currency' => 'SEK'
|
||||
),
|
||||
'Denmark' => array(
|
||||
'id' => 2,
|
||||
'name' => 'Denmark',
|
||||
'code' => 'dk',
|
||||
'dk' => array(
|
||||
'vat' => 9 ,
|
||||
'currency' => 'DKK'
|
||||
),
|
||||
'Finland' => array(
|
||||
'id' => 3,
|
||||
'name' => 'Finland',
|
||||
'code' => 'fi',
|
||||
'fi' => array(
|
||||
'vat' => 9 ,
|
||||
'currency' => 'EUR'
|
||||
),
|
||||
@@ -44,22 +35,101 @@ class Wiaas_Countries {
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
|
||||
}
|
||||
|
||||
public static function get_list_of_countries(){
|
||||
$result = [];
|
||||
foreach(self::$available_countries as $country){
|
||||
array_push($result, array(
|
||||
'country_id' => $country['id'],
|
||||
'country_name' => $country['name']
|
||||
));
|
||||
/**
|
||||
* Retrieve all possible country choices
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_country_choices() {
|
||||
$countries = new WC_Countries();
|
||||
$choices = array();
|
||||
|
||||
foreach ($countries->get_countries() as $code => $name) {
|
||||
$choices[strtolower($code)] = $name;
|
||||
}
|
||||
return $result;
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
public static function get_country_name_by_id($id){
|
||||
foreach(self::$available_countries as $country){
|
||||
if ($country['id'] == $id) return $country['name'];
|
||||
/**
|
||||
* Retrieve all possible currency choices
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_currency_choices() {
|
||||
return get_woocommerce_currencies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve list of available countries setup by administrator
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_available_countries() {
|
||||
$available_countries = [];
|
||||
|
||||
$available_country_terms = get_terms(array(
|
||||
'taxonomy' => 'product_country',
|
||||
'hide_empty' => false,
|
||||
));
|
||||
|
||||
foreach($available_country_terms as $country_term) {
|
||||
$code = get_term_meta($country_term->term_id, '_wiaas_country_code', true);
|
||||
$currency = get_term_meta($country_term->term_id, '_wiaas_country_currency', true);
|
||||
$vat = get_term_meta($country_term->term_id, '_wiaas_country_vat', true);
|
||||
|
||||
$available_countries[] = array(
|
||||
'id' => $country_term->term_id,
|
||||
'name' => $country_term->name,
|
||||
'code' => $code,
|
||||
'currency' => $currency,
|
||||
'vat' => $vat
|
||||
);
|
||||
}
|
||||
return '';
|
||||
|
||||
return $available_countries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve country name by code for available country
|
||||
*
|
||||
* @param string $code
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function get_available_country_name_by_code($code) {
|
||||
$available_countries = self::get_available_countries();
|
||||
|
||||
foreach ($available_countries as $available_country) {
|
||||
|
||||
if ($available_country['code'] === $code) {
|
||||
|
||||
return $available_country['name'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve country code by currency for available country
|
||||
*
|
||||
* @param string $currency
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function get_available_country_code_by_currency($currency) {
|
||||
$available_countries = self::get_available_countries();
|
||||
|
||||
foreach ($available_countries as $available_country) {
|
||||
|
||||
if ($available_country['currency'] === $currency) {
|
||||
|
||||
return $available_country['code'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,8 +163,27 @@ class Wiaas_Countries {
|
||||
|
||||
register_taxonomy( 'product_country', array( 'product' ), $args );
|
||||
|
||||
foreach (self::$available_countries as $available_country) {
|
||||
wp_insert_term($available_country['name'], 'product_country');
|
||||
$choices = self::get_country_choices();
|
||||
|
||||
foreach (self::$default_countries as $code => $info) {
|
||||
|
||||
$name = $choices[$code];
|
||||
|
||||
if (has_term($name)) {
|
||||
// bail out
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $choices[$code];
|
||||
$result = wp_insert_term($name, 'product_country');
|
||||
|
||||
if (is_wp_error($result)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
update_term_meta($result->term_id, '_wiaas_country_code', $code);
|
||||
update_term_meta($result->term_id, '_wiaas_country_currency', $info['currency']);
|
||||
update_term_meta($result->term_id, '_wiaas_country_vat', $info['vat']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,12 +203,40 @@ class Wiaas_Countries {
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
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;
|
||||
public static function get_product_country($product) {
|
||||
$country_terms = get_the_terms($product->get_id(), 'product_country');
|
||||
|
||||
if (is_wp_error($country_terms) || empty($country_terms) || empty($country_terms[0])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$country_term = $country_terms[0];
|
||||
|
||||
$code = get_term_meta($country_term->term_id, '_wiaas_country_code', true);
|
||||
$currency = get_term_meta($country_term->term_id, '_wiaas_country_currency', true);
|
||||
$vat = get_term_meta($country_term->term_id, '_wiaas_country_vat', true);
|
||||
|
||||
return array(
|
||||
'id' => $country_term->term_id,
|
||||
'name' => $country_term->name,
|
||||
'code' => $code,
|
||||
'currency' => $currency,
|
||||
'vat' => $vat
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
@@ -5,22 +5,31 @@ defined( 'ABSPATH' ) || exit;
|
||||
class Wiaas_DB_Update {
|
||||
|
||||
private static $db_updates = array(
|
||||
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
|
||||
'20180801222206' => 'wiaas_db_update_setup_gravity',
|
||||
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
|
||||
'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',
|
||||
'201810111644700' => 'wiaas_db_update_add_organization_info_ui_fields',
|
||||
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
|
||||
'201810171645700' => 'wiaas_db_update_create_default_roles',
|
||||
'201810171745700' => 'wiaas_db_import_aam_role_settings',
|
||||
'201810173045700' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
||||
'201810173145700' => 'wiaas_db_update_update_supplier_capabilities',
|
||||
'201810173245700' => 'wiaas_db_update_update_admin_capabilities',
|
||||
'201810173345700' => 'wiaas_create_role_access_groups'
|
||||
'20181012164450' => 'wiaas_db_update_add_user_organization_ui_fields',
|
||||
'20181017164550' => 'wiaas_db_update_create_default_roles',
|
||||
'20181017174550' => 'wiaas_db_import_aam_role_settings',
|
||||
'20181018014550' => 'wiaas_db_update_update_supplier_capabilities',
|
||||
'20181018024550' => 'wiaas_db_update_update_admin_capabilities',
|
||||
'20181018034550' => 'wiaas_admin_create_role_access_groups',
|
||||
'20181018044450' => 'wiaas_db_setup_create_customer_commercial_lead_table',
|
||||
'20181018054450' => 'wiaas_db_update_update_commercial_lead_capabilities',
|
||||
'20181018064450' => 'wiaas_db_update_add_organization_info_ui_fields',
|
||||
'20181019014550' => 'wiaas_db_update_add_general_ui_fields',
|
||||
'20181019014650' => 'wiaas_db_update_add_product_properties_ui_fields',
|
||||
'20181020014650' => 'wiaas_create_organization_roles_capabilities',
|
||||
'20181021162450' => 'wiaas_db_update_update_supplier_order_capabilities',
|
||||
'20181102112451' => 'wiaas_disable_processing_order_email_delivery',
|
||||
'20181103172850' => 'wiaas_db_update_update_delivery_forms',
|
||||
'20181104182856' => 'wiaas_db_update_enable_workflow_inbox_for_roles',
|
||||
'20181105133550' => 'wiaas_db_update_add_bundle_properties_ui_field',
|
||||
'20181106133553' => 'wiaas_db_update_add_installation_date_delivery_action_form',
|
||||
'20181125133553' => 'wiaas_db_update_add_country_settings_ui_fields',
|
||||
'20181125143553' => 'wiaas_db_migration_fix_user_profile_addresses', // remove after migration
|
||||
'20181125153553' => 'wiaas_db_migration_fix_countries' // remove after migration
|
||||
);
|
||||
|
||||
public static function execute() {
|
||||
|
||||
11
backend/app/plugins/wiaas/includes/class-wiaas-db.php
Normal file
11
backend/app/plugins/wiaas/includes/class-wiaas-db.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_DB {
|
||||
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/db/class-wiaas-shop-db.php';
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_DB::init();
|
||||
@@ -10,53 +10,82 @@ defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Wiaas_Delivery_Process {
|
||||
|
||||
private static $process_form_title_prefix = 'DELIVERY PROCESS:';
|
||||
|
||||
public static function init() {
|
||||
self::_register_delivery_process_step_type();
|
||||
self::_register_delivery_process();
|
||||
|
||||
self::_init_hooks();
|
||||
}
|
||||
|
||||
private static function _init_hooks() {
|
||||
add_action('woocommerce_new_order', array( __CLASS__, 'create_delivery_process_for_order' ));
|
||||
|
||||
add_filter( 'gform_entry_meta', array(__CLASS__, 'extend_gravity_form_entry_meta'), 10, 2 );
|
||||
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_process_step'), 5, 3 );
|
||||
|
||||
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 3 );
|
||||
|
||||
// Some temporary functions to make inbox page prettier
|
||||
add_filter('gravityflow_inbox_submitter_name', array(__CLASS__, 'display_step_name_in_inbox'), 10, 3);
|
||||
add_filter('gravityflow_approve_label_workflow_detail', array(__CLASS__, 'approval_step_approval_label'), 10, 2);
|
||||
add_filter('gravityflow_reject_label_workflow_detail', array(__CLASS__, 'approval_step_reject_label'), 10, 2);
|
||||
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_order'), 10, 2 );
|
||||
}
|
||||
|
||||
public static function approval_step_approval_label($label, $step) {
|
||||
if ($step->get_name() === 'Complete step') {
|
||||
return esc_html__( 'Complete step', 'wiaas' );
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
public static function approval_step_reject_label($label, $step) {
|
||||
if ($step->get_name() === 'Complete step') {
|
||||
return esc_html__( 'Cancel', 'wiaas' );
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
public static function display_step_name_in_inbox($name, $entry, $form) {
|
||||
return $entry['wiaas_delivery_step_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers our Delivery Process Step Type as available Gravity Flow Step Type
|
||||
*
|
||||
* Registers our Delivery Process Addons
|
||||
*
|
||||
*/
|
||||
private static function _register_delivery_process_step_type() {
|
||||
private static function _register_delivery_process() {
|
||||
require_once( 'delivery-process/class-wiaas-delivery-process-addon.php' );
|
||||
require_once( 'delivery-process/class-wiaas-delivery-process-action.php' );
|
||||
require_once( 'delivery-process/class-wiaas-delivery-process-step-assignee.php' );
|
||||
require_once( 'delivery-process/class-wiaas-delivery-process-step.php' );
|
||||
|
||||
// order fields
|
||||
require_once( 'delivery-process/class-wiaas-order-fields.php' );
|
||||
|
||||
require_once( 'delivery-process/class-wiaas-field-order-number.php' );
|
||||
require_once( 'delivery-process/class-wiaas-field-order-bundle.php' );
|
||||
require_once( 'delivery-process/class-wiaas-field-order-installation-select.php' );
|
||||
require_once( 'delivery-process/class-wiaas-field-order-bundle-document.php' );
|
||||
require_once( 'delivery-process/class-wiaas-field-order-document.php' );
|
||||
require_once( 'delivery-process/class-wiaas-field-order-bundle-installation-date.php' );
|
||||
|
||||
// merge tags (for emails)
|
||||
require_once( 'delivery-process/class-wiaas-merge-tag-customer-order-url.php' );
|
||||
|
||||
Gravity_Flow_Steps::register( new Wiaas_Delivery_Process_Step() );
|
||||
|
||||
GFAddOn::register( 'Wiaas_Delivery_Process_Addon' );
|
||||
}
|
||||
|
||||
|
||||
public static function create_delivery_process_for_order($order_id, $process_id) {
|
||||
|
||||
$process_form = null;
|
||||
$process_form = GFAPI::get_form($process_id);
|
||||
|
||||
if( $process_form ) {
|
||||
|
||||
$new_process_entry = array(
|
||||
'wiaas_delivery_order_id' => $order_id,
|
||||
'form_id' => $process_id,
|
||||
);
|
||||
|
||||
$order_fields = GFCommon::get_fields_by_type($process_form, array('wiaas_order'));
|
||||
|
||||
|
||||
if (! empty($order_fields)) {
|
||||
|
||||
$order_field = $order_fields[0];
|
||||
|
||||
$new_process_entry[$order_field['id']] = $order_id;
|
||||
}
|
||||
|
||||
$process_entry_id = GFAPI::add_entry( $new_process_entry );
|
||||
|
||||
update_post_meta($order_id, 'wiaas_delivery_process_id', $process_id);
|
||||
update_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order->set_status('processing', 'Started order delivery process.', true);
|
||||
$order->save();
|
||||
|
||||
return $process_entry_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,9 +94,10 @@ class Wiaas_Delivery_Process {
|
||||
* @param $form
|
||||
*/
|
||||
public static function maybe_complete_parent_order($entry_id, $form) {
|
||||
|
||||
$entry = GFAPI::get_entry($entry_id);
|
||||
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
$order_id = $entry['wiaas_delivery_order_id'];
|
||||
|
||||
if (!isset($order_id)) {
|
||||
return;
|
||||
@@ -76,12 +106,170 @@ class Wiaas_Delivery_Process {
|
||||
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id', true);
|
||||
|
||||
// order process entry completed, so complete order
|
||||
if (absint($process_entry_id) === $entry_id) {
|
||||
if (absint($process_entry_id) === absint($entry_id)) {
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_status('completed', 'Completed order delivery process.', true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_available_process_list_for_country($country_code) {
|
||||
|
||||
$forms = GFAPI::get_forms();
|
||||
|
||||
$available_process_forms = array();
|
||||
|
||||
foreach ($forms as $form) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
if ($delivery_settings['delivery_form_type'] === 'process' &&
|
||||
$delivery_settings['delivery_country'] === $country_code) {
|
||||
|
||||
$available_process_forms[] = $form;
|
||||
}
|
||||
}
|
||||
|
||||
return $available_process_forms;
|
||||
}
|
||||
|
||||
|
||||
public static function get_customer_acceptance_data($order_id) {
|
||||
|
||||
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
|
||||
|
||||
$data = array();
|
||||
|
||||
if (! empty($delivery_process_entry)) {
|
||||
|
||||
$workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
|
||||
|
||||
$step = $workflow->get_current_step($delivery_process_entry);
|
||||
|
||||
if ($step && Wiaas_Delivery_Process_Action::process_step_has_customer_acceptance_action($step)) {
|
||||
|
||||
$action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
|
||||
|
||||
$action_entry = $action_entries[0];
|
||||
|
||||
$data[] = Wiaas_Delivery_Process_Action::get_customer_acceptance_action_data($action_entry['id']);
|
||||
}
|
||||
}
|
||||
|
||||
return empty( $data ) ? $data : $data[0];
|
||||
}
|
||||
|
||||
public static function get_customer_questionnaires_data($order_id) {
|
||||
|
||||
$data = array();
|
||||
|
||||
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if (! empty($delivery_process_entry)) {
|
||||
|
||||
$workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
|
||||
|
||||
$step = $workflow->get_current_step($delivery_process_entry);
|
||||
|
||||
if ($step && Wiaas_Delivery_Process_Action::process_step_has_customer_validate_questionnaires_action($step)) {
|
||||
|
||||
$action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
|
||||
|
||||
foreach ($action_entries as $action_entry) {
|
||||
|
||||
$action_data = Wiaas_Delivery_Process_Action::get_customer_validate_questionnaires_action_data($action_entry['id']);
|
||||
|
||||
if (! empty($action_data)) {
|
||||
|
||||
$data[] = $action_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function update_customer_acceptance_status($order_id, $status, $reason) {
|
||||
|
||||
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if (! empty($delivery_process_entry) ) {
|
||||
|
||||
$workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
|
||||
|
||||
$step = $workflow->get_current_step($delivery_process_entry);
|
||||
|
||||
$action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
|
||||
|
||||
$action_entry = $action_entries[0];
|
||||
|
||||
Wiaas_Delivery_Process_Action::update_customer_acceptance_status($action_entry['id'], $status, $reason);
|
||||
}
|
||||
}
|
||||
|
||||
public static function is_customer_acceptance_uploaded($order_id) {
|
||||
|
||||
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if (! empty($delivery_process_entry) ) {
|
||||
|
||||
$workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
|
||||
|
||||
$step = $workflow->get_current_step($delivery_process_entry);
|
||||
|
||||
$action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
|
||||
|
||||
$action_entry = $action_entries[0];
|
||||
|
||||
return Wiaas_Delivery_Process_Action::is_customer_acceptance_uploaded($action_entry['id']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function upload_customer_questionnaire($order_id, $action_entry_id) {
|
||||
|
||||
Wiaas_Delivery_Process_Action::upload_customer_questionnaire($action_entry_id);
|
||||
}
|
||||
|
||||
public static function upload_customer_acceptance_document($order_id) {
|
||||
|
||||
$delivery_process_entry = self::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if (! empty($delivery_process_entry) ) {
|
||||
|
||||
$workflow = new Gravity_Flow_API($delivery_process_entry['form_id']);
|
||||
|
||||
$step = $workflow->get_current_step($delivery_process_entry);
|
||||
|
||||
$action_entries = Wiaas_Delivery_Process_Action::get_process_step_action_entries($step);
|
||||
|
||||
$action_entry = $action_entries[0];
|
||||
|
||||
$success = Wiaas_Delivery_Process_Action::upload_customer_acceptance_document($action_entry['id']);
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function get_order_delivery_process_entry($order_id) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$process_entry_id = $order->get_meta('wiaas_delivery_process_entry_id', true);
|
||||
|
||||
if (empty($process_entry_id)) {
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
return GFAPI::get_entry($process_entry_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves delivery process instance for order
|
||||
*
|
||||
@@ -91,8 +279,9 @@ class Wiaas_Delivery_Process {
|
||||
*/
|
||||
public static function get_order_delivery_process($order_id) {
|
||||
|
||||
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id');
|
||||
if (!isset($process_entry_id)) {
|
||||
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id', true);
|
||||
|
||||
if (empty($process_entry_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -107,114 +296,57 @@ class Wiaas_Delivery_Process {
|
||||
$delivery_process = array(
|
||||
'id' => $process_form['id'],
|
||||
'name' => $process_form['title'],
|
||||
'steps' => array()
|
||||
'steps' => array(
|
||||
array(
|
||||
'short_desc' => 'Order placed',
|
||||
'status' => 'complete',
|
||||
'order_id' => $order_id,
|
||||
'process_id' => $process_entry_id,
|
||||
'step_id' => -1,
|
||||
),
|
||||
array(
|
||||
'short_desc' => 'Assign process',
|
||||
'status' => 'complete',
|
||||
'order_id' => $order_id,
|
||||
'process_id' => $process_entry_id,
|
||||
'step_id' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $steps_info as $step_info ) {
|
||||
$step = $api->get_step( $step_info->get_id(), $process_instance );
|
||||
$current_step = $api->get_current_step($process_instance);
|
||||
|
||||
foreach ( $steps_info as $step_info ) {
|
||||
$step = $api->get_step( $step_info->get_id(), $process_instance );
|
||||
|
||||
if (! $step->is_visible_to_customer) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$action_code = Wiaas_Delivery_Process_Action::get_process_step_action_form_action_code($step);
|
||||
$info = $step->get_feed_meta();
|
||||
|
||||
$status = $step->get_status();
|
||||
|
||||
if ($current_step && $current_step->get_id() === $step->get_id()) {
|
||||
$status = 'pending';
|
||||
}
|
||||
|
||||
|
||||
$delivery_process['steps'][] = array(
|
||||
'step_id' => $step->get_id(),
|
||||
'step_form_entry_id' => $step->get_target_form_entry_id() ?: null,
|
||||
'process_id' => $process_entry_id,
|
||||
'short_desc' => $info['step_name'],
|
||||
'full_desc' => $info['description'],
|
||||
'action_code' => $step->get_delivery_action_type(),
|
||||
'step_type' => $step->get_delivery_action_type() === 'manual' ? 'manual' : 'extraAction',
|
||||
'status' => $step->get_status() ?: 'inactive',
|
||||
'action_code' => $action_code,
|
||||
'status' => $status,
|
||||
'order_id' => $order_id,
|
||||
'actual_date' => $step->get_target_actual_date(),
|
||||
'comments' => $step->get_target_step_comments(),
|
||||
);
|
||||
}
|
||||
|
||||
return $delivery_process;
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically create delivery process instance when order is created
|
||||
* @param $order_id
|
||||
*/
|
||||
public static function create_delivery_process_for_order($order_id) {
|
||||
$process_form = null;
|
||||
$forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true );
|
||||
$process_form = $forms[0];
|
||||
if(isset($process_form)) {
|
||||
$order = wc_get_order( $order_id );
|
||||
$new_process_entry = array(
|
||||
'form_id' => $process_form->id,
|
||||
'2' => $order->get_customer_id(),
|
||||
'wiaas_delivery_order_id' => $order_id,
|
||||
);
|
||||
$process_entry_id = GFAPI::add_entry( $new_process_entry );
|
||||
|
||||
add_post_meta($order_id, 'wiaas_delivery_process_id', $process_form->id);
|
||||
add_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
|
||||
*
|
||||
* This way we can track for each delivery step its parent process
|
||||
* @param $entry_meta
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function extend_gravity_form_entry_meta($entry_meta) {
|
||||
$entry_meta[ 'wiaas_delivery_process_id' ] = array(
|
||||
'label' => 'Wiaas Delivery Process Id',
|
||||
'is_numeric' => true,
|
||||
'update_entry_meta_callback' => null,
|
||||
'is_default_column' => false, // this column will be displayed by default on the entry list
|
||||
'filter' => array(
|
||||
'operators' => array( 'is' ),
|
||||
),
|
||||
);
|
||||
|
||||
$entry_meta[ 'wiaas_delivery_order_id' ] = array(
|
||||
'label' => 'Wiaas Delivery Process Order Id',
|
||||
'is_numeric' => true,
|
||||
'update_entry_meta_callback' => null,
|
||||
'is_default_column' => false, // this column will be displayed by default on the entry list
|
||||
'filter' => array(
|
||||
'operators' => array( 'is' ),
|
||||
),
|
||||
);
|
||||
|
||||
$entry_meta[ 'wiaas_delivery_step_name' ] = array(
|
||||
'label' => 'Wiaas Delivery Step name',
|
||||
'is_numeric' => false,
|
||||
'update_entry_meta_callback' => null,
|
||||
'is_default_column' => false, // this column will be displayed by default on the entry list
|
||||
'filter' => array(
|
||||
'operators' => array( 'is' ),
|
||||
),
|
||||
);
|
||||
|
||||
return $entry_meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process parent process when single step workflow has completed
|
||||
* @param $entry_id
|
||||
* @param $form
|
||||
* @param $final_status
|
||||
*/
|
||||
public static function maybe_complete_parent_process_step($entry_id, $form) {
|
||||
$entry = GFAPI::get_entry($entry_id);
|
||||
$parent_entry_id = $entry['wiaas_delivery_process_id'];
|
||||
|
||||
if (empty($parent_entry_id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parent_entry_id = absint( $parent_entry_id );
|
||||
$parent_entry = GFAPI::get_entry( $parent_entry_id );
|
||||
|
||||
$parent_api = new Gravity_Flow_API( $parent_entry['form_id'] );
|
||||
$parent_api->process_workflow( $parent_entry_id );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );
|
||||
|
||||
@@ -18,8 +18,15 @@ class Wiaas_Order {
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
||||
require_once dirname( __FILE__ ) . '/order/wiaas-order-functions.php';
|
||||
|
||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
|
||||
|
||||
add_filter( 'woocommerce_register_shop_order_post_statuses', array(__CLASS__, 'register_custom_order_statuses'), 10, 1);
|
||||
|
||||
add_filter( 'wc_order_statuses', array(__CLASS__, 'add_custom_statuses_to_list' ), 10, 1);
|
||||
|
||||
add_filter( 'bulk_actions-edit-shop_order', array(__CLASS__, 'add_custom_statuses_to_bulk_edit' ), 10, 1);
|
||||
|
||||
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
||||
|
||||
@@ -28,6 +35,252 @@ class Wiaas_Order {
|
||||
add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2);
|
||||
|
||||
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
|
||||
|
||||
add_filter('woocommerce_order_number', array( __CLASS__, 'format_order_number'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prefix order number
|
||||
*
|
||||
* @param int $number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function format_order_number($number) {
|
||||
return "1000000$number";
|
||||
}
|
||||
|
||||
public static function get_additional_days_prior_installation($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
return $order->get_meta('_wiaas_order_additional_days_prior_installation');
|
||||
}
|
||||
|
||||
public static function add_additional_tracking_info($order_id, $supplier_id){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['tracking_info'][] = array(
|
||||
'number' => '',
|
||||
'url' => ''
|
||||
);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function save_tracking_info($order_id, $supplier_id, $tracking_index, $tracking_num, $tracking_url){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['tracking_info'][$tracking_index]['number'] = $tracking_num;
|
||||
$suppliers[$key]['tracking_info'][$tracking_index]['url'] = $tracking_url;
|
||||
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function delete_tracking_info($order_id, $supplier_id, $tracking_index){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
unset($suppliers[$key]['tracking_info'][$tracking_index]);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function save_estimated_date($order_id, $supplier_id, $date){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
$updated = false;
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['estimated_date'] = $date;
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$updated){
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function save_confirmed_date($order_id, $supplier_id, $date){
|
||||
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
$updated = false;
|
||||
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['confirmed_date'] = $date;
|
||||
$updated = true;
|
||||
if (!$suppliers[$key]['estimated_date']){
|
||||
$suppliers[$key]['estimated_date'] = $date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$updated){
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_order_estimated_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_order_estimated_delivery_date') ?: NULL;
|
||||
}
|
||||
|
||||
public static function save_order_estimated_date($order_id, $date){
|
||||
return update_post_meta($order_id, '_wiaas_order_estimated_delivery_date', $date);
|
||||
}
|
||||
|
||||
public static function get_final_estimated_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_final_estimated_delivery_date') ?: 0;
|
||||
}
|
||||
|
||||
public static function get_final_confirmed_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_final_confirmed_delivery_date') ?: 0;
|
||||
}
|
||||
|
||||
public static function get_earliest_installation_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_earliest_installation_date') ?: 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get suppliers related to order
|
||||
*/
|
||||
public static function get_suppliers($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
return $order->get_meta('_wiaas_delivery_suppliers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register additional order statuses
|
||||
*
|
||||
* @param array $order_statuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function register_custom_order_statuses($order_statuses){
|
||||
// Status must start with "wc-"
|
||||
$order_statuses['wc-open'] = array(
|
||||
'label' => _x( 'Open', 'Order status', 'woocommerce' ),
|
||||
'public' => false,
|
||||
'exclude_from_search' => false,
|
||||
'show_in_admin_all_list' => true,
|
||||
'show_in_admin_status_list' => true,
|
||||
'label_count' => _n_noop( 'Open <span class="count">(%s)</span>', 'Open <span class="count">(%s)</span>', 'woocommerce' ),
|
||||
);
|
||||
return $order_statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* display custom wiaas statuses in order status dropdown
|
||||
*
|
||||
* @param array $order_statuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function add_custom_statuses_to_list($order_statuses){
|
||||
$order_statuses['wc-open'] = _x( 'Open', 'Order status', 'woocommerce' );
|
||||
return $order_statuses;
|
||||
}
|
||||
|
||||
/**
|
||||
* display custom wiaas statuses in bulk actions
|
||||
*
|
||||
* @param array $bulk_actions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function add_custom_statuses_to_bulk_edit($bulk_actions){
|
||||
// Note: "mark_" must be there instead of "wc"
|
||||
$bulk_actions['mark_open'] = 'Change status to open';
|
||||
return $bulk_actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@@ -39,16 +292,6 @@ 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
|
||||
@@ -159,10 +402,63 @@ class Wiaas_Order {
|
||||
return get_post_meta($order_id, '_wiaas_tender', true);
|
||||
}
|
||||
|
||||
public static function get_order_country_code($order_id) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$code = $order->get_meta('_wiaas_country_code');
|
||||
|
||||
if (empty($code)) {
|
||||
$code = Wiaas_Countries::get_available_country_code_by_currency($order->get_currency());
|
||||
$order->add_meta_data('_wiaas_country_code', $code);
|
||||
$order->save_meta_data();
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* PRIVATE
|
||||
*/
|
||||
|
||||
private static function _update_max_and_earliest_dates($order, $suppliers){
|
||||
$max_estimated_date = 0;
|
||||
$max_confirmed_date = 0;
|
||||
$earliest_installation_date = 0;
|
||||
$missing_estimated = false;
|
||||
|
||||
foreach($suppliers as $supplier) {
|
||||
|
||||
if (! empty($supplier['confirmed_date']) ) {
|
||||
|
||||
$max_confirmed_date = max($max_confirmed_date, $supplier['confirmed_date']);
|
||||
} else {
|
||||
|
||||
$missing_confirmed = true;
|
||||
}
|
||||
|
||||
if (! empty($supplier['estimated_date']) ) {
|
||||
|
||||
$max_estimated_date = max($max_estimated_date, $supplier['estimated_date']);
|
||||
|
||||
} else {
|
||||
|
||||
$missing_estimated = true;
|
||||
$earliest_installation_date = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $missing_estimated) {
|
||||
|
||||
$earliest_installation_date = max($max_estimated_date, $max_confirmed_date);
|
||||
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' weekdays', $earliest_installation_date);
|
||||
}
|
||||
|
||||
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
|
||||
$order->update_meta_data('_wiaas_final_estimated_delivery_date', $max_estimated_date);
|
||||
$order->update_meta_data('_wiaas_earliest_installation_date', $earliest_installation_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append specific wiaas order details, like reference
|
||||
* @param $data
|
||||
@@ -182,19 +478,33 @@ class Wiaas_Order {
|
||||
/**
|
||||
* Appends additional wiaas customer lead info to order json response
|
||||
* @param $data
|
||||
* @param $order
|
||||
* @param WC_Order $order
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function _append_commercial_lead_info($data, $order, $request) {
|
||||
|
||||
$data['commercial_lead'] = array(
|
||||
'id' => 1,
|
||||
'name' => 'Coor Service Management',
|
||||
'phone' => '123456789',
|
||||
'email' => 'rikard@co-ideation.com'
|
||||
);
|
||||
$commercial_lead_org_id = $order->get_meta('_wiaas_commercial_lead_id', true);
|
||||
|
||||
$commercial_lead_organization_info = $order->get_meta('_wiaas_commercial_lead_info', true);
|
||||
|
||||
if (! empty($commercial_lead_org_id) && empty($commercial_lead_organization_info)) {
|
||||
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
|
||||
|
||||
$data['commercial_lead'] = array(
|
||||
'id' => $commercial_lead_org_id,
|
||||
'name' => $commercial_lead_organization_info['name'],
|
||||
'phone' => $commercial_lead_organization_info['phone'],
|
||||
'email' => $commercial_lead_organization_info['email']
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($commercial_lead_organization_info)) {
|
||||
$commercial_lead_organization_info['id'] = $commercial_lead_org_id;
|
||||
|
||||
$data['commercial_lead'] = $commercial_lead_organization_info;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -202,25 +512,34 @@ class Wiaas_Order {
|
||||
/**
|
||||
* Appends additional wiaas customer info to order json response
|
||||
* @param $data
|
||||
* @param $order
|
||||
* @param WC_Order $order
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function _append_customer_info($data, $order, $request) {
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
$customer_organization_id = $order->get_meta('_wiaas_customer_id', true);
|
||||
|
||||
$customer_id = $data['customer_id'];
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
|
||||
$customer_user = get_user_by('id', $customer_id);
|
||||
$data['customer'] = array(
|
||||
'email' => $customer_user->user_email,
|
||||
'name' => $customer_user->display_name,
|
||||
'phone' => '+46 (10) 5595148'
|
||||
);
|
||||
if (empty($customer_organization_id)) {
|
||||
|
||||
$data['is_my_order'] = $customer_id === $current_user->ID;
|
||||
$customer_organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||
}
|
||||
|
||||
$customer_organization_info = $order->get_meta('_wiaas_customer_info', true);
|
||||
|
||||
if ( !empty($customer_organization_id) && empty($customer_organization_info) ) {
|
||||
|
||||
$customer_organization_info = wiaas_get_organization_info($customer_organization_id);
|
||||
|
||||
$customer_organization_info['id'] = $customer_organization_id;
|
||||
}
|
||||
|
||||
$data['customer'] = $customer_organization_info;
|
||||
|
||||
$data['is_my_order'] = $customer_user_id === get_current_user_id();
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -290,6 +609,12 @@ class Wiaas_Order {
|
||||
}
|
||||
}
|
||||
|
||||
// installation date
|
||||
if (! empty($item['wiaas_installation_date'])) {
|
||||
|
||||
$product_line['installation_date'] = $item['wiaas_installation_date'];
|
||||
}
|
||||
|
||||
$line_items[] = $product_line;
|
||||
}
|
||||
}
|
||||
@@ -368,11 +693,14 @@ class Wiaas_Order {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data['documents'] = wiaas_get_order_other_documents($order->get_id());
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ 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);
|
||||
|
||||
@@ -45,6 +48,10 @@ class Wiaas_Package {
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function get_earliest_installation_additional_days($package_id){
|
||||
return get_post_meta($package_id, 'additional_days_prior_earliest_installation', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append package documents
|
||||
* @param $data
|
||||
@@ -93,9 +100,8 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_additional_packages($data, $package, $request) {
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
$commercial_lead_id = absint($request['shop_id']);
|
||||
|
||||
$data['additional_packages'] = array();
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
@@ -142,9 +148,8 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_package_prices($data, $package, $request) {
|
||||
// TODO: Change this so commercial lead is sent via request
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = array_keys(wiaas_get_commercial_leads())[0];
|
||||
$commercial_lead_id = absint($request['shop_id']);
|
||||
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||
|
||||
|
||||
@@ -6,17 +6,21 @@ class Wiaas_Product {
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
|
||||
|
||||
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'define_product_capabilities'));
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define capabilities for editing products so we can easily control read/edit/create access for them
|
||||
* 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 mixed
|
||||
* @return array
|
||||
*/
|
||||
public static function define_product_capabilities($args) {
|
||||
public static function manage_product_settings($args) {
|
||||
|
||||
$args['capabilities'] = array(
|
||||
'edit_post' => 'edit_product',
|
||||
@@ -28,8 +32,48 @@ class Wiaas_Product {
|
||||
'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;
|
||||
}
|
||||
|
||||
public static function get_supplier_id($product_id){
|
||||
return wp_get_post_terms($product_id, 'supplier', array('fields' => 'ids'))[0];
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Product::init();
|
||||
@@ -1,5 +1,13 @@
|
||||
<?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() {
|
||||
@@ -10,6 +18,92 @@ class Wiaas_Shop {
|
||||
|
||||
// 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);
|
||||
|
||||
// remove customer shop relationships for all deactivated and removed shops
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -20,7 +114,7 @@ class Wiaas_Shop {
|
||||
'hierarchical' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => false,
|
||||
'public' => true,
|
||||
'public' => false,
|
||||
'capabilities' => array(
|
||||
'manage_terms' => 'manage_wiaas_package_price_terms',
|
||||
'edit_terms' => 'edit_wiaas_package_price_terms',
|
||||
@@ -44,7 +138,7 @@ class Wiaas_Shop {
|
||||
* $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
|
||||
@@ -55,20 +149,66 @@ class Wiaas_Shop {
|
||||
// remove pricing terms for previous prices
|
||||
if (! empty($old_cl_extras)) {
|
||||
|
||||
$old_visible_price_types = array_keys(wp_list_filter($old_cl_extras, array( 'visible' => true )));
|
||||
$old_terms = self::_get_search_terms_from_cl_extras($owner_id, $old_cl_extras);
|
||||
|
||||
$old_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $old_visible_price_types);
|
||||
|
||||
wp_remove_object_terms($package_id, $old_terms_names, '_wiaas_shop_prices');
|
||||
wp_remove_object_terms($package_id, $old_terms, '_wiaas_shop_prices');
|
||||
}
|
||||
|
||||
// get visible price types set by shop owner (commercial lead)
|
||||
$visible_price_types = array_keys(wp_list_filter($cl_extras, array('visible' => true)));
|
||||
|
||||
$new_terms_names = preg_filter('/^/', '_' . $owner_id . '_', $visible_price_types);
|
||||
$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_set_object_terms($package_id, $new_terms_names, '_wiaas_shop_prices');
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class Wiaas_User {
|
||||
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
|
||||
|
||||
add_filter('woocommerce_rest_prepare_customer', array(__CLASS__, 'transform_rest_customer'), 10, 3);
|
||||
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'transform_jwt_token_response'), 10, 2);
|
||||
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'transform_jwt_token_response'), 999, 2);
|
||||
}
|
||||
|
||||
public static function load_user_organization() {
|
||||
@@ -58,6 +58,10 @@ class Wiaas_User {
|
||||
* @return mixed
|
||||
*/
|
||||
public static function transform_jwt_token_response($data, $user) {
|
||||
if (is_wp_error($data)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'token' => $data['token'],
|
||||
'userInfo' => array(
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Wiaas_Validation
|
||||
*/
|
||||
class Wiaas_Validation {
|
||||
|
||||
public static function is_phone($phone){
|
||||
return WC_Validation::is_phone($phone);
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
{"0":{"title":"DELIVERY PROCESS EXAMPLE: Copy and set to active to create new delivery process","description":"","labelPlacement":"top_label","descriptionPlacement":"below","button":{"type":"text","text":"Submit","imageUrl":""},"fields":[{"type":"wiaas_order","id":1,"label":"Order number","adminLabel":"","isRequired":false,"size":"medium","errorMessage":"","visibility":"visible","inputs":null,"formId":36,"description":"","allowsPrepopulate":false,"inputMask":false,"inputMaskValue":"","inputType":"","labelPlacement":"","descriptionPlacement":"","subLabelPlacement":"","placeholder":"","cssClass":"","inputName":"","noDuplicates":false,"defaultValue":"","choices":"","conditionalLogic":"","enableCalculation":false,"numberFormat":"decimal_dot","rangeMin":"","rangeMax":"","productField":"","multipleFiles":false,"maxFiles":"","calculationFormula":"","calculationRounding":"","disableQuantity":false,"displayAllCategories":false,"useRichTextEditor":false,"displayOnly":"","enablePrice":""}],"version":"2.3.2","id":36,"useCurrentUserAsAuthor":true,"postContentTemplateEnabled":false,"postTitleTemplateEnabled":false,"postTitleTemplate":"","postContentTemplate":"","lastPageButton":null,"pagination":null,"firstPageCssClass":null,"wiaas_delivery_process":{"delivery_form_type":"process","delivery_country":"se"},"is_active":"1","date_created":"2018-11-02 10:15:28","is_trash":"0","confirmations":[{"id":"5bdb1c7c26da9","name":"Default Confirmation","isDefault":true,"type":"message","message":"Thanks for contacting us! We will get in touch with you shortly.","url":"","pageId":"","queryString":""}],"notifications":[{"id":"5bdb1c7c26952","to":"{admin_email}","name":"Admin Notification","event":"form_submission","toType":"email","subject":"New submission from {form_title}","message":"{all_fields}"}],"feeds":{"gravityflow":[{"id":"120","form_id":"36","is_active":"1","feed_order":"0","meta":{"step_name":"Delivery Step Placeholder (Use Delivery Step type to create process workflow steps)","description":"","step_type":"wiaas_delivery_step","step_highlight":"0","step_highlight_type":"color","step_highlight_color":"#dd3333","feed_condition_conditional_logic":"0","feed_condition_conditional_logic_object":[],"scheduled":"0","schedule_type":"delay","schedule_date":"","schedule_delay_offset":"","schedule_delay_unit":"hours","schedule_date_field_offset":"0","schedule_date_field_offset_unit":"hours","schedule_date_field_before_after":"after","instructionsEnable":"0","instructionsValue":"","is_visible_to_customer":"1","target_form_id":"","destination_complete":"next"},"addon_slug":"gravityflow","event_type":null}]}},"version":"2.3.2"}
|
||||
@@ -1,524 +0,0 @@
|
||||
{
|
||||
"0": {
|
||||
"title": "DELIVERY ACTION TYPE: Customer acceptance",
|
||||
"description": "The customer must accept the implementation before further actions can be taken. If the customer isn't satisfied, the problems or discrepancies must be fixed in order to gen an acceptance.",
|
||||
"labelPlacement": "top_label",
|
||||
"descriptionPlacement": "below",
|
||||
"button": {
|
||||
"type": "text",
|
||||
"text": "Submit",
|
||||
"imageUrl": ""
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"type": "workflow_user",
|
||||
"id": 2,
|
||||
"label": "customer-id",
|
||||
"adminLabel": "customer-id",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "administrative",
|
||||
"inputs": null,
|
||||
"choices": [
|
||||
],
|
||||
"formId": 1,
|
||||
"description": "",
|
||||
"allowsPrepopulate": true,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "customer-id",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"conditionalLogic": "",
|
||||
"failed_validation": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"enablePrice": "",
|
||||
"gravityflowUsersRoleFilter": ""
|
||||
},
|
||||
{
|
||||
"type": "date",
|
||||
"id": 6,
|
||||
"label": "Actual date",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"dateType": "datepicker",
|
||||
"calendarIconType": "none",
|
||||
"formId": 1,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"calendarIconUrl": "",
|
||||
"dateFormat": "ymd_dash",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": ""
|
||||
},
|
||||
{
|
||||
"type": "radio",
|
||||
"id": 8,
|
||||
"label": "acceptance",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"choices": [
|
||||
{
|
||||
"text": "not-accepted",
|
||||
"value": "not-accepted",
|
||||
"isSelected": true,
|
||||
"price": ""
|
||||
},
|
||||
{
|
||||
"text": "accept",
|
||||
"value": "accept",
|
||||
"isSelected": false,
|
||||
"price": ""
|
||||
},
|
||||
{
|
||||
"text": "decline",
|
||||
"value": "decline",
|
||||
"isSelected": false,
|
||||
"price": ""
|
||||
}
|
||||
],
|
||||
"formId": 1,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"conditionalLogic": "",
|
||||
"productField": "",
|
||||
"enableOtherChoice": "",
|
||||
"enablePrice": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": ""
|
||||
},
|
||||
{
|
||||
"type": "date",
|
||||
"id": 9,
|
||||
"label": "Expiration date",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"dateType": "datepicker",
|
||||
"calendarIconType": "none",
|
||||
"formId": 1,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"calendarIconUrl": "",
|
||||
"dateFormat": "ymd_dash",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": ""
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"id": 10,
|
||||
"label": "Reason",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"formId": 1,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"productField": "",
|
||||
"enablePasswordInput": "",
|
||||
"maxLength": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"enablePrice": ""
|
||||
},
|
||||
{
|
||||
"type": "fileupload",
|
||||
"id": 12,
|
||||
"label": "File",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"formId": 1,
|
||||
"description": "Upload customer acceptance file",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"maxFileSize": "",
|
||||
"maxFiles": "",
|
||||
"multipleFiles": true,
|
||||
"allowedExtensions": "pdf,docx,doc,xlsx,xls,odt,ods,jpg,png,jpeg",
|
||||
"productField": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false
|
||||
}
|
||||
],
|
||||
"version": "2.3.2",
|
||||
"id": 1,
|
||||
"useCurrentUserAsAuthor": true,
|
||||
"postContentTemplateEnabled": false,
|
||||
"postTitleTemplateEnabled": false,
|
||||
"postTitleTemplate": "",
|
||||
"postContentTemplate": "",
|
||||
"lastPageButton": null,
|
||||
"pagination": null,
|
||||
"firstPageCssClass": null,
|
||||
"is_active": "1",
|
||||
"date_created": "2018-08-15 20:30:18",
|
||||
"is_trash": "0",
|
||||
"confirmations": [
|
||||
{
|
||||
"id": "5b5f75f7494b7",
|
||||
"name": "Default Confirmation",
|
||||
"isDefault": true,
|
||||
"type": "message",
|
||||
"message": "Thanks for contacting us! We will get in touch with you shortly.",
|
||||
"url": "",
|
||||
"pageId": "",
|
||||
"queryString": ""
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"id": "5b5f75f748cee",
|
||||
"to": "{admin_email}",
|
||||
"name": "Admin Notification",
|
||||
"event": "form_submission",
|
||||
"toType": "email",
|
||||
"subject": "New submission from {form_title}",
|
||||
"message": "{all_fields}"
|
||||
}
|
||||
],
|
||||
"feeds": {
|
||||
"gravityflow": [
|
||||
{
|
||||
"id": "1",
|
||||
"form_id": "1",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Upload acceptance file",
|
||||
"description": "",
|
||||
"step_type": "user_input",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"schedule_date_field": "6",
|
||||
"type": "select",
|
||||
"assignees": [
|
||||
"role|administrator",
|
||||
"assignee_user_field|2"
|
||||
],
|
||||
"routing": "",
|
||||
"assignee_policy": "any",
|
||||
"highlight_editable_fields_enabled": "0",
|
||||
"highlight_editable_fields_class": "green-triangle",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"display_fields_mode": "selected_fields",
|
||||
"default_status": "hidden",
|
||||
"note_mode": "not_required",
|
||||
"assignee_notification_enabled": "0",
|
||||
"assignee_notification_from_name": "",
|
||||
"assignee_notification_from_email": "{admin_email}",
|
||||
"assignee_notification_reply_to": "",
|
||||
"assignee_notification_bcc": "",
|
||||
"assignee_notification_subject": "Upload order acceptance file",
|
||||
"assignee_notification_message": "A new entry requires your input.",
|
||||
"assignee_notification_disable_autoformat": "0",
|
||||
"resend_assignee_emailEnable": "0",
|
||||
"resend_assignee_emailValue": "7",
|
||||
"resend_assignee_email_repeatEnable": "0",
|
||||
"resend_assignee_email_repeatValue": "3",
|
||||
"in_progress_notification_enabled": "0",
|
||||
"in_progress_notification_type": "select",
|
||||
"in_progress_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"in_progress_notification_from_name": "",
|
||||
"in_progress_notification_from_email": "{admin_email}",
|
||||
"in_progress_notification_reply_to": "",
|
||||
"in_progress_notification_bcc": "",
|
||||
"in_progress_notification_subject": "",
|
||||
"in_progress_notification_message": "Entry {entry_id} has been updated and remains in progress.",
|
||||
"in_progress_notification_disable_autoformat": "0",
|
||||
"complete_notification_enabled": "0",
|
||||
"complete_notification_type": "select",
|
||||
"complete_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"complete_notification_from_name": "",
|
||||
"complete_notification_from_email": "{admin_email}",
|
||||
"complete_notification_reply_to": "",
|
||||
"complete_notification_bcc": "",
|
||||
"complete_notification_subject": "",
|
||||
"complete_notification_message": "Entry {entry_id} has been updated completing the step.",
|
||||
"complete_notification_disable_autoformat": "0",
|
||||
"confirmation_messageEnable": "0",
|
||||
"confirmation_messageValue": "Thank you.",
|
||||
"expiration": "0",
|
||||
"expiration_type": "date_field",
|
||||
"expiration_date": "",
|
||||
"expiration_delay_offset": "7",
|
||||
"expiration_delay_unit": "days",
|
||||
"expiration_date_field_offset": "0",
|
||||
"expiration_date_field_offset_unit": "hours",
|
||||
"expiration_date_field_before_after": "after",
|
||||
"expiration_date_field": "9",
|
||||
"status_expiration": "expired",
|
||||
"destination_expired": "2",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"form_id": "1",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Approve customer acceptance",
|
||||
"description": "",
|
||||
"step_type": "approval",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"type": "select",
|
||||
"assignees": [
|
||||
"role|administrator"
|
||||
],
|
||||
"routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"assignee_policy": "any",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "Instructions: please review the values in the fields below and click on the Approve or Reject button",
|
||||
"display_fields_mode": "all_fields",
|
||||
"assignee_notification_enabled": "0",
|
||||
"assignee_notification_from_name": "",
|
||||
"assignee_notification_from_email": "{admin_email}",
|
||||
"assignee_notification_reply_to": "",
|
||||
"assignee_notification_bcc": "",
|
||||
"assignee_notification_subject": "",
|
||||
"assignee_notification_message": "A new entry is pending your approval. Please check your Workflow Inbox.",
|
||||
"assignee_notification_disable_autoformat": "0",
|
||||
"resend_assignee_emailEnable": "0",
|
||||
"resend_assignee_emailValue": "7",
|
||||
"resend_assignee_email_repeatEnable": "0",
|
||||
"resend_assignee_email_repeatValue": "3",
|
||||
"rejection_notification_enabled": "0",
|
||||
"rejection_notification_type": "select",
|
||||
"rejection_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"rejection_notification_from_name": "",
|
||||
"rejection_notification_from_email": "{admin_email}",
|
||||
"rejection_notification_reply_to": "",
|
||||
"rejection_notification_bcc": "",
|
||||
"rejection_notification_subject": "",
|
||||
"rejection_notification_message": "Entry {entry_id} has been rejected",
|
||||
"rejection_notification_disable_autoformat": "0",
|
||||
"approval_notification_enabled": "0",
|
||||
"approval_notification_type": "select",
|
||||
"approval_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"approval_notification_from_name": "",
|
||||
"approval_notification_from_email": "{admin_email}",
|
||||
"approval_notification_reply_to": "",
|
||||
"approval_notification_bcc": "",
|
||||
"approval_notification_subject": "",
|
||||
"approval_notification_message": "Entry {entry_id} has been approved",
|
||||
"approval_notification_disable_autoformat": "0",
|
||||
"revertEnable": "0",
|
||||
"revertValue": 1,
|
||||
"note_mode": "not_required",
|
||||
"expiration": "0",
|
||||
"expiration_type": "delay",
|
||||
"expiration_date": "",
|
||||
"expiration_delay_offset": "",
|
||||
"expiration_delay_unit": "hours",
|
||||
"expiration_date_field_offset": "0",
|
||||
"expiration_date_field_offset_unit": "hours",
|
||||
"expiration_date_field_before_after": "after",
|
||||
"status_expiration": "rejected",
|
||||
"destination_expired": "next",
|
||||
"destination_rejected": 1,
|
||||
"destination_approved": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "2.3.2"
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
{
|
||||
"0": {
|
||||
"title": "DELIVERY ACTION TYPE: Manual",
|
||||
"description": "Manual process step action type",
|
||||
"labelPlacement": "top_label",
|
||||
"descriptionPlacement": "below",
|
||||
"button": {
|
||||
"type": "text",
|
||||
"text": "Submit",
|
||||
"imageUrl": ""
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"type": "workflow_user",
|
||||
"id": 2,
|
||||
"label": "customer-id",
|
||||
"adminLabel": "customer-id",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "administrative",
|
||||
"inputs": null,
|
||||
"choices": [
|
||||
{
|
||||
"value": 2,
|
||||
"text": "Customer Wiaas"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"text": "wpUser"
|
||||
}
|
||||
],
|
||||
"formId": 4,
|
||||
"description": "",
|
||||
"allowsPrepopulate": true,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "customer-id",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"conditionalLogic": "",
|
||||
"failed_validation": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"enablePrice": "",
|
||||
"gravityflowUsersRoleFilter": ""
|
||||
},
|
||||
{
|
||||
"type": "date",
|
||||
"id": 3,
|
||||
"label": "Actual Date",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"dateType": "datepicker",
|
||||
"calendarIconType": "calendar",
|
||||
"formId": 4,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"calendarIconUrl": "",
|
||||
"dateFormat": "ymd_dash",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": ""
|
||||
}
|
||||
],
|
||||
"version": "2.3.2",
|
||||
"id": 4,
|
||||
"useCurrentUserAsAuthor": true,
|
||||
"postContentTemplateEnabled": false,
|
||||
"postTitleTemplateEnabled": false,
|
||||
"postTitleTemplate": "",
|
||||
"postContentTemplate": "",
|
||||
"lastPageButton": null,
|
||||
"pagination": null,
|
||||
"firstPageCssClass": null,
|
||||
"is_active": "1",
|
||||
"date_created": "2018-08-09 15:36:00",
|
||||
"is_trash": "0",
|
||||
"confirmations": [
|
||||
{
|
||||
"id": "5b5f9ebc52a80",
|
||||
"name": "Default Confirmation",
|
||||
"isDefault": true,
|
||||
"type": "message",
|
||||
"message": "Thanks for contacting us! We will get in touch with you shortly.",
|
||||
"url": "",
|
||||
"pageId": "",
|
||||
"queryString": ""
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"id": "5b5f9ebc520f3",
|
||||
"to": "{admin_email}",
|
||||
"name": "Admin Notification",
|
||||
"event": "form_submission",
|
||||
"toType": "email",
|
||||
"subject": "New submission from {form_title}",
|
||||
"message": "{all_fields}"
|
||||
}
|
||||
],
|
||||
"feeds": {
|
||||
"gravityflow": [
|
||||
{
|
||||
"id": "6",
|
||||
"form_id": "4",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Complete step",
|
||||
"description": "",
|
||||
"step_type": "approval",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"schedule_date_field": "3",
|
||||
"type": "select",
|
||||
"assignees": [
|
||||
"role|administrator"
|
||||
],
|
||||
"routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"assignee_policy": "any",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "Instructions: please review the values in the fields below and click on the Approve or Reject button",
|
||||
"display_fields_mode": "all_fields",
|
||||
"assignee_notification_enabled": "0",
|
||||
"assignee_notification_from_name": "",
|
||||
"assignee_notification_from_email": "{admin_email}",
|
||||
"assignee_notification_reply_to": "",
|
||||
"assignee_notification_bcc": "",
|
||||
"assignee_notification_subject": "",
|
||||
"assignee_notification_message": "A new entry is pending your approval. Please check your Workflow Inbox.",
|
||||
"assignee_notification_disable_autoformat": "0",
|
||||
"resend_assignee_emailEnable": "0",
|
||||
"resend_assignee_emailValue": "7",
|
||||
"resend_assignee_email_repeatEnable": "0",
|
||||
"resend_assignee_email_repeatValue": "3",
|
||||
"rejection_notification_enabled": "0",
|
||||
"rejection_notification_type": "select",
|
||||
"rejection_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"rejection_notification_from_name": "",
|
||||
"rejection_notification_from_email": "{admin_email}",
|
||||
"rejection_notification_reply_to": "",
|
||||
"rejection_notification_bcc": "",
|
||||
"rejection_notification_subject": "",
|
||||
"rejection_notification_message": "Entry {entry_id} has been rejected",
|
||||
"rejection_notification_disable_autoformat": "0",
|
||||
"approval_notification_enabled": "0",
|
||||
"approval_notification_type": "select",
|
||||
"approval_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"approval_notification_from_name": "",
|
||||
"approval_notification_from_email": "{admin_email}",
|
||||
"approval_notification_reply_to": "",
|
||||
"approval_notification_bcc": "",
|
||||
"approval_notification_subject": "",
|
||||
"approval_notification_message": "Entry {entry_id} has been approved",
|
||||
"approval_notification_disable_autoformat": "0",
|
||||
"note_mode": "not_required",
|
||||
"expiration": "0",
|
||||
"expiration_type": "delay",
|
||||
"expiration_date": "",
|
||||
"expiration_delay_offset": "",
|
||||
"expiration_delay_unit": "hours",
|
||||
"expiration_date_field_offset": "0",
|
||||
"expiration_date_field_offset_unit": "hours",
|
||||
"expiration_date_field_before_after": "after",
|
||||
"expiration_date_field": "3",
|
||||
"status_expiration": "rejected",
|
||||
"destination_expired": "next",
|
||||
"destination_rejected": "complete",
|
||||
"destination_approved": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "2.3.2"
|
||||
}
|
||||
@@ -1,406 +0,0 @@
|
||||
{
|
||||
"0": {
|
||||
"title": "DELIVERY ACTION TYPE: Schedule meeting",
|
||||
"description": "Schedule meeting with customer",
|
||||
"labelPlacement": "top_label",
|
||||
"descriptionPlacement": "below",
|
||||
"button": {
|
||||
"type": "text",
|
||||
"text": "Submit",
|
||||
"imageUrl": ""
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"type": "workflow_user",
|
||||
"id": 3,
|
||||
"label": "customer-id",
|
||||
"adminLabel": "customer-id",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "administrative",
|
||||
"inputs": null,
|
||||
"choices": [
|
||||
{
|
||||
"value": 2,
|
||||
"text": "Customer Wiaas"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"text": "wpUser"
|
||||
}
|
||||
],
|
||||
"formId": 2,
|
||||
"description": "",
|
||||
"allowsPrepopulate": true,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "customer-id",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"conditionalLogic": "",
|
||||
"failed_validation": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"gravityflowUsersRoleFilter": ""
|
||||
},
|
||||
{
|
||||
"type": "date",
|
||||
"id": 4,
|
||||
"label": "Actual Date",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"dateType": "datepicker",
|
||||
"calendarIconType": "calendar",
|
||||
"formId": 2,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"calendarIconUrl": "",
|
||||
"dateFormat": "ymd_dash",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": ""
|
||||
},
|
||||
{
|
||||
"type": "date",
|
||||
"id": 5,
|
||||
"label": "Schedule date",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"dateType": "datepicker",
|
||||
"calendarIconType": "calendar",
|
||||
"formId": 2,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"calendarIconUrl": "",
|
||||
"dateFormat": "ymd_dash",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false
|
||||
}
|
||||
],
|
||||
"version": "2.3.2",
|
||||
"id": 2,
|
||||
"useCurrentUserAsAuthor": true,
|
||||
"postContentTemplateEnabled": false,
|
||||
"postTitleTemplateEnabled": false,
|
||||
"postTitleTemplate": "",
|
||||
"postContentTemplate": "",
|
||||
"lastPageButton": null,
|
||||
"pagination": null,
|
||||
"firstPageCssClass": null,
|
||||
"is_active": "1",
|
||||
"date_created": "2018-08-09 15:35:59",
|
||||
"is_trash": "0",
|
||||
"confirmations": [
|
||||
{
|
||||
"id": "5b60b12baa00e",
|
||||
"name": "Default Confirmation",
|
||||
"isDefault": true,
|
||||
"type": "message",
|
||||
"message": "Thanks for contacting us! We will get in touch with you shortly.",
|
||||
"url": "",
|
||||
"pageId": "",
|
||||
"queryString": ""
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"id": "5b60b12ba9850",
|
||||
"to": "{admin_email}",
|
||||
"name": "Admin Notification",
|
||||
"event": "form_submission",
|
||||
"toType": "email",
|
||||
"subject": "New submission from {form_title}",
|
||||
"message": "{all_fields}"
|
||||
}
|
||||
],
|
||||
"feeds": {
|
||||
"gravityflow": [
|
||||
{
|
||||
"id": "3",
|
||||
"form_id": "2",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Broker proposes meeting date",
|
||||
"description": "",
|
||||
"step_type": "user_input",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"schedule_date_field": "4",
|
||||
"type": "select",
|
||||
"assignees": [
|
||||
"role|administrator"
|
||||
],
|
||||
"editable_fields": [
|
||||
"4",
|
||||
"5"
|
||||
],
|
||||
"routing": "",
|
||||
"assignee_policy": "all",
|
||||
"highlight_editable_fields_enabled": "0",
|
||||
"highlight_editable_fields_class": "green-triangle",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"display_fields_mode": "selected_fields",
|
||||
"display_fields_selected": [
|
||||
"4",
|
||||
"5"
|
||||
],
|
||||
"default_status": "submit_buttons",
|
||||
"note_mode": "not_required",
|
||||
"assignee_notification_enabled": "0",
|
||||
"assignee_notification_from_name": "",
|
||||
"assignee_notification_from_email": "{admin_email}",
|
||||
"assignee_notification_reply_to": "",
|
||||
"assignee_notification_bcc": "",
|
||||
"assignee_notification_subject": "",
|
||||
"assignee_notification_message": "A new entry requires your input.",
|
||||
"assignee_notification_disable_autoformat": "0",
|
||||
"resend_assignee_emailEnable": "0",
|
||||
"resend_assignee_emailValue": "7",
|
||||
"resend_assignee_email_repeatEnable": "0",
|
||||
"resend_assignee_email_repeatValue": "3",
|
||||
"in_progress_notification_enabled": "0",
|
||||
"in_progress_notification_type": "select",
|
||||
"in_progress_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"in_progress_notification_from_name": "",
|
||||
"in_progress_notification_from_email": "{admin_email}",
|
||||
"in_progress_notification_reply_to": "",
|
||||
"in_progress_notification_bcc": "",
|
||||
"in_progress_notification_subject": "",
|
||||
"in_progress_notification_message": "Entry {entry_id} has been updated and remains in progress.",
|
||||
"in_progress_notification_disable_autoformat": "0",
|
||||
"complete_notification_enabled": "0",
|
||||
"complete_notification_type": "select",
|
||||
"complete_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"complete_notification_from_name": "",
|
||||
"complete_notification_from_email": "{admin_email}",
|
||||
"complete_notification_reply_to": "",
|
||||
"complete_notification_bcc": "",
|
||||
"complete_notification_subject": "",
|
||||
"complete_notification_message": "Entry {entry_id} has been updated completing the step.",
|
||||
"complete_notification_disable_autoformat": "0",
|
||||
"confirmation_messageEnable": "0",
|
||||
"confirmation_messageValue": "Thank you.",
|
||||
"expiration": "0",
|
||||
"expiration_type": "delay",
|
||||
"expiration_date": "",
|
||||
"expiration_delay_offset": "",
|
||||
"expiration_delay_unit": "hours",
|
||||
"expiration_date_field_offset": "0",
|
||||
"expiration_date_field_offset_unit": "hours",
|
||||
"expiration_date_field_before_after": "after",
|
||||
"expiration_date_field": "4",
|
||||
"status_expiration": "complete",
|
||||
"destination_expired": "next",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "4",
|
||||
"form_id": "2",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Customer approval for scheduled date",
|
||||
"description": "",
|
||||
"step_type": "approval",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"schedule_date_field": "4",
|
||||
"type": "select",
|
||||
"assignees": [
|
||||
"assignee_user_field|3"
|
||||
],
|
||||
"routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"assignee_policy": "all",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "Instructions: please review the values in the fields below and click on the Approve or Reject button",
|
||||
"display_fields_mode": "selected_fields",
|
||||
"display_fields_selected": [
|
||||
"5"
|
||||
],
|
||||
"assignee_notification_enabled": "0",
|
||||
"assignee_notification_from_name": "",
|
||||
"assignee_notification_from_email": "{admin_email}",
|
||||
"assignee_notification_reply_to": "",
|
||||
"assignee_notification_bcc": "",
|
||||
"assignee_notification_subject": "",
|
||||
"assignee_notification_message": "A new entry is pending your approval. Please check your Workflow Inbox.",
|
||||
"assignee_notification_disable_autoformat": "0",
|
||||
"resend_assignee_emailEnable": "0",
|
||||
"resend_assignee_emailValue": "7",
|
||||
"resend_assignee_email_repeatEnable": "0",
|
||||
"resend_assignee_email_repeatValue": "3",
|
||||
"rejection_notification_enabled": "0",
|
||||
"rejection_notification_type": "select",
|
||||
"rejection_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"rejection_notification_from_name": "",
|
||||
"rejection_notification_from_email": "{admin_email}",
|
||||
"rejection_notification_reply_to": "",
|
||||
"rejection_notification_bcc": "",
|
||||
"rejection_notification_subject": "",
|
||||
"rejection_notification_message": "Entry {entry_id} has been rejected",
|
||||
"rejection_notification_disable_autoformat": "0",
|
||||
"approval_notification_enabled": "0",
|
||||
"approval_notification_type": "select",
|
||||
"approval_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"approval_notification_from_name": "",
|
||||
"approval_notification_from_email": "{admin_email}",
|
||||
"approval_notification_reply_to": "",
|
||||
"approval_notification_bcc": "",
|
||||
"approval_notification_subject": "",
|
||||
"approval_notification_message": "Entry {entry_id} has been approved",
|
||||
"approval_notification_disable_autoformat": "0",
|
||||
"revertEnable": "0",
|
||||
"revertValue": 3,
|
||||
"note_mode": "not_required",
|
||||
"expiration": "0",
|
||||
"expiration_type": "delay",
|
||||
"expiration_date": "",
|
||||
"expiration_delay_offset": "",
|
||||
"expiration_delay_unit": "hours",
|
||||
"expiration_date_field_offset": "0",
|
||||
"expiration_date_field_offset_unit": "hours",
|
||||
"expiration_date_field_before_after": "after",
|
||||
"expiration_date_field": "4",
|
||||
"status_expiration": "rejected",
|
||||
"destination_expired": "next",
|
||||
"destination_rejected": 3,
|
||||
"destination_approved": "complete"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "2.3.2"
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
{
|
||||
"0": {
|
||||
"title": "DELIVERY ACTION TYPE: Validate Questionnaire",
|
||||
"description": "The configuration details submitted at ordering must be validated and any missing or incomplete information must be added.",
|
||||
"labelPlacement": "top_label",
|
||||
"descriptionPlacement": "below",
|
||||
"button": {
|
||||
"type": "text",
|
||||
"text": "Submit",
|
||||
"imageUrl": ""
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"type": "workflow_user",
|
||||
"id": 4,
|
||||
"label": "customer-id",
|
||||
"adminLabel": "customer-id",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "administrative",
|
||||
"inputs": null,
|
||||
"choices": [
|
||||
{
|
||||
"value": 2,
|
||||
"text": "Customer Wiaas"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"text": "wpUser"
|
||||
}
|
||||
],
|
||||
"formId": 3,
|
||||
"description": "",
|
||||
"allowsPrepopulate": true,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "customer-id",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"conditionalLogic": "",
|
||||
"failed_validation": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"enablePrice": "",
|
||||
"gravityflowUsersRoleFilter": ""
|
||||
},
|
||||
{
|
||||
"type": "date",
|
||||
"id": 5,
|
||||
"label": "Actual date",
|
||||
"adminLabel": "",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"dateType": "datepicker",
|
||||
"calendarIconType": "none",
|
||||
"formId": 3,
|
||||
"description": "",
|
||||
"allowsPrepopulate": false,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"calendarIconUrl": "",
|
||||
"dateFormat": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false
|
||||
}
|
||||
],
|
||||
"version": "2.3.2",
|
||||
"id": 3,
|
||||
"useCurrentUserAsAuthor": true,
|
||||
"postContentTemplateEnabled": false,
|
||||
"postTitleTemplateEnabled": false,
|
||||
"postTitleTemplate": "",
|
||||
"postContentTemplate": "",
|
||||
"lastPageButton": null,
|
||||
"pagination": null,
|
||||
"firstPageCssClass": null,
|
||||
"is_active": "1",
|
||||
"date_created": "2018-08-09 15:36:00",
|
||||
"is_trash": "0",
|
||||
"confirmations": [
|
||||
{
|
||||
"id": "5b5f688188e90",
|
||||
"name": "Default Confirmation",
|
||||
"isDefault": true,
|
||||
"type": "message",
|
||||
"message": "Thanks for contacting us! We will get in touch with you shortly.",
|
||||
"url": "",
|
||||
"pageId": "",
|
||||
"queryString": ""
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"id": "5b5f68818822e",
|
||||
"to": "{admin_email}",
|
||||
"name": "Admin Notification",
|
||||
"event": "form_submission",
|
||||
"toType": "email",
|
||||
"subject": "New submission from {form_title}",
|
||||
"message": "{all_fields}"
|
||||
}
|
||||
],
|
||||
"feeds": {
|
||||
"gravityflow": [
|
||||
{
|
||||
"id": "5",
|
||||
"form_id": "3",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Approve customer configuration",
|
||||
"description": "",
|
||||
"step_type": "approval",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": {
|
||||
"conditionalLogic": {
|
||||
"actionType": "show",
|
||||
"logicType": "all",
|
||||
"rules": [
|
||||
{
|
||||
"fieldId": "2",
|
||||
"operator": "is",
|
||||
"value": "administrator"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"schedule_date_field": "5",
|
||||
"type": "select",
|
||||
"assignees": [
|
||||
"role|administrator"
|
||||
],
|
||||
"routing": [
|
||||
{
|
||||
"target": false,
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": false,
|
||||
"assignee": "user_id|2"
|
||||
}
|
||||
],
|
||||
"assignee_policy": "any",
|
||||
"instructionsEnable": "1",
|
||||
"instructionsValue": "Instructions: please review the values in the fields below and click on the Approve or Reject button",
|
||||
"display_fields_mode": "selected_fields",
|
||||
"assignee_notification_enabled": "0",
|
||||
"assignee_notification_from_name": "",
|
||||
"assignee_notification_from_email": "{admin_email}",
|
||||
"assignee_notification_reply_to": "",
|
||||
"assignee_notification_bcc": "",
|
||||
"assignee_notification_subject": "",
|
||||
"assignee_notification_message": "A new entry is pending your approval. Please check your Workflow Inbox.",
|
||||
"assignee_notification_disable_autoformat": "0",
|
||||
"resend_assignee_emailEnable": "0",
|
||||
"resend_assignee_emailValue": "7",
|
||||
"resend_assignee_email_repeatEnable": "0",
|
||||
"resend_assignee_email_repeatValue": "3",
|
||||
"rejection_notification_enabled": "0",
|
||||
"rejection_notification_type": "select",
|
||||
"rejection_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"rejection_notification_from_name": "",
|
||||
"rejection_notification_from_email": "{admin_email}",
|
||||
"rejection_notification_reply_to": "",
|
||||
"rejection_notification_bcc": "",
|
||||
"rejection_notification_subject": "",
|
||||
"rejection_notification_message": "Entry {entry_id} has been rejected",
|
||||
"rejection_notification_disable_autoformat": "0",
|
||||
"approval_notification_enabled": "0",
|
||||
"approval_notification_type": "select",
|
||||
"approval_notification_routing": [
|
||||
{
|
||||
"assignee": "user_id|2",
|
||||
"fieldId": "0",
|
||||
"operator": "is",
|
||||
"value": "",
|
||||
"type": ""
|
||||
}
|
||||
],
|
||||
"approval_notification_from_name": "",
|
||||
"approval_notification_from_email": "{admin_email}",
|
||||
"approval_notification_reply_to": "",
|
||||
"approval_notification_bcc": "",
|
||||
"approval_notification_subject": "",
|
||||
"approval_notification_message": "Entry {entry_id} has been approved",
|
||||
"approval_notification_disable_autoformat": "0",
|
||||
"note_mode": "not_required",
|
||||
"expiration": "0",
|
||||
"expiration_type": "delay",
|
||||
"expiration_date": "",
|
||||
"expiration_delay_offset": "",
|
||||
"expiration_delay_unit": "hours",
|
||||
"expiration_date_field_offset": "0",
|
||||
"expiration_date_field_offset_unit": "hours",
|
||||
"expiration_date_field_before_after": "after",
|
||||
"expiration_date_field": "5",
|
||||
"status_expiration": "rejected",
|
||||
"destination_expired": "next",
|
||||
"destination_rejected": "complete",
|
||||
"destination_approved": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "2.3.2"
|
||||
}
|
||||
@@ -1,338 +0,0 @@
|
||||
{
|
||||
"0": {
|
||||
"title": "DELIVERY PROCESS: Normal Delivery",
|
||||
"description": "Normal delivery process",
|
||||
"labelPlacement": "top_label",
|
||||
"descriptionPlacement": "below",
|
||||
"button": {
|
||||
"type": "text",
|
||||
"text": "Submit",
|
||||
"imageUrl": ""
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"type": "number",
|
||||
"id": 1,
|
||||
"label": "order-id",
|
||||
"adminLabel": "order-id",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"numberFormat": "decimal_dot",
|
||||
"formId": 5,
|
||||
"description": "",
|
||||
"allowsPrepopulate": true,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "order-id",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"choices": "",
|
||||
"conditionalLogic": "",
|
||||
"enableCalculation": false,
|
||||
"rangeMin": "",
|
||||
"rangeMax": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"enablePrice": ""
|
||||
},
|
||||
{
|
||||
"type": "workflow_user",
|
||||
"id": 2,
|
||||
"label": "customer-id",
|
||||
"adminLabel": "customer-id",
|
||||
"isRequired": false,
|
||||
"size": "medium",
|
||||
"errorMessage": "",
|
||||
"visibility": "visible",
|
||||
"inputs": null,
|
||||
"choices": [
|
||||
{
|
||||
"value": 2,
|
||||
"text": "Customer Wiaas"
|
||||
},
|
||||
{
|
||||
"value": 1,
|
||||
"text": "wpUser"
|
||||
}
|
||||
],
|
||||
"formId": 5,
|
||||
"description": "",
|
||||
"allowsPrepopulate": true,
|
||||
"inputMask": false,
|
||||
"inputMaskValue": "",
|
||||
"inputType": "",
|
||||
"labelPlacement": "",
|
||||
"descriptionPlacement": "",
|
||||
"subLabelPlacement": "",
|
||||
"placeholder": "",
|
||||
"cssClass": "",
|
||||
"inputName": "customer-id",
|
||||
"noDuplicates": false,
|
||||
"defaultValue": "",
|
||||
"conditionalLogic": "",
|
||||
"failed_validation": "",
|
||||
"productField": "",
|
||||
"multipleFiles": false,
|
||||
"maxFiles": "",
|
||||
"calculationFormula": "",
|
||||
"calculationRounding": "",
|
||||
"enableCalculation": "",
|
||||
"disableQuantity": false,
|
||||
"displayAllCategories": false,
|
||||
"useRichTextEditor": false,
|
||||
"displayOnly": "",
|
||||
"enablePrice": "",
|
||||
"gravityflowUsersRoleFilter": ""
|
||||
}
|
||||
],
|
||||
"version": "2.3.2.6",
|
||||
"id": 5,
|
||||
"useCurrentUserAsAuthor": true,
|
||||
"postContentTemplateEnabled": false,
|
||||
"postTitleTemplateEnabled": false,
|
||||
"postTitleTemplate": "",
|
||||
"postContentTemplate": "",
|
||||
"lastPageButton": null,
|
||||
"pagination": null,
|
||||
"firstPageCssClass": null,
|
||||
"is_active": "1",
|
||||
"date_created": "2018-08-09 15:36:00",
|
||||
"is_trash": "0",
|
||||
"confirmations": [
|
||||
{
|
||||
"id": "5b5f7ae4bb79e",
|
||||
"name": "Default Confirmation",
|
||||
"isDefault": true,
|
||||
"type": "message",
|
||||
"message": "Thanks for contacting us! We will get in touch with you shortly.",
|
||||
"url": "",
|
||||
"pageId": "",
|
||||
"queryString": ""
|
||||
}
|
||||
],
|
||||
"notifications": [
|
||||
{
|
||||
"id": "5b5f7ae4baced",
|
||||
"to": "{admin_email}",
|
||||
"name": "Admin Notification",
|
||||
"event": "form_submission",
|
||||
"toType": "email",
|
||||
"subject": "New submission from {form_title}",
|
||||
"message": "{all_fields}",
|
||||
"isActive": false
|
||||
}
|
||||
],
|
||||
"feeds": {
|
||||
"gravityflow": [
|
||||
{
|
||||
"id": "7",
|
||||
"form_id": "5",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Validate customer configuration information",
|
||||
"description": "Validate customer configuration information",
|
||||
"step_type": "wiaas_delivery_step",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"target_form_id": 3,
|
||||
"store_new_entry_idEnable": "1",
|
||||
"new_entry_id_field": "6",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "8",
|
||||
"form_id": "5",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Wait for installation to be scheduled and confirmed",
|
||||
"description": "Wait for installation to be scheduled and confirmed",
|
||||
"step_type": "wiaas_delivery_step",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"target_form_id": 4,
|
||||
"store_new_entry_idEnable": "0",
|
||||
"new_entry_id_field": "",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "9",
|
||||
"form_id": "5",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Installation",
|
||||
"description": " Installation",
|
||||
"step_type": "wiaas_delivery_step",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"target_form_id": 4,
|
||||
"store_new_entry_idEnable": "0",
|
||||
"new_entry_id_field": "",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "10",
|
||||
"form_id": "5",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Customer acceptance",
|
||||
"description": "Customer acceptance",
|
||||
"step_type": "wiaas_delivery_step",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"target_form_id": 1,
|
||||
"store_new_entry_idEnable": "1",
|
||||
"new_entry_id_field": "7",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "11",
|
||||
"form_id": "5",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Customer training",
|
||||
"description": "Customer training",
|
||||
"step_type": "wiaas_delivery_step",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"target_form_id": 4,
|
||||
"store_new_entry_idEnable": "0",
|
||||
"new_entry_id_field": "",
|
||||
"destination_complete": "next",
|
||||
"feedName": " - Copy 1"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
},
|
||||
{
|
||||
"id": "12",
|
||||
"form_id": "5",
|
||||
"is_active": "1",
|
||||
"feed_order": "0",
|
||||
"meta": {
|
||||
"step_name": "Set start\/stop dates for contracts",
|
||||
"description": "Set start\/stop dates for contracts",
|
||||
"step_type": "wiaas_delivery_step",
|
||||
"step_highlight": "0",
|
||||
"step_highlight_type": "color",
|
||||
"step_highlight_color": "#dd3333",
|
||||
"feed_condition_conditional_logic": "0",
|
||||
"feed_condition_conditional_logic_object": [],
|
||||
"scheduled": "0",
|
||||
"schedule_type": "delay",
|
||||
"schedule_date": "",
|
||||
"schedule_delay_offset": "",
|
||||
"schedule_delay_unit": "hours",
|
||||
"schedule_date_field_offset": "0",
|
||||
"schedule_date_field_offset_unit": "hours",
|
||||
"schedule_date_field_before_after": "after",
|
||||
"instructionsEnable": "0",
|
||||
"instructionsValue": "",
|
||||
"target_form_id": 4,
|
||||
"store_new_entry_idEnable": "0",
|
||||
"new_entry_id_field": "",
|
||||
"destination_complete": "next"
|
||||
},
|
||||
"addon_slug": "gravityflow",
|
||||
"event_type": null
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"version": "2.3.2"
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bc845c001de4",
|
||||
"title": "Bundle Properties",
|
||||
"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
|
||||
},
|
||||
{
|
||||
"key": "field_5bcfcc2cf88f4",
|
||||
"label": "Country",
|
||||
"name": "country",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"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
|
||||
},
|
||||
{
|
||||
"key": "field_5bdb1512ab14f",
|
||||
"label": "Additional days prior earliest installation",
|
||||
"name": "additional_days_prior_earliest_installation",
|
||||
"type": "number",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": 5,
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"min": 0,
|
||||
"max": "",
|
||||
"step": ""
|
||||
},
|
||||
{
|
||||
"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
|
||||
}
|
||||
],
|
||||
"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": ""
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,501 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bdad38fcebee",
|
||||
"title": "Country settings",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bdad398384e1",
|
||||
"label": "Code",
|
||||
"name": "_wiaas_country_code",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"ax": "ax - Åland Islands",
|
||||
"af": "af - Afghanistan",
|
||||
"al": "al - Albania",
|
||||
"dz": "dz - Algeria",
|
||||
"as": "as - American Samoa",
|
||||
"ad": "ad - Andorra",
|
||||
"ao": "ao - Angola",
|
||||
"ai": "ai - Anguilla",
|
||||
"aq": "aq - Antarctica",
|
||||
"ag": "ag - Antigua and Barbuda",
|
||||
"ar": "ar - Argentina",
|
||||
"am": "am - Armenia",
|
||||
"aw": "aw - Aruba",
|
||||
"au": "au - Australia",
|
||||
"at": "at - Austria",
|
||||
"az": "az - Azerbaijan",
|
||||
"bs": "bs - Bahamas",
|
||||
"bh": "bh - Bahrain",
|
||||
"bd": "bd - Bangladesh",
|
||||
"bb": "bb - Barbados",
|
||||
"by": "by - Belarus",
|
||||
"pw": "pw - Belau",
|
||||
"be": "be - Belgium",
|
||||
"bz": "bz - Belize",
|
||||
"bj": "bj - Benin",
|
||||
"bm": "bm - Bermuda",
|
||||
"bt": "bt - Bhutan",
|
||||
"bo": "bo - Bolivia",
|
||||
"bq": "bq - Bonaire, Saint Eustatius and Saba",
|
||||
"ba": "ba - Bosnia and Herzegovina",
|
||||
"bw": "bw - Botswana",
|
||||
"bv": "bv - Bouvet Island",
|
||||
"br": "br - Brazil",
|
||||
"io": "io - British Indian Ocean Territory",
|
||||
"vg": "vg - British Virgin Islands",
|
||||
"bn": "bn - Brunei",
|
||||
"bg": "bg - Bulgaria",
|
||||
"bf": "bf - Burkina Faso",
|
||||
"bi": "bi - Burundi",
|
||||
"kh": "kh - Cambodia",
|
||||
"cm": "cm - Cameroon",
|
||||
"ca": "ca - Canada",
|
||||
"cv": "cv - Cape Verde",
|
||||
"ky": "ky - Cayman Islands",
|
||||
"cf": "cf - Central African Republic",
|
||||
"td": "td - Chad",
|
||||
"cl": "cl - Chile",
|
||||
"cn": "cn - China",
|
||||
"cx": "cx - Christmas Island",
|
||||
"cc": "cc - Cocos (Keeling) Islands",
|
||||
"co": "co - Colombia",
|
||||
"km": "km - Comoros",
|
||||
"cg": "cg - Congo (Brazzaville)",
|
||||
"cd": "cd - Congo (Kinshasa)",
|
||||
"ck": "ck - Cook Islands",
|
||||
"cr": "cr - Costa Rica",
|
||||
"hr": "hr - Croatia",
|
||||
"cu": "cu - Cuba",
|
||||
"cw": "cw - Curaçao",
|
||||
"cy": "cy - Cyprus",
|
||||
"cz": "cz - Czech Republic",
|
||||
"dk": "dk - Denmark",
|
||||
"dj": "dj - Djibouti",
|
||||
"dm": "dm - Dominica",
|
||||
"do": "do - Dominican Republic",
|
||||
"ec": "ec - Ecuador",
|
||||
"eg": "eg - Egypt",
|
||||
"sv": "sv - El Salvador",
|
||||
"gq": "gq - Equatorial Guinea",
|
||||
"er": "er - Eritrea",
|
||||
"ee": "ee - Estonia",
|
||||
"et": "et - Ethiopia",
|
||||
"fk": "fk - Falkland Islands",
|
||||
"fo": "fo - Faroe Islands",
|
||||
"fj": "fj - Fiji",
|
||||
"fi": "fi - Finland",
|
||||
"fr": "fr - France",
|
||||
"gf": "gf - French Guiana",
|
||||
"pf": "pf - French Polynesia",
|
||||
"tf": "tf - French Southern Territories",
|
||||
"ga": "ga - Gabon",
|
||||
"gm": "gm - Gambia",
|
||||
"ge": "ge - Georgia",
|
||||
"de": "de - Germany",
|
||||
"gh": "gh - Ghana",
|
||||
"gi": "gi - Gibraltar",
|
||||
"gr": "gr - Greece",
|
||||
"gl": "gl - Greenland",
|
||||
"gd": "gd - Grenada",
|
||||
"gp": "gp - Guadeloupe",
|
||||
"gu": "gu - Guam",
|
||||
"gt": "gt - Guatemala",
|
||||
"gg": "gg - Guernsey",
|
||||
"gn": "gn - Guinea",
|
||||
"gw": "gw - Guinea-Bissau",
|
||||
"gy": "gy - Guyana",
|
||||
"ht": "ht - Haiti",
|
||||
"hm": "hm - Heard Island and McDonald Islands",
|
||||
"hn": "hn - Honduras",
|
||||
"hk": "hk - Hong Kong",
|
||||
"hu": "hu - Hungary",
|
||||
"is": "is - Iceland",
|
||||
"in": "in - India",
|
||||
"id": "id - Indonesia",
|
||||
"ir": "ir - Iran",
|
||||
"iq": "iq - Iraq",
|
||||
"ie": "ie - Ireland",
|
||||
"im": "im - Isle of Man",
|
||||
"il": "il - Israel",
|
||||
"it": "it - Italy",
|
||||
"ci": "ci - Ivory Coast",
|
||||
"jm": "jm - Jamaica",
|
||||
"jp": "jp - Japan",
|
||||
"je": "je - Jersey",
|
||||
"jo": "jo - Jordan",
|
||||
"kz": "kz - Kazakhstan",
|
||||
"ke": "ke - Kenya",
|
||||
"ki": "ki - Kiribati",
|
||||
"kw": "kw - Kuwait",
|
||||
"kg": "kg - Kyrgyzstan",
|
||||
"la": "la - Laos",
|
||||
"lv": "lv - Latvia",
|
||||
"lb": "lb - Lebanon",
|
||||
"ls": "ls - Lesotho",
|
||||
"lr": "lr - Liberia",
|
||||
"ly": "ly - Libya",
|
||||
"li": "li - Liechtenstein",
|
||||
"lt": "lt - Lithuania",
|
||||
"lu": "lu - Luxembourg",
|
||||
"mo": "mo - Macao S.A.R., China",
|
||||
"mk": "mk - Macedonia",
|
||||
"mg": "mg - Madagascar",
|
||||
"mw": "mw - Malawi",
|
||||
"my": "my - Malaysia",
|
||||
"mv": "mv - Maldives",
|
||||
"ml": "ml - Mali",
|
||||
"mt": "mt - Malta",
|
||||
"mh": "mh - Marshall Islands",
|
||||
"mq": "mq - Martinique",
|
||||
"mr": "mr - Mauritania",
|
||||
"mu": "mu - Mauritius",
|
||||
"yt": "yt - Mayotte",
|
||||
"mx": "mx - Mexico",
|
||||
"fm": "fm - Micronesia",
|
||||
"md": "md - Moldova",
|
||||
"mc": "mc - Monaco",
|
||||
"mn": "mn - Mongolia",
|
||||
"me": "me - Montenegro",
|
||||
"ms": "ms - Montserrat",
|
||||
"ma": "ma - Morocco",
|
||||
"mz": "mz - Mozambique",
|
||||
"mm": "mm - Myanmar",
|
||||
"na": "na - Namibia",
|
||||
"nr": "nr - Nauru",
|
||||
"np": "np - Nepal",
|
||||
"nl": "nl - Netherlands",
|
||||
"nc": "nc - New Caledonia",
|
||||
"nz": "nz - New Zealand",
|
||||
"ni": "ni - Nicaragua",
|
||||
"ne": "ne - Niger",
|
||||
"ng": "ng - Nigeria",
|
||||
"nu": "nu - Niue",
|
||||
"nf": "nf - Norfolk Island",
|
||||
"kp": "kp - North Korea",
|
||||
"mp": "mp - Northern Mariana Islands",
|
||||
"no": "no - Norway",
|
||||
"om": "om - Oman",
|
||||
"pk": "pk - Pakistan",
|
||||
"ps": "ps - Palestinian Territory",
|
||||
"pa": "pa - Panama",
|
||||
"pg": "pg - Papua New Guinea",
|
||||
"py": "py - Paraguay",
|
||||
"pe": "pe - Peru",
|
||||
"ph": "ph - Philippines",
|
||||
"pn": "pn - Pitcairn",
|
||||
"pl": "pl - Poland",
|
||||
"pt": "pt - Portugal",
|
||||
"pr": "pr - Puerto Rico",
|
||||
"qa": "qa - Qatar",
|
||||
"re": "re - Reunion",
|
||||
"ro": "ro - Romania",
|
||||
"ru": "ru - Russia",
|
||||
"rw": "rw - Rwanda",
|
||||
"st": "st - São Tomé and Príncipe",
|
||||
"bl": "bl - Saint Barthélemy",
|
||||
"sh": "sh - Saint Helena",
|
||||
"kn": "kn - Saint Kitts and Nevis",
|
||||
"lc": "lc - Saint Lucia",
|
||||
"sx": "sx - Saint Martin (Dutch part)",
|
||||
"mf": "mf - Saint Martin (French part)",
|
||||
"pm": "pm - Saint Pierre and Miquelon",
|
||||
"vc": "vc - Saint Vincent and the Grenadines",
|
||||
"ws": "ws - Samoa",
|
||||
"sm": "sm - San Marino",
|
||||
"sa": "sa - Saudi Arabia",
|
||||
"sn": "sn - Senegal",
|
||||
"rs": "rs - Serbia",
|
||||
"sc": "sc - Seychelles",
|
||||
"sl": "sl - Sierra Leone",
|
||||
"sg": "sg - Singapore",
|
||||
"sk": "sk - Slovakia",
|
||||
"si": "si - Slovenia",
|
||||
"sb": "sb - Solomon Islands",
|
||||
"so": "so - Somalia",
|
||||
"za": "za - South Africa",
|
||||
"gs": "gs - South Georgia\/Sandwich Islands",
|
||||
"kr": "kr - South Korea",
|
||||
"ss": "ss - South Sudan",
|
||||
"es": "es - Spain",
|
||||
"lk": "lk - Sri Lanka",
|
||||
"sd": "sd - Sudan",
|
||||
"sr": "sr - Suriname",
|
||||
"sj": "sj - Svalbard and Jan Mayen",
|
||||
"sz": "sz - Swaziland",
|
||||
"se": "se - Sweden",
|
||||
"ch": "ch - Switzerland",
|
||||
"sy": "sy - Syria",
|
||||
"tw": "tw - Taiwan",
|
||||
"tj": "tj - Tajikistan",
|
||||
"tz": "tz - Tanzania",
|
||||
"th": "th - Thailand",
|
||||
"tl": "tl - Timor-Leste",
|
||||
"tg": "tg - Togo",
|
||||
"tk": "tk - Tokelau",
|
||||
"to": "to - Tonga",
|
||||
"tt": "tt - Trinidad and Tobago",
|
||||
"tn": "tn - Tunisia",
|
||||
"tr": "tr - Turkey",
|
||||
"tm": "tm - Turkmenistan",
|
||||
"tc": "tc - Turks and Caicos Islands",
|
||||
"tv": "tv - Tuvalu",
|
||||
"ug": "ug - Uganda",
|
||||
"ua": "ua - Ukraine",
|
||||
"ae": "ae - United Arab Emirates",
|
||||
"gb": "gb - United Kingdom (UK)",
|
||||
"us": "us - United States (US)",
|
||||
"um": "um - United States (US) Minor Outlying Islands",
|
||||
"vi": "vi - United States (US) Virgin Islands",
|
||||
"uy": "uy - Uruguay",
|
||||
"uz": "uz - Uzbekistan",
|
||||
"vu": "vu - Vanuatu",
|
||||
"va": "va - Vatican",
|
||||
"ve": "ve - Venezuela",
|
||||
"vn": "vn - Vietnam",
|
||||
"wf": "wf - Wallis and Futuna",
|
||||
"eh": "eh - Western Sahara",
|
||||
"ye": "ye - Yemen",
|
||||
"zm": "zm - Zambia",
|
||||
"zw": "zw - Zimbabwe"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 0,
|
||||
"ui": 1,
|
||||
"ajax": 0,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bfc4b4fa5992",
|
||||
"label": "Currency",
|
||||
"name": "_wiaas_country_currency",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"AED": "United Arab Emirates dirham",
|
||||
"AFN": "Afghan afghani",
|
||||
"ALL": "Albanian lek",
|
||||
"AMD": "Armenian dram",
|
||||
"ANG": "Netherlands Antillean guilder",
|
||||
"AOA": "Angolan kwanza",
|
||||
"ARS": "Argentine peso",
|
||||
"AUD": "Australian dollar",
|
||||
"AWG": "Aruban florin",
|
||||
"AZN": "Azerbaijani manat",
|
||||
"BAM": "Bosnia and Herzegovina convertible mark",
|
||||
"BBD": "Barbadian dollar",
|
||||
"BDT": "Bangladeshi taka",
|
||||
"BGN": "Bulgarian lev",
|
||||
"BHD": "Bahraini dinar",
|
||||
"BIF": "Burundian franc",
|
||||
"BMD": "Bermudian dollar",
|
||||
"BND": "Brunei dollar",
|
||||
"BOB": "Bolivian boliviano",
|
||||
"BRL": "Brazilian real",
|
||||
"BSD": "Bahamian dollar",
|
||||
"BTC": "Bitcoin",
|
||||
"BTN": "Bhutanese ngultrum",
|
||||
"BWP": "Botswana pula",
|
||||
"BYR": "Belarusian ruble (old)",
|
||||
"BYN": "Belarusian ruble",
|
||||
"BZD": "Belize dollar",
|
||||
"CAD": "Canadian dollar",
|
||||
"CDF": "Congolese franc",
|
||||
"CHF": "Swiss franc",
|
||||
"CLP": "Chilean peso",
|
||||
"CNY": "Chinese yuan",
|
||||
"COP": "Colombian peso",
|
||||
"CRC": "Costa Rican colón",
|
||||
"CUC": "Cuban convertible peso",
|
||||
"CUP": "Cuban peso",
|
||||
"CVE": "Cape Verdean escudo",
|
||||
"CZK": "Czech koruna",
|
||||
"DJF": "Djiboutian franc",
|
||||
"DKK": "Danish krone",
|
||||
"DOP": "Dominican peso",
|
||||
"DZD": "Algerian dinar",
|
||||
"EGP": "Egyptian pound",
|
||||
"ERN": "Eritrean nakfa",
|
||||
"ETB": "Ethiopian birr",
|
||||
"EUR": "Euro",
|
||||
"FJD": "Fijian dollar",
|
||||
"FKP": "Falkland Islands pound",
|
||||
"GBP": "Pound sterling",
|
||||
"GEL": "Georgian lari",
|
||||
"GGP": "Guernsey pound",
|
||||
"GHS": "Ghana cedi",
|
||||
"GIP": "Gibraltar pound",
|
||||
"GMD": "Gambian dalasi",
|
||||
"GNF": "Guinean franc",
|
||||
"GTQ": "Guatemalan quetzal",
|
||||
"GYD": "Guyanese dollar",
|
||||
"HKD": "Hong Kong dollar",
|
||||
"HNL": "Honduran lempira",
|
||||
"HRK": "Croatian kuna",
|
||||
"HTG": "Haitian gourde",
|
||||
"HUF": "Hungarian forint",
|
||||
"IDR": "Indonesian rupiah",
|
||||
"ILS": "Israeli new shekel",
|
||||
"IMP": "Manx pound",
|
||||
"INR": "Indian rupee",
|
||||
"IQD": "Iraqi dinar",
|
||||
"IRR": "Iranian rial",
|
||||
"IRT": "Iranian toman",
|
||||
"ISK": "Icelandic króna",
|
||||
"JEP": "Jersey pound",
|
||||
"JMD": "Jamaican dollar",
|
||||
"JOD": "Jordanian dinar",
|
||||
"JPY": "Japanese yen",
|
||||
"KES": "Kenyan shilling",
|
||||
"KGS": "Kyrgyzstani som",
|
||||
"KHR": "Cambodian riel",
|
||||
"KMF": "Comorian franc",
|
||||
"KPW": "North Korean won",
|
||||
"KRW": "South Korean won",
|
||||
"KWD": "Kuwaiti dinar",
|
||||
"KYD": "Cayman Islands dollar",
|
||||
"KZT": "Kazakhstani tenge",
|
||||
"LAK": "Lao kip",
|
||||
"LBP": "Lebanese pound",
|
||||
"LKR": "Sri Lankan rupee",
|
||||
"LRD": "Liberian dollar",
|
||||
"LSL": "Lesotho loti",
|
||||
"LYD": "Libyan dinar",
|
||||
"MAD": "Moroccan dirham",
|
||||
"MDL": "Moldovan leu",
|
||||
"MGA": "Malagasy ariary",
|
||||
"MKD": "Macedonian denar",
|
||||
"MMK": "Burmese kyat",
|
||||
"MNT": "Mongolian tögrög",
|
||||
"MOP": "Macanese pataca",
|
||||
"MRO": "Mauritanian ouguiya",
|
||||
"MUR": "Mauritian rupee",
|
||||
"MVR": "Maldivian rufiyaa",
|
||||
"MWK": "Malawian kwacha",
|
||||
"MXN": "Mexican peso",
|
||||
"MYR": "Malaysian ringgit",
|
||||
"MZN": "Mozambican metical",
|
||||
"NAD": "Namibian dollar",
|
||||
"NGN": "Nigerian naira",
|
||||
"NIO": "Nicaraguan córdoba",
|
||||
"NOK": "Norwegian krone",
|
||||
"NPR": "Nepalese rupee",
|
||||
"NZD": "New Zealand dollar",
|
||||
"OMR": "Omani rial",
|
||||
"PAB": "Panamanian balboa",
|
||||
"PEN": "Peruvian nuevo sol",
|
||||
"PGK": "Papua New Guinean kina",
|
||||
"PHP": "Philippine peso",
|
||||
"PKR": "Pakistani rupee",
|
||||
"PLN": "Polish złoty",
|
||||
"PRB": "Transnistrian ruble",
|
||||
"PYG": "Paraguayan guaraní",
|
||||
"QAR": "Qatari riyal",
|
||||
"RON": "Romanian leu",
|
||||
"RSD": "Serbian dinar",
|
||||
"RUB": "Russian ruble",
|
||||
"RWF": "Rwandan franc",
|
||||
"SAR": "Saudi riyal",
|
||||
"SBD": "Solomon Islands dollar",
|
||||
"SCR": "Seychellois rupee",
|
||||
"SDG": "Sudanese pound",
|
||||
"SEK": "Swedish krona",
|
||||
"SGD": "Singapore dollar",
|
||||
"SHP": "Saint Helena pound",
|
||||
"SLL": "Sierra Leonean leone",
|
||||
"SOS": "Somali shilling",
|
||||
"SRD": "Surinamese dollar",
|
||||
"SSP": "South Sudanese pound",
|
||||
"STD": "São Tomé and Príncipe dobra",
|
||||
"SYP": "Syrian pound",
|
||||
"SZL": "Swazi lilangeni",
|
||||
"THB": "Thai baht",
|
||||
"TJS": "Tajikistani somoni",
|
||||
"TMT": "Turkmenistan manat",
|
||||
"TND": "Tunisian dinar",
|
||||
"TOP": "Tongan paʻanga",
|
||||
"TRY": "Turkish lira",
|
||||
"TTD": "Trinidad and Tobago dollar",
|
||||
"TWD": "New Taiwan dollar",
|
||||
"TZS": "Tanzanian shilling",
|
||||
"UAH": "Ukrainian hryvnia",
|
||||
"UGX": "Ugandan shilling",
|
||||
"USD": "United States (US) dollar",
|
||||
"UYU": "Uruguayan peso",
|
||||
"UZS": "Uzbekistani som",
|
||||
"VEF": "Venezuelan bolívar",
|
||||
"VND": "Vietnamese đồng",
|
||||
"VUV": "Vanuatu vatu",
|
||||
"WST": "Samoan tālā",
|
||||
"XAF": "Central African CFA franc",
|
||||
"XCD": "East Caribbean dollar",
|
||||
"XOF": "West African CFA franc",
|
||||
"XPF": "CFP franc",
|
||||
"YER": "Yemeni rial",
|
||||
"ZAR": "South African rand",
|
||||
"ZMW": "Zambian kwacha"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 0,
|
||||
"ui": 1,
|
||||
"ajax": 0,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bfc4b00ff8ad",
|
||||
"label": "VAT",
|
||||
"name": "_wiaas_country_vat",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "taxonomy",
|
||||
"operator": "==",
|
||||
"value": "product_country"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "side",
|
||||
"style": "default",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,103 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbf694106e34",
|
||||
"title": "General",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bceef4c9771c",
|
||||
"label": "General",
|
||||
"name": "_wiaas_product_general",
|
||||
"type": "group",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"layout": "block",
|
||||
"sub_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": 1,
|
||||
"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": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "label",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
@@ -65,8 +65,38 @@
|
||||
"multiple": 1,
|
||||
"ui": 1,
|
||||
"ajax": 1,
|
||||
"return_format": "label",
|
||||
"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": [
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
[
|
||||
{
|
||||
"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": "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
|
||||
},
|
||||
{
|
||||
"key": "field_5bcfcceffe617",
|
||||
"label": "Country",
|
||||
"name": "country",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"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_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": ""
|
||||
}
|
||||
]
|
||||
@@ -6,14 +6,6 @@
|
||||
* General functions for updating wiaas database to latest version
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Enable restricting visibility by user roles for products
|
||||
*/
|
||||
function wiaas_db_update_enable_product_by_user_role() {
|
||||
update_option('wcj_product_by_user_role_enabled', 'yes');
|
||||
}
|
||||
|
||||
function wiaas_db_update_setup_gravity() {
|
||||
// Gravity Form settings
|
||||
update_option('gform_pending_installation', false);
|
||||
@@ -25,59 +17,6 @@ function wiaas_db_update_setup_gravity() {
|
||||
update_option('gravityflow_pending_installation', false);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_delivery_process_forms() {
|
||||
$action_type_forms_files = array(
|
||||
'delivery_action_customer_acceptance_form',
|
||||
'delivery_action_schedule_meeting',
|
||||
'delivery_action_validate_questionnaire_form',
|
||||
'delivery_action_manual_form',
|
||||
);
|
||||
|
||||
// Since import action will generate form with new id, we need to remember this mapping
|
||||
// so we can update process delivery steps to point to correct form ids
|
||||
$action_type_forms_ids_mappings = array();
|
||||
|
||||
$process_forms_files = array(
|
||||
'delivery_process_normal_delivery_form'
|
||||
);
|
||||
|
||||
$created_forms = array();
|
||||
|
||||
// import forms for delivery action types
|
||||
foreach ($action_type_forms_files as $action_type_form_file) {
|
||||
$form_json = file_get_contents( dirname( __FILE__ ) . "/data/delivery-forms/" . $action_type_form_file . '.json' );
|
||||
|
||||
$form_meta = json_decode( $form_json, true );
|
||||
$form_meta = $form_meta[0];
|
||||
|
||||
$form_id = GFAPI::add_form($form_meta);
|
||||
|
||||
$created_forms[] = GFAPI::get_form($form_id);
|
||||
|
||||
$action_type_forms_ids_mappings[$form_meta['id']] = $form_id;
|
||||
}
|
||||
|
||||
// import forms for delivery process
|
||||
foreach ($process_forms_files as $process_form_file) {
|
||||
$form_json = file_get_contents( dirname( __FILE__ ) . "/data/delivery-forms/" . $process_form_file . '.json' );
|
||||
|
||||
$form_meta = json_decode( $form_json, true );
|
||||
$form_meta = $form_meta[0];
|
||||
|
||||
// update delivery steps forms ids with correct values
|
||||
foreach ($form_meta['feeds']['gravityflow'] as $key => $process_step_meta) {
|
||||
$process_step_target_form_id = $form_meta['feeds']['gravityflow'][$key]['meta']['target_form_id'];
|
||||
$form_meta['feeds']['gravityflow'][$key]['meta']['target_form_id'] = $action_type_forms_ids_mappings[$process_step_target_form_id];
|
||||
}
|
||||
|
||||
$form_id = GFAPI::add_form($form_meta);
|
||||
|
||||
$created_forms[] = GFAPI::get_form($form_id);
|
||||
}
|
||||
|
||||
do_action('gform_forms_post_import', $created_forms);
|
||||
}
|
||||
|
||||
function wiaas_db_update_enable_orders_access_management() {
|
||||
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
||||
|
||||
@@ -88,26 +27,10 @@ function wiaas_db_update_enable_orders_access_management() {
|
||||
Groups_Options::update_option(Groups_Post_Access::POST_TYPES, $post_types_option);
|
||||
}
|
||||
|
||||
function wiaas_db_update_enable_order_numbers() {
|
||||
update_option('wcj_order_numbers_enabled', 'yes');
|
||||
update_option('wcj_order_number_sequential_enabled', 'no');
|
||||
update_option('wcj_order_number_counter', '0');
|
||||
update_option('wcj_order_number_counter_reset_enabled', 'no');
|
||||
update_option('wcj_order_number_prefix', '1000000');
|
||||
}
|
||||
|
||||
function wiaas_create_broker_access_group() {
|
||||
Groups_Group::create(array(
|
||||
'name' => 'Broker',
|
||||
));
|
||||
}
|
||||
|
||||
function wiaas_db_setup_exclusive_taxonomies() {
|
||||
update_option('radio_button_for_taxonomies_options', array(
|
||||
'taxonomies' => array(
|
||||
'product_cat',
|
||||
'product_country',
|
||||
'wiaas_document_types',
|
||||
'shop_order_project',
|
||||
),
|
||||
'delete' => 0,
|
||||
));
|
||||
@@ -125,4 +48,186 @@ function wiaas_db_setup_customer_capabilities() {
|
||||
$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_create_organization_roles_capabilities() {
|
||||
$roles = array( 'commercial_lead', 'supplier', 'customer', 'administrator');
|
||||
foreach ($roles as $role) {
|
||||
Groups_Capability::create( array( 'capability' => 'wiaas_' . $role ));
|
||||
}
|
||||
}
|
||||
|
||||
function wiaas_disable_processing_order_email_delivery() {
|
||||
update_option( 'woocommerce_customer_processing_order_settings', array(
|
||||
'enabled' => 'no',
|
||||
'subject' => '',
|
||||
'heading' => '',
|
||||
'mail_type' => 'html'
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
function wiaas_db_update_update_delivery_forms() {
|
||||
|
||||
$forms = GFAPI::get_forms();
|
||||
foreach ($forms as $form) {
|
||||
RGFormsModel::update_form_active($form['id'], false);
|
||||
}
|
||||
|
||||
$created_forms = array();
|
||||
|
||||
$actions_forms_json = file_get_contents( dirname( __FILE__ ) . '/data/delivery-forms/delivery-action-forms.json' );
|
||||
|
||||
$action_forms_meta = json_decode( $actions_forms_json, true );
|
||||
|
||||
foreach ($action_forms_meta as $action_form_meta) {
|
||||
|
||||
$form_id = GFAPI::add_form($action_form_meta);
|
||||
$created_forms[] = GFAPI::get_form($form_id);
|
||||
}
|
||||
|
||||
|
||||
$sample_form_json = file_get_contents( dirname( __FILE__ ) . '/data/delivery-forms/delivery-process-sample-form.json' );
|
||||
|
||||
$sample_form = json_decode( $sample_form_json, true );
|
||||
|
||||
$sample_form = $sample_form[0];
|
||||
|
||||
$sample_form_id = GFAPI::add_form($sample_form);
|
||||
|
||||
RGFormsModel::update_form_active($sample_form_id, false);
|
||||
|
||||
$created_forms[] = GFAPI::get_form($sample_form_id);
|
||||
|
||||
do_action('gform_forms_post_import', $created_forms);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_installation_date_delivery_action_form() {
|
||||
|
||||
$action_form_json = file_get_contents( dirname( __FILE__ ) . '/data/delivery-forms/delivery-action-enter-installation-date.json' );
|
||||
|
||||
$action_form_meta = json_decode( $action_form_json, true )[0];
|
||||
|
||||
$action_form_id = GFAPI::add_form($action_form_meta);
|
||||
|
||||
do_action('gform_forms_post_import', array( GFAPI::get_form($action_form_id) ));
|
||||
}
|
||||
|
||||
// TODO: Remove after migration has been completed
|
||||
function wiaas_db_migration_fix_user_profile_addresses() {
|
||||
|
||||
$users = get_users();
|
||||
|
||||
foreach ($users as $user) {
|
||||
|
||||
$billing_addresses = Wiaas_Customer::get_customer_billing_addresses($user->ID);
|
||||
|
||||
if (! empty($billing_addresses)) {
|
||||
|
||||
foreach ($billing_addresses as $index => $billing_address) {
|
||||
|
||||
switch ($billing_address['id_country_selected']) {
|
||||
|
||||
case 1:
|
||||
$billing_address['country_code'] = 'se';
|
||||
break;
|
||||
case 2:
|
||||
$billing_address['country_code'] = 'dk';
|
||||
break;
|
||||
case 3:
|
||||
$billing_address['country_code'] = 'fi';
|
||||
break;
|
||||
}
|
||||
unset($billing_address['id_country_selected']);
|
||||
$billing_addresses[$index] = $billing_address;
|
||||
}
|
||||
|
||||
update_user_meta( $user->ID, 'billing_addresses', $billing_addresses);
|
||||
}
|
||||
|
||||
$profile_addresses = Wiaas_Customer::get_customer_profile_addresses($user->ID);
|
||||
|
||||
if (! empty($profile_addresses)) {
|
||||
|
||||
foreach ($profile_addresses as $index => $profile_address) {
|
||||
|
||||
switch ($profile_address['id_country_selected']) {
|
||||
|
||||
case 1:
|
||||
$profile_address['country_code'] = 'se';
|
||||
break;
|
||||
case 2:
|
||||
$profile_address['country_code'] = 'dk';
|
||||
break;
|
||||
case 3:
|
||||
$profile_address['country_code'] = 'fi';
|
||||
break;
|
||||
}
|
||||
unset($profile_address['id_country_selected']);
|
||||
$profile_addresses[$index] = $profile_address;
|
||||
}
|
||||
|
||||
update_user_meta( $user->ID, 'profile_addresses', $profile_addresses);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove after migration has been completed
|
||||
function wiaas_db_migration_fix_countries() {
|
||||
|
||||
$available_country_terms = get_terms(array(
|
||||
'taxonomy' => 'product_country',
|
||||
'hide_empty' => false,
|
||||
));
|
||||
|
||||
foreach($available_country_terms as $country_term) {
|
||||
|
||||
$code = ''; $currency = ''; $vat = '';
|
||||
|
||||
switch ($country_term->name) {
|
||||
|
||||
case 'Sweden':
|
||||
$code = 'se';
|
||||
$currency = 'SEK';
|
||||
$vat = 9;
|
||||
break;
|
||||
case 'Denmark':
|
||||
$code = 'dk';
|
||||
$currency = 'DKK';
|
||||
$vat = 9;
|
||||
break;
|
||||
case 'Finland':
|
||||
$code = 'fi';
|
||||
$currency = 'EUR';
|
||||
$vat = 9;
|
||||
break;
|
||||
}
|
||||
|
||||
update_term_meta($country_term->term_id, '_wiaas_country_code', $code);
|
||||
update_term_meta($country_term->term_id, '_wiaas_country_currency', $currency);
|
||||
update_term_meta($country_term->term_id, '_wiaas_country_vat', $vat);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,140 +10,288 @@
|
||||
|
||||
|
||||
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'
|
||||
);
|
||||
$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 wordpress default roles
|
||||
remove_role('author');
|
||||
remove_role('contributor');
|
||||
remove_role('editor');
|
||||
remove_role('subscriber');
|
||||
|
||||
// remove woocoommerce shop manager role
|
||||
remove_role('shop_manager');
|
||||
// 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' );
|
||||
// Dummy gettext calls to get strings in the catalog.
|
||||
/* translators: user role */
|
||||
_x( 'Supplier', 'User role', 'wiaas' );
|
||||
/* translators: user role */
|
||||
_x( 'Commercial Lead', 'User role', 'wiaas' );
|
||||
|
||||
// Add wiaas roles
|
||||
add_role(
|
||||
'commercial_lead',
|
||||
'Commercial Lead',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
// Add wiaas roles
|
||||
add_role(
|
||||
'commercial_lead',
|
||||
'Commercial Lead',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'supplier',
|
||||
'Supplier',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
add_role(
|
||||
'supplier',
|
||||
'Supplier',
|
||||
array(
|
||||
'read' => true,
|
||||
)
|
||||
);
|
||||
|
||||
add_role(
|
||||
'user',
|
||||
'User',
|
||||
array(
|
||||
'read' => true
|
||||
)
|
||||
);
|
||||
add_role(
|
||||
'user',
|
||||
'User',
|
||||
array(
|
||||
'read' => true
|
||||
)
|
||||
);
|
||||
|
||||
// set default wiaas role
|
||||
update_option('default_role', 'user');
|
||||
// set default wiaas role
|
||||
update_option('default_role', 'user');
|
||||
|
||||
// capabilities
|
||||
// capabilities
|
||||
|
||||
$capabilities = array();
|
||||
$capabilities = array();
|
||||
|
||||
$capability_types = array( 'wiaas_doc' );
|
||||
$capability_types = array( 'wiaas_doc' );
|
||||
|
||||
foreach ( $capability_types as $capability_type ) {
|
||||
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",
|
||||
$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",
|
||||
);
|
||||
}
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
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' );
|
||||
// update role settings that are imported
|
||||
$content = file_get_contents( dirname( __FILE__ ) . '/data/aam-settings.json' );
|
||||
|
||||
$importer = new AAM_Core_Importer($content);
|
||||
$importer = new AAM_Core_Importer($content);
|
||||
|
||||
$importer->run();
|
||||
$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',
|
||||
)
|
||||
);
|
||||
// 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',
|
||||
)
|
||||
);
|
||||
|
||||
update_option('aam_menu_default', array (
|
||||
'menu-edit.php' => '1',
|
||||
'edit.php' => '1',
|
||||
'post-new.php' => '1',
|
||||
'edit-tags.php?taxonomy=category' => '1',
|
||||
'edit-tags.php?taxonomy=post_tag' => '1',
|
||||
'menu-edit.php?post_type=page' => '1',
|
||||
'edit.php?post_type=page' => '1',
|
||||
'post-new.php?post_type=page' => '1',
|
||||
'menu-woocommerce' => '1',
|
||||
'woocommerce' => '1',
|
||||
'edit.php?post_type=shop_coupon' => '1',
|
||||
'edit-tags.php?taxonomy=shop_order_project' => '1',
|
||||
'wc-reports' => '1',
|
||||
'wc-settings' => '1',
|
||||
'wc-status' => '1',
|
||||
'wc-addons' => '1',
|
||||
'wcj-tools' => '1',
|
||||
'admin.php?page=wc-settings&tab=jetpack' => '1',
|
||||
'menu-themes.php' => '1',
|
||||
'themes.php' => '1',
|
||||
'customize.php' => '1',
|
||||
'widgets.php' => '1',
|
||||
'nav-menus.php' => '1',
|
||||
'custom-header' => '1',
|
||||
'menu-tools.php' => '1',
|
||||
'tools.php' => '1',
|
||||
'import.php' => '1',
|
||||
'export.php' => '1',
|
||||
'export_personal_data' => '1',
|
||||
'remove_personal_data' => '1',
|
||||
'menu-options-general.php' => '1',
|
||||
'options-general.php' => '1',
|
||||
'options-writing.php' => '1',
|
||||
'options-reading.php' => '1',
|
||||
'options-discussion.php' => '1',
|
||||
'options-media.php' => '1',
|
||||
'options-permalink.php' => '1',
|
||||
'privacy.php' => '1',
|
||||
'radio-buttons-for-taxonomies' => '1',
|
||||
'sendgrid-settings' => '1',
|
||||
'menu-plugins.php' => '1',
|
||||
'plugins.php' => '1',
|
||||
'plugin-install.php' => '1',
|
||||
'menu-groups-admin' => '1',
|
||||
'groups-admin' => '1',
|
||||
'groups-admin-capabilities' => '1',
|
||||
'groups-admin-options' => '1',
|
||||
'groups-admin-add-ons' => '1',
|
||||
)
|
||||
);
|
||||
|
||||
update_option('aam-utilities', array(
|
||||
'core.settings.getStarted' => '0',
|
||||
'ui.settings.renderAccessActionLink' => '0',
|
||||
'core.settings.secureLogin' => '0',
|
||||
'core.settings.xmlrpc' => '0',
|
||||
'core.settings.cron' => '0',
|
||||
'core.settings.extensionSupport' => '0',
|
||||
'ui.settings.renderAccessMetabox' => '0',
|
||||
'core.settings.apiAccessControl' => '0',
|
||||
'core.settings.frontendAccessControl' => '0',
|
||||
|
||||
));
|
||||
|
||||
update_option('aam_menu_role_administrator', array(
|
||||
'menu-edit.php' => '1',
|
||||
'edit.php' => '1',
|
||||
'post-new.php' => '1',
|
||||
'edit-tags.php?taxonomy=category' => '1',
|
||||
'edit-tags.php?taxonomy=post_tag' => '1',
|
||||
'menu-edit.php?post_type=page' => '1',
|
||||
'edit.php?post_type=page' => '1',
|
||||
'post-new.php?post_type=page' => '1',
|
||||
'menu-woocommerce' => '1',
|
||||
'woocommerce' => '1',
|
||||
'edit.php?post_type=shop_coupon' => '1',
|
||||
'wc-reports' => '1',
|
||||
'wc-settings' => '1',
|
||||
'wc-status' => '1',
|
||||
'wc-addons' => '1',
|
||||
'wcj-tools' => '1',
|
||||
'admin.php?page=wc-settings&tab=jetpack' => '1',
|
||||
'menu-themes.php' => '1',
|
||||
'themes.php' => '1',
|
||||
'customize.php' => '1',
|
||||
'widgets.php' => '1',
|
||||
'nav-menus.php' => '1',
|
||||
'custom-header' => '1',
|
||||
'menu-tools.php' => '1',
|
||||
'tools.php' => '1',
|
||||
'import.php' => '1',
|
||||
'export.php' => '1',
|
||||
'export_personal_data' => '1',
|
||||
'remove_personal_data' => '1',
|
||||
'menu-options-general.php' => '1',
|
||||
'options-general.php' => '1',
|
||||
'options-writing.php' => '1',
|
||||
'options-reading.php' => '1',
|
||||
'options-discussion.php' => '1',
|
||||
'options-media.php' => '1',
|
||||
'options-permalink.php' => '1',
|
||||
'privacy.php' => '1',
|
||||
'radio-buttons-for-taxonomies' => '1',
|
||||
'sendgrid-settings' => '1',
|
||||
'menu-plugins.php' => '1',
|
||||
'plugins.php' => '1',
|
||||
'plugin-install.php' => '1',
|
||||
'menu-groups-admin' => '1',
|
||||
'groups-admin' => '1',
|
||||
'groups-admin-capabilities' => '1',
|
||||
'groups-admin-options' => '1',
|
||||
'groups-admin-add-ons' => '1',
|
||||
'menu-edit-comments.php' => '1',
|
||||
));
|
||||
|
||||
update_option('aam_metabox_default', array(
|
||||
'dashboard' =>
|
||||
array (
|
||||
'rg_forms_dashboard' => '1',
|
||||
'dashboard_quick_press' => '1',
|
||||
'dashboard_primary' => '1',
|
||||
'woocommerce_dashboard_status' => '1',
|
||||
'dashboard_activity' => '1',
|
||||
),
|
||||
));
|
||||
|
||||
update_option('aam_metabox_role_administrator', array(
|
||||
'dashboard' =>
|
||||
array (
|
||||
'rg_forms_dashboard' => '1',
|
||||
'dashboard_quick_press' => '1',
|
||||
'dashboard_primary' => '1',
|
||||
'woocommerce_dashboard_status' => '1',
|
||||
'dashboard_activity' => '1',
|
||||
'dashboard_right_now' => '1',
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
function wiaas_db_update_update_commercial_lead_capabilities() {
|
||||
// add commercial lead specific roles
|
||||
wp_roles()->add_cap( 'commercial_lead', 'manage_wiaas_cl_products' );
|
||||
|
||||
wp_roles()->add_cap( 'commercial_lead', 'view_admin_dashboard' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'read' );
|
||||
wp_roles()->add_cap( 'commercial_lead', 'upload_files' );
|
||||
|
||||
// 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() {
|
||||
@@ -154,23 +302,25 @@ function wiaas_db_update_update_supplier_capabilities() {
|
||||
|
||||
function wiaas_db_update_update_admin_capabilities() {
|
||||
wp_roles()->add_cap( 'administrator', 'create_products' );
|
||||
wp_roles()->add_cap( 'administrator', 'manage_wiaas_order_projects' );
|
||||
}
|
||||
|
||||
|
||||
function wiaas_create_role_access_groups() {
|
||||
function wiaas_admin_create_role_access_groups() {
|
||||
Groups_Group::create(array(
|
||||
'name' => 'admin',
|
||||
));
|
||||
}
|
||||
|
||||
Groups_Group::create(array(
|
||||
'name' => 'commercial_lead',
|
||||
));
|
||||
function wiaas_db_update_update_supplier_order_capabilities() {
|
||||
// add supplier role to view orders
|
||||
wp_roles()->add_cap( 'supplier', 'edit_shop_orders' );
|
||||
}
|
||||
|
||||
Groups_Group::create(array(
|
||||
'name' => 'supplier',
|
||||
));
|
||||
function wiaas_db_update_enable_workflow_inbox_for_roles() {
|
||||
// add workflow inbox for supplier
|
||||
wp_roles()->add_cap( 'supplier', 'gravityflow_inbox' );
|
||||
// add workflow inbox for commercial lead
|
||||
wp_roles()->add_cap( 'commercial_lead', 'gravityflow_inbox' );
|
||||
|
||||
Groups_Group::create(array(
|
||||
'name' => 'customer',
|
||||
));
|
||||
}
|
||||
@@ -6,7 +6,7 @@ function wiaas_db_update_add_organization_info_ui_fields() {
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_user_organization_ui_fields() {
|
||||
@@ -15,5 +15,124 @@ function wiaas_db_update_add_user_organization_ui_fields() {
|
||||
|
||||
$ui_json = json_decode( $ui_json, true );
|
||||
|
||||
acf_import_field_group($ui_json[0]);
|
||||
}
|
||||
_wiaas_import_field_group($ui_json);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_bundle_properties_ui_field() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-bundle-properties.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);
|
||||
}
|
||||
|
||||
function wiaas_db_update_add_country_settings_ui_fields() {
|
||||
|
||||
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-country-settings.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 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
173
backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php
Normal file
173
backend/app/plugins/wiaas/includes/db/class-wiaas-shop-db.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?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' => absint($result_row->shop_owner_id),
|
||||
'order_type' => $result_row->order_type
|
||||
);
|
||||
}, $results);
|
||||
|
||||
return $shops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove shop
|
||||
*
|
||||
* @param int $owner_id
|
||||
*/
|
||||
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 )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Delivery_Process_Action
|
||||
*/
|
||||
class Wiaas_Delivery_Process_Action {
|
||||
|
||||
/**
|
||||
* Check if form is delivery process action form
|
||||
*
|
||||
* @param $form
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_action_form($form) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve action form for step
|
||||
*
|
||||
* @param Wiaas_Delivery_Process_Step $step
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public static function get_process_step_action_form($step) {
|
||||
|
||||
if (empty($step->target_form_id)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return GFAPI::get_form($step->target_form_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action code for delivery process step form
|
||||
*
|
||||
* Action code is used for implementing specific logic for step form
|
||||
*
|
||||
* @param Wiaas_Delivery_Process_Step $step
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_process_step_action_form_action_code($step) {
|
||||
|
||||
$action_form = self::get_process_step_action_form($step);
|
||||
|
||||
if (empty($action_form)) {
|
||||
|
||||
return 'manual';
|
||||
}
|
||||
|
||||
$delivery_settings = rgar($action_form, 'wiaas_delivery_process');
|
||||
|
||||
return empty($delivery_settings) ? 'manual' : $delivery_settings['delivery_action_code'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if delivery process step has customer acceptance action form
|
||||
*
|
||||
* @param Wiaas_Delivery_Process_Step $step
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function process_step_has_customer_acceptance_action($step) {
|
||||
|
||||
return self::get_process_step_action_form_action_code($step) === 'customer-acceptance';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if delivery process step has customer validate action form
|
||||
*
|
||||
* @param Wiaas_Delivery_Process_Step $step
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function process_step_has_customer_validate_questionnaires_action($step) {
|
||||
|
||||
return self::get_process_step_action_form_action_code($step) === 'validate-questionnaire';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Wiaas_Delivery_Process_Step $step
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public static function get_process_step_action_entries(Wiaas_Delivery_Process_Step $step) {
|
||||
|
||||
$action_form = self::get_process_step_action_form($step);
|
||||
|
||||
if (!$action_form) {
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
$search_criteria = array(
|
||||
'field_filters' => array(
|
||||
array( 'key' => 'wiaas_delivery_process_id',
|
||||
'value' => $step->get_entry_id()
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$sorting = array( 'key' => 'date_created', 'direction' => 'DESC' );
|
||||
|
||||
return GFAPI::get_entries( $action_form, $search_criteria, $sorting );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve forms that will be used as possible action forms
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_action_forms() {
|
||||
|
||||
$forms = GFAPI::get_forms();
|
||||
|
||||
$action_forms = array();
|
||||
|
||||
foreach ( $forms as $form ) {
|
||||
|
||||
$delivery_settings = rgar($form, 'wiaas_delivery_process');
|
||||
|
||||
if ( ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action'){
|
||||
|
||||
$action_forms[] = $form;
|
||||
}
|
||||
}
|
||||
|
||||
return $action_forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete current workflow step for action form
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
*/
|
||||
public static function complete_action_step($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$workflow = new Gravity_Flow_API($action_form['id']);
|
||||
|
||||
$current_step = $workflow->get_current_step($action_entry);
|
||||
|
||||
if ( $current_step ) {
|
||||
|
||||
$new_status = $current_step->get_type() === 'approval' ? 'approved' : 'complete';
|
||||
|
||||
$assignees = $current_step->get_assignees();
|
||||
|
||||
foreach ($assignees as $assignee) {
|
||||
|
||||
$current_step->process_assignee_status($assignee, $new_status, $action_form);
|
||||
}
|
||||
}
|
||||
|
||||
gravity_flow()->process_workflow($action_form, $action_entry['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload customer questionnaire document
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
*/
|
||||
public static function upload_customer_questionnaire($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
|
||||
$document_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'wiaas_order_bundle_document')[0];
|
||||
|
||||
|
||||
$new_file = $document_field->get_single_file_value($action_entry['form_id'], 'file');
|
||||
|
||||
$action_entry[$document_field->id] = $new_file;
|
||||
|
||||
GFAPI::update_entry($action_entry);
|
||||
|
||||
self::complete_action_step($action_entry_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if customer uploaded acceptance document
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_customer_acceptance_uploaded($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
|
||||
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_document')[0];
|
||||
|
||||
return ! empty( $action_entry[$acceptance_documents_field->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update acceptance status for order
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
* @param $new_status
|
||||
* @param $reason
|
||||
*/
|
||||
public static function update_customer_acceptance_status($action_entry_id, $new_status, $reason) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
|
||||
$decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
|
||||
|
||||
$action_entry[$acceptance_field->id] = $new_status;
|
||||
$action_entry[$decline_reason_field->id] = $reason;
|
||||
|
||||
GFAPI::update_entry($action_entry);
|
||||
|
||||
if ($new_status === 'accept') {
|
||||
|
||||
Wiaas_Delivery_Process_Action::complete_action_step($action_entry['id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload customer acceptance document for order
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function upload_customer_acceptance_document($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_document')[0];
|
||||
|
||||
$old_value = $action_entry[$acceptance_documents_field->id];
|
||||
|
||||
$value = $acceptance_documents_field->get_single_file_value($action_form['id'], 'file');
|
||||
|
||||
if ($acceptance_documents_field->multipleFiles ) {
|
||||
|
||||
$value = array( $value );
|
||||
|
||||
$old_value = json_decode( $old_value );
|
||||
|
||||
if (! empty($old_value)) {
|
||||
|
||||
$old_value = is_array( $old_value ) ? $old_value : array( $old_value );
|
||||
|
||||
$value = array_merge( $value, $old_value );
|
||||
}
|
||||
|
||||
$value = json_encode( $value );
|
||||
}
|
||||
|
||||
$action_entry[$acceptance_documents_field->id] = $value;
|
||||
|
||||
$result = GFAPI::update_entry($action_entry);
|
||||
|
||||
// complete step if current step is customer acceptance user input
|
||||
$workflow = new Gravity_Flow_API($action_form['id']);
|
||||
$current_step = $workflow->get_current_step($action_entry);
|
||||
|
||||
if ($current_step->get_type() === 'user_input' && ! is_wp_error($result)) {
|
||||
|
||||
Wiaas_Delivery_Process_Action::complete_action_step($action_entry['id']);
|
||||
}
|
||||
|
||||
return ! is_wp_error($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect customer acceptance action data
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_customer_acceptance_action_data($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
|
||||
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_document')[0];
|
||||
$acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
|
||||
$decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
|
||||
$expiration_date_field = GFCommon::get_fields_by_type($action_form, 'date')[0];
|
||||
|
||||
$file_paths = json_decode($action_entry[$acceptance_documents_field->id]);
|
||||
|
||||
$documents = array();
|
||||
|
||||
foreach ($file_paths as $file_path) {
|
||||
|
||||
$info = pathinfo( $file_path );
|
||||
|
||||
$documents[] = array(
|
||||
'name' => $info['basename'],
|
||||
'extension' => $info['extension'],
|
||||
'url' => $acceptance_documents_field->get_download_url( $file_path, true )
|
||||
);
|
||||
}
|
||||
|
||||
$status = 0;
|
||||
if ($action_entry[$acceptance_field->id] === 'accept') {
|
||||
$status = 1;
|
||||
}
|
||||
|
||||
if ($action_entry[$acceptance_field->id] === 'decline') {
|
||||
$status = -1;
|
||||
}
|
||||
|
||||
return array(
|
||||
'action_id' => $action_entry['id'],
|
||||
'documents' => $documents,
|
||||
'expiration' => $action_entry[$expiration_date_field->id],
|
||||
'decline_reason' => $action_entry[$decline_reason_field->id],
|
||||
'status' => $status
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customer validate questionnaires action data
|
||||
*
|
||||
* @param int $action_entry_id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_customer_validate_questionnaires_action_data($action_entry_id) {
|
||||
|
||||
$action_entry = GFAPI::get_entry($action_entry_id);
|
||||
|
||||
$action_form = GFAPI::get_form($action_entry['form_id']);
|
||||
|
||||
$order_id = $action_entry['wiaas_delivery_order_id'];
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
|
||||
// we need to collect document, bundle id and current status
|
||||
$bundle_item_id = null; $status = null;
|
||||
|
||||
$bundle_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle')[0];
|
||||
$bundle_item_id = absint(explode('|', $action_entry[$bundle_field->id])[1]);
|
||||
|
||||
if (empty($bundle_item_id)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$document_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle_document')[0];
|
||||
$file_path = $action_entry[$document_field->id];
|
||||
|
||||
$info = pathinfo( $action_entry[$document_field->id] );
|
||||
|
||||
$document = array(
|
||||
'name' => $info['basename'],
|
||||
'extension' => $info['extension'],
|
||||
'url' => $document_field->get_download_url( $file_path, true )
|
||||
);
|
||||
|
||||
$discussion_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'workflow_discussion')[0];
|
||||
$discussion_items = json_decode($action_entry[$discussion_field->id], ARRAY_A);
|
||||
|
||||
$formatted_comments = array();
|
||||
|
||||
if (is_array($discussion_items)) {
|
||||
foreach ($discussion_items as $item) {
|
||||
|
||||
$formatted = $discussion_field->format_discussion_item( $item, 'text', $action_entry_id );
|
||||
$formatted = explode("\n", $formatted);
|
||||
|
||||
$formatted_comments[] = array(
|
||||
'header' => $formatted[0],
|
||||
'value' => $formatted[1]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$action_workflow_api = new Gravity_Flow_API($action_form['id']);
|
||||
$action_step = $action_workflow_api->get_current_step($action_entry);
|
||||
|
||||
|
||||
// if completed it means that document got validated
|
||||
$status = 'validated';
|
||||
|
||||
if (! empty($action_step)) {
|
||||
|
||||
$is_assignee = $action_step->is_assignee($action_step->get_current_assignee_key());
|
||||
|
||||
if ($is_assignee) {
|
||||
// if customer is assignee it means it is his turn to upload changed version of document
|
||||
// which means it was rejected
|
||||
$status = 'invalid';
|
||||
} else {
|
||||
// if customer is not assignee it means administrator is still reviewing document
|
||||
$status = 'not-validated';
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'item_id' => $bundle_item_id,
|
||||
'order_id' =>$order->get_id(),
|
||||
'action_id' => $action_entry['id'],
|
||||
'document' => $document,
|
||||
'status' => $status,
|
||||
'comments' => $formatted_comments
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
|
||||
if (! class_exists( 'GFForms' ) ) {
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
|
||||
|
||||
private static $_instance = null;
|
||||
|
||||
protected $_slug = 'wiaas_delivery_process';
|
||||
|
||||
protected $_title = 'Delivery Settings';
|
||||
|
||||
protected $_short_title = 'Delivery Settings';
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if ( self::$_instance == null ) {
|
||||
self::$_instance = new Wiaas_Delivery_Process_Addon();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function init() {
|
||||
|
||||
parent::init();
|
||||
|
||||
add_filter( 'gform_enqueue_scripts', array( $this, 'filter_gform_enqueue_scripts' ) );
|
||||
}
|
||||
|
||||
public function filter_gform_enqueue_scripts( ) {
|
||||
|
||||
wp_enqueue_script( 'gform_datepicker_init' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
|
||||
*
|
||||
* @param array $entry_meta
|
||||
* @param int $form_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_entry_meta( $entry_meta, $form_id ) {
|
||||
$entry_meta[ 'wiaas_delivery_process_id' ] = array(
|
||||
'label' => 'Wiaas Delivery Process Id',
|
||||
'is_numeric' => true,
|
||||
'update_entry_meta_callback' => array( __CLASS__, 'update_entry_delivery_process_id' ),
|
||||
'is_default_column' => false, // this column will be displayed by default on the entry list
|
||||
'filter' => array(
|
||||
'operators' => array( 'is' ),
|
||||
),
|
||||
);
|
||||
|
||||
$entry_meta[ 'wiaas_delivery_order_id' ] = array(
|
||||
'label' => 'Wiaas Delivery Process Order Id',
|
||||
'is_numeric' => true,
|
||||
'update_entry_meta_callback' => null,
|
||||
'is_default_column' => false, // this column will be displayed by default on the entry list
|
||||
'filter' => array(
|
||||
'operators' => array( 'is' ),
|
||||
),
|
||||
);
|
||||
|
||||
$entry_meta[ 'wiaas_delivery_step_name' ] = array(
|
||||
'label' => 'Wiaas Delivery Step name',
|
||||
'is_numeric' => false,
|
||||
'update_entry_meta_callback' => null,
|
||||
'is_default_column' => false, // this column will be displayed by default on the entry list
|
||||
'filter' => array(
|
||||
'operators' => array( 'is' ),
|
||||
),
|
||||
);
|
||||
|
||||
return $entry_meta;
|
||||
}
|
||||
|
||||
public static function update_entry_delivery_process_id($key, $entry, $form) {
|
||||
|
||||
if ( isset( $_REQUEST['wiaas_delivery_process_id'] ) ) {
|
||||
return absint( $_REQUEST['wiaas_delivery_process_id'] );
|
||||
}
|
||||
|
||||
if ( isset( $entry[ $key ] ) ) {
|
||||
return $entry[ $key ];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
public function scripts() {
|
||||
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
$scripts = array(
|
||||
|
||||
array(
|
||||
'handle' => 'wiaas_form_editor_js',
|
||||
'src' => $plugin_url . '/assets/js/wiaas-form-editor.js',
|
||||
'enqueue' => array(
|
||||
array(
|
||||
'admin_page' => array('form_editor'),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return array_merge( parent::scripts(), $scripts );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add settings menu for form delivery process
|
||||
*
|
||||
* @param $tabs
|
||||
* @param $form_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_form_settings_menu( $tabs, $form_id ) {
|
||||
|
||||
$tabs[] = array(
|
||||
'name' => $this->_slug,
|
||||
'label' => esc_html__( 'Delivery Settings', 'wiaas' ),
|
||||
'query' => array( 'fid' => null )
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add settings field for delivery process settings menu
|
||||
*
|
||||
* @param $form
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function form_settings_fields($form) {
|
||||
|
||||
return array(
|
||||
|
||||
array(
|
||||
'title' => esc_html__( 'Delivery Process', 'wiaas' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'delivery_process',
|
||||
'label' => esc_html__( 'Delivery Form Type', 'wiaas' ),
|
||||
'type' => 'delivery_process',
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function settings_delivery_process() {
|
||||
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_form_type',
|
||||
'choices' => array(
|
||||
array( 'value' => 'process', 'label' => 'Process Form' ),
|
||||
array( 'value' => 'action', 'label' => 'Action Form' ),
|
||||
),
|
||||
'after_select' => '<p class="description"> Choose if this form will be used as process form or action form.</p>' .
|
||||
'<p class="description"> <strong>Process form</strong> defines order delivery process workflow.</p>' .
|
||||
'<p class="description"> <strong>Action form</strong> defines custom order data that is collected from delivery process participants.</p>'
|
||||
));
|
||||
|
||||
|
||||
?>
|
||||
<br /> <br /> <br />
|
||||
<?php
|
||||
|
||||
|
||||
$settings = $this->get_current_settings();
|
||||
|
||||
if ($settings['delivery_form_type'] !== 'process') {
|
||||
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_action_code',
|
||||
'choices' => array(
|
||||
array( 'value' => '', 'label' => 'Select action code ...' ),
|
||||
array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
|
||||
array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
|
||||
array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' ),
|
||||
),
|
||||
'after_select' => '<p class="description"> Choose action code for action form.</p>'
|
||||
));
|
||||
|
||||
|
||||
$this->settings_checkbox_and_select(array(
|
||||
'checkbox' => array(
|
||||
'label' => esc_html__( 'Automatic', 'wiaas' ),
|
||||
'name' => 'automatic_action_entries_enabled',
|
||||
'default_value' => '0',
|
||||
),
|
||||
'select' => array(
|
||||
'name' => 'automatic_action_entries_type',
|
||||
'choices' => array(
|
||||
array(
|
||||
'value' => 'single',
|
||||
'label' => esc_html__( 'Single entry', 'wiaas' ),
|
||||
),
|
||||
array(
|
||||
'value' => 'bundle',
|
||||
'label' => esc_html__( 'Entry per bundle', 'wiaas' ),
|
||||
)
|
||||
),
|
||||
'after_select' => '<p class="description">Automatic entries can be created once per order or per every bundle in order.</p>' .
|
||||
'<p class="description">Automatic entry will not be created if any required field cannot be populated.</p>',
|
||||
)
|
||||
));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$countries = Wiaas_Countries::get_available_countries();
|
||||
|
||||
$countries_choices = array();
|
||||
foreach ($countries as $country) {
|
||||
$countries_choices[] = array( 'value' => $country['code'] , 'label' => $country['name'] );
|
||||
}
|
||||
|
||||
$this->settings_select(array(
|
||||
'name' => 'delivery_country',
|
||||
'choices' => $countries_choices,
|
||||
'after_select' => '<p class="description"> Choose country for which this process is defined.</p>'
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handle organization and order level assignment to delivery process step.
|
||||
*
|
||||
* Currently Gravity Flow enables assignment of roles to step, but these roles are not bounded to organization level
|
||||
* so cannot be used in that form for our delivery processes.
|
||||
*
|
||||
* This will enable delivery process step to be assigned to order admin, order seller, order customer or
|
||||
* single order supplier organization.
|
||||
*
|
||||
*
|
||||
* Class Wiaas_Delivery_Process_Step_Assignee
|
||||
*/
|
||||
|
||||
class Wiaas_Delivery_Process_Step_Assignee {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('gravityflow_assignee_choices', array (__CLASS__, 'filter_delivery_process_step_assignee_choices'));
|
||||
|
||||
add_filter('gravityflow_step_assignees', array (__CLASS__, 'maybe_handle_order_organization_assignees'), 10, 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow only order specific organization roles and fields as choices for delivery process step assignee
|
||||
*
|
||||
* @param array $old_choices
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_delivery_process_step_assignee_choices($old_choices) {
|
||||
|
||||
$choices = array(
|
||||
$choices[] = array(
|
||||
'label' => __( 'Order', 'wiaas' ),
|
||||
'choices' => array(
|
||||
array(
|
||||
'value' => 'role|administrator', // allow global administrator role here since it is only one
|
||||
'label' => __('Administrator', 'wiaas')
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// add administrator users
|
||||
$args = array(
|
||||
'number' => 1000,
|
||||
'orderby' => 'display_name',
|
||||
'role' => 'administrator'
|
||||
);
|
||||
$accounts = get_users( $args );
|
||||
$account_choices = array();
|
||||
foreach ( $accounts as $account ) {
|
||||
$account_choices[] = array( 'value' => 'user_id|' . $account->ID, 'label' => $account->display_name );
|
||||
}
|
||||
|
||||
$choices[] = array(
|
||||
'label' => __( 'Users', 'gravityflow' ),
|
||||
'choices' => $account_choices,
|
||||
);
|
||||
|
||||
// append field choices
|
||||
foreach ($old_choices as $old_choice) {
|
||||
|
||||
if ($old_choice['label'] === 'Fields') {
|
||||
|
||||
$choices[] = $old_choice;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle order level assignees for delivery process step
|
||||
*
|
||||
* @param $assignees
|
||||
*
|
||||
* @param Gravity_Flow_Step $step
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function maybe_handle_order_organization_assignees($assignees, Gravity_Flow_Step $step) {
|
||||
|
||||
$mapped_assignees = array();
|
||||
|
||||
$order_id = self::_get_order_id_for_step($step);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
foreach ($assignees as $assignee) {
|
||||
|
||||
/**
|
||||
* Handle step assignee for installation company field
|
||||
*/
|
||||
if (strpos($assignee->get_type(), 'wiaas_installation_') !== false) {
|
||||
|
||||
$item_id = $assignee->get_id();
|
||||
|
||||
$item = $order->get_item($item_id);
|
||||
|
||||
$organization_id = $item['wiaas_supplier_organization_id'];
|
||||
|
||||
$user_ids = wiaas_get_organization_user_ids($organization_id);
|
||||
|
||||
if (empty($user_ids)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$user_id = $user_ids[0];
|
||||
|
||||
$mapped_assignees[] = $step->get_assignee( array(
|
||||
'id' => $user_id,
|
||||
'type' => 'user_id',
|
||||
'editable_fields' => $assignee->get_editable_fields()
|
||||
) );
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle step assignee for order role
|
||||
*/
|
||||
if ($assignee->get_type() === 'wiaas_order_role') {
|
||||
|
||||
|
||||
$order_role = $assignee->get_id();
|
||||
|
||||
// Assign step to order customer
|
||||
if ($order_role === 'customer') {
|
||||
|
||||
$customer_user_id = $order->get_customer_id();
|
||||
|
||||
// for now assign only customer that create order
|
||||
// check if all customer organization users should be able to see order step
|
||||
|
||||
$mapped_assignees[] = $step->get_assignee( array(
|
||||
'id' => $customer_user_id,
|
||||
'type' => 'user_id',
|
||||
'editable_fields' => $assignee->get_editable_fields()
|
||||
) );
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$mapped_assignees[] = $assignee;
|
||||
}
|
||||
|
||||
return $mapped_assignees;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve order id for delivery process step
|
||||
*
|
||||
* @param Gravity_Flow_Step $step
|
||||
*
|
||||
* @return bool|int Order id on success, false if step does not have associated order id
|
||||
*
|
||||
*/
|
||||
private static function _get_order_id_for_step(Gravity_Flow_Step $step) {
|
||||
|
||||
$entry = $step->get_entry();
|
||||
|
||||
// if order is present in entry metadata use that value
|
||||
if (! empty($entry['wiaas_delivery_order_id'])) {
|
||||
|
||||
return absint($entry['wiaas_delivery_order_id']);
|
||||
}
|
||||
|
||||
// try getting order id from order field
|
||||
$form = GFAPI::get_form($entry['form_id']);
|
||||
|
||||
$order_fields = GFCommon::get_fields_by_type($form, array( 'wiaas_order'));
|
||||
|
||||
if (! empty($order_fields)) {
|
||||
|
||||
$order_field = $order_fields[0]; // there should only be one order field per entry
|
||||
|
||||
return absint($entry[$order_field->id]);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Delivery_Process_Step_Assignee::init();
|
||||
@@ -7,30 +7,12 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
* @var string
|
||||
*/
|
||||
public $_step_type = 'wiaas_delivery_step';
|
||||
|
||||
private static $delivery_action_form_title_prefix = 'DELIVERY ACTION TYPE:';
|
||||
|
||||
private static $delivery_action_types = array(
|
||||
'DELIVERY ACTION TYPE: Customer acceptance' => 'customer-acceptance',
|
||||
'DELIVERY ACTION TYPE: Validate Questionnaire' => 'validate-questionnaire',
|
||||
'DELIVERY ACTION TYPE: Manual' => 'manual',
|
||||
'DELIVERY ACTION TYPE: Schedule meeting' => 'schedule-meeting'
|
||||
);
|
||||
|
||||
public static function get_delivery_action_types() {
|
||||
return array_keys(self::$delivery_action_types);
|
||||
}
|
||||
|
||||
public static function get_delivery_action_type_prefix() {
|
||||
return self::$delivery_action_form_title_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns label for Wiass Delivery Process Step
|
||||
* @return string
|
||||
*/
|
||||
public function get_label() {
|
||||
return esc_html__( 'Wiaas Delivery Step', 'wiaas' );
|
||||
return esc_html__( 'Delivery Step', 'wiaas' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,12 +23,12 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
|
||||
$settings_api = $this->get_common_settings_api();
|
||||
|
||||
$forms = $this->get_target_forms_choices();
|
||||
$forms = Wiaas_Delivery_Process_Action::get_action_forms();
|
||||
$form_choices[] = array( 'label' => esc_html__( 'Select a Form', 'wiaas' ), 'value' => '' );
|
||||
foreach ( $forms as $form ) {
|
||||
$form_choices[] = array( 'label' => $form->title, 'value' => $form->id );
|
||||
}
|
||||
|
||||
$form_choices[] = array( 'label' => $form['title'], 'value' => $form['id'] );
|
||||
}
|
||||
|
||||
$settings = array(
|
||||
'title' => esc_html__( 'Wiaas Delivery Step', 'wiaas' ),
|
||||
@@ -71,18 +53,71 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
'type' => 'select',
|
||||
'onchange' => "jQuery(this).closest('form').submit();",
|
||||
'choices' => $form_choices,
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function start() {
|
||||
|
||||
parent::start();
|
||||
|
||||
$this->update_step_status('pending');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function evaluate_status() {
|
||||
|
||||
return $this->get_status();
|
||||
}
|
||||
|
||||
public function get_status_label($status) {
|
||||
|
||||
$label = parent::get_status_label($status);
|
||||
|
||||
if (empty($label)) {
|
||||
|
||||
$label = __('Not started', 'wiaas');
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Wiass Delivery Process Step
|
||||
* Update status
|
||||
*
|
||||
* @param bool $status
|
||||
*/
|
||||
public function update_step_status($status = false) {
|
||||
|
||||
/**
|
||||
* If status is being updated after manual step completion ('Next Step' or 'Previous Step') change default
|
||||
* behavior of settings status to cancelled if manual action is sending flow to next step.
|
||||
* Instead of default cancelled status set complete status for this step.
|
||||
*/
|
||||
if ($status === 'cancelled' && $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' )) {
|
||||
|
||||
list( $base_admin_action, $step_id ) = rgexplode( '|', $admin_action, 2 );
|
||||
|
||||
$next_step = gravity_flow()->get_next_step($this, $this->get_entry(), $this->get_form());
|
||||
// going to next step
|
||||
if ($base_admin_action === 'send_to_step' && $next_step && $next_step->get_id() == $step_id) {
|
||||
|
||||
$status = 'complete';
|
||||
}
|
||||
}
|
||||
|
||||
parent::update_step_status($status);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Process Wiaas Delivery Process Step
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
* @return bool We will always return false because step will be completed only by manual user action
|
||||
*/
|
||||
function process() {
|
||||
|
||||
@@ -90,81 +125,77 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
$entry = $this->get_entry();
|
||||
$target_form = GFAPI::get_form( $this->target_form_id );
|
||||
|
||||
# if target form is not valid just finish the step
|
||||
# if target form is not set we are done
|
||||
if (!$target_form) {
|
||||
return true;
|
||||
// return false since we wait for admin to process the step
|
||||
return false;
|
||||
}
|
||||
|
||||
# create new entry for target form with populated value for customer-id from parent entry
|
||||
$new_entry = array(
|
||||
'form_id' => $this->target_form_id,
|
||||
'wiaas_delivery_process_id' => $this->get_entry_id(),
|
||||
'wiaas_delivery_order_id' => $entry['wiaas_delivery_order_id'],
|
||||
'wiaas_delivery_step_name' => $this->get_name(),
|
||||
);
|
||||
$delivery_settings = rgar($target_form, 'wiaas_delivery_process');
|
||||
|
||||
$customer_id_value = null;
|
||||
if (! $delivery_settings['automatic_action_entries_enabled']) {
|
||||
|
||||
if ( is_array( $form['fields'] ) ) {
|
||||
foreach ( $form['fields'] as $field ) {
|
||||
if (GFCommon::get_label( $field ) === 'customer-id') {
|
||||
$customer_id_value = $entry[$field->id];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$action_entries_ids = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids');
|
||||
|
||||
// if action entries present this step is reprocessing and we should not be creating new action entries
|
||||
if (! empty($action_entries_ids)) {
|
||||
// return false since we wait for admin to process the step
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( is_array( $target_form['fields'] ) ) {
|
||||
foreach ( $target_form['fields'] as $field ) {
|
||||
if (GFCommon::get_label( $field ) === 'customer-id') {
|
||||
$new_entry[$field->id] = $customer_id_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// create new entries for step action forms
|
||||
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
|
||||
$order_id = empty($order_field) ? null : absint($entry[$order_field->id]);
|
||||
|
||||
// if process has not order we cannot create actions
|
||||
if (empty($order_id)) {
|
||||
// return false since we wait for admin to process the step
|
||||
return false;
|
||||
}
|
||||
|
||||
$entry_id = GFAPI::add_entry( $new_entry );
|
||||
if ( is_wp_error( $entry_id ) ) {
|
||||
$this->log_debug( __METHOD__ .'(): failed to add entry' );
|
||||
} else {
|
||||
// store entry id
|
||||
gform_update_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id', $entry_id);
|
||||
$delivery_settings = rgar($target_form, 'wiaas_delivery_process');
|
||||
|
||||
switch ($delivery_settings['automatic_action_entries_type']) {
|
||||
|
||||
case 'single':
|
||||
$action_entries_ids = $this->_create_single_action_entry($target_form, $order_id);
|
||||
break;
|
||||
case 'bundle':
|
||||
$action_entries_ids = $this->_create_per_bundle_action_entries($target_form, $order_id);
|
||||
}
|
||||
|
||||
gform_update_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids', $action_entries_ids);
|
||||
|
||||
$note = $this->get_name() . ': ' . esc_html__( 'started.', 'wiaas' );
|
||||
$this->add_note( $note );
|
||||
|
||||
# return false since we wait for workflow of target entry to be complete first
|
||||
// return false since we wait for admin to process the step
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates current step status based on target form entry status
|
||||
*
|
||||
* If target form entry has associated workflow current step will complete its status
|
||||
* only when target form entry workflow is completed
|
||||
* @return string
|
||||
*/
|
||||
public function status_evaluation() {
|
||||
public function workflow_detail_box($form, $args) {
|
||||
parent::workflow_detail_box($form, $args);
|
||||
|
||||
# retrieve target form entry to check its workflow status
|
||||
$target_form_entry = $this->get_target_form_entry();
|
||||
$target_form = GFAPI::get_form( $this->target_form_id );
|
||||
|
||||
# if there is no target form entry just complete the step
|
||||
if(!$target_form_entry) {
|
||||
return 'complete';
|
||||
if (empty( $target_form)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# retrieve target form entry workflow status
|
||||
$api = new Gravity_Flow_API( $this->target_form_id );
|
||||
$status = $api->get_status($target_form_entry);
|
||||
?>
|
||||
<h4>Step: <?php echo $this->get_name() ?></h4>
|
||||
<h4>Action: <?php echo $target_form['title'] ?></h4>
|
||||
<?php
|
||||
|
||||
# status is complete only if target entry flow is complete
|
||||
return $status === 'complete' || $status === 'approved' ? 'complete' : 'pending';
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands step entry with additional metadata to track created target entry id
|
||||
* Expands step entry with additional metadata to track created target actions entries id
|
||||
*
|
||||
* @param array $entry_meta
|
||||
* @param int $form_id
|
||||
*
|
||||
@@ -172,79 +203,94 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
*/
|
||||
public function get_entry_meta($entry_meta, $form_id) {
|
||||
if ($form_id === $this->get_form_id()) {
|
||||
$entry_meta['wiaas_delivery_step_' . $this->get_id() .'_entry_id'] = null;
|
||||
$entry_meta['wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids'] = array();
|
||||
}
|
||||
return $entry_meta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves forms that are valid options for delivery step action
|
||||
*
|
||||
* PRIVATE
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Create action entry to trigger subworkflow
|
||||
* @param $target_form
|
||||
* @param $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_target_forms_choices() {
|
||||
return GFFormsModel::search_forms(self::$delivery_action_form_title_prefix, true);
|
||||
private function _create_single_action_entry($target_form, $order_id) {
|
||||
|
||||
$action_entries_ids = array();
|
||||
|
||||
$new_entry = Wiaas_Order_Fields::map_order_to_entry($order_id, $target_form);
|
||||
|
||||
if (empty($new_entry)) {
|
||||
// entry cannot be created
|
||||
return $action_entries_ids;
|
||||
}
|
||||
|
||||
$new_entry['form_id'] = $target_form['id'];
|
||||
$new_entry['wiaas_delivery_process_id'] = $this->get_entry_id();
|
||||
$new_entry['wiaas_delivery_order_id'] = $order_id;
|
||||
|
||||
$entry_id = GFAPI::add_entry( $new_entry );
|
||||
|
||||
if ( is_wp_error( $entry_id ) ) {
|
||||
$this->log_debug( __METHOD__ .'(): failed to add entry' );
|
||||
} else {
|
||||
// store entry id
|
||||
$action_entries_ids[] = $entry_id;
|
||||
}
|
||||
|
||||
return $action_entries_ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves delivery action type that is executed with this step
|
||||
* @return string
|
||||
* Create action form entries for every bundle in order to trigger subworkflows
|
||||
*
|
||||
* @param $target_form
|
||||
* @param $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_delivery_action_type() {
|
||||
$target_form = GFAPI::get_form( $this->target_form_id );
|
||||
return self::$delivery_action_types[$target_form['title']];
|
||||
}
|
||||
private function _create_per_bundle_action_entries($target_form, $order_id) {
|
||||
|
||||
public function get_target_actual_date() {
|
||||
$target_entry = $this->get_target_form_entry();
|
||||
$target_form = GFAPI::get_form( $this->target_form_id );
|
||||
$action_entries_ids = array();
|
||||
|
||||
if (!is_wp_error($target_entry) && is_array($target_form['fields'])) {
|
||||
foreach ( $target_form['fields'] as $field ) {
|
||||
if (GFCommon::get_label( $field ) === 'Actual Date') {
|
||||
return $target_entry[$field->id];
|
||||
}
|
||||
$bundle_items = wiaas_get_order_standard_bundle_items($order_id);
|
||||
|
||||
foreach ($bundle_items as $item) {
|
||||
|
||||
$new_entry = Wiaas_Order_Fields::map_order_to_entry($order_id, $target_form, $item->get_id());
|
||||
|
||||
if (empty($new_entry)) {
|
||||
// entry cannot be created
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_entry['form_id'] = $target_form['id'];
|
||||
$new_entry['wiaas_delivery_process_id'] = $this->get_entry_id();
|
||||
$new_entry['wiaas_delivery_order_id'] = $order_id;
|
||||
|
||||
$entry_id = GFAPI::add_entry( $new_entry );
|
||||
|
||||
if ( is_wp_error( $entry_id ) ) {
|
||||
|
||||
$this->log_debug( __METHOD__ .'(): failed to add entry' );
|
||||
} else {
|
||||
// store entry id
|
||||
|
||||
$action_entries_ids[] = $entry_id;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_target_step_comments() {
|
||||
$notes = RGFormsModel::get_lead_notes( $this->get_target_form_entry_id() );
|
||||
|
||||
$comments = array();
|
||||
foreach ( $notes as $key => $note ) {
|
||||
if ( $note->note_type !== 'gravityflow' ) {
|
||||
$comments[] = array(
|
||||
'date' => $note->date_created,
|
||||
'text' => $note->value,
|
||||
'user' => $note->user_name
|
||||
);
|
||||
}
|
||||
}
|
||||
return $comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves target form entry created when step was started
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_target_form_entry() {
|
||||
$entry = GFAPI::get_entry($this->get_target_form_entry_id());
|
||||
if(is_wp_error($entry)) {
|
||||
return null;
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves target form entry id created when step was started
|
||||
* @return int
|
||||
*/
|
||||
public function get_target_form_entry_id() {
|
||||
$value = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id');
|
||||
|
||||
return absint($value);
|
||||
return $action_entries_ids;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Field_Order_Bundle_Document extends GF_Field_FileUpload {
|
||||
|
||||
public $type ='wiaas_order_bundle_document';
|
||||
|
||||
public $wiaasDocTypeFilter = 'config';
|
||||
|
||||
public function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'wiaas_doc_type_filter',
|
||||
'multiple_files_setting',
|
||||
'conditional_logic_field_setting',
|
||||
'error_message_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'rules_setting',
|
||||
'file_extensions_setting',
|
||||
'file_size_setting',
|
||||
'visibility_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
);
|
||||
}
|
||||
|
||||
public function get_input_type() {
|
||||
return 'fileupload';
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Bundle Document', 'wiaas' );
|
||||
}
|
||||
|
||||
public function get_download_url( $file, $force_download = false ) {
|
||||
|
||||
$upload_root = GFFormsModel::get_upload_url( $this->formId );
|
||||
$upload_root = trailingslashit( $upload_root );
|
||||
|
||||
// handle download for order documents not uploaded by gravity forms
|
||||
if ( strpos( $file, $upload_root ) === false ) {
|
||||
|
||||
return admin_url() . '?gf-wiaas-order-doc=' . urlencode($file);
|
||||
}
|
||||
|
||||
return parent::get_download_url( $file, $force_download );
|
||||
}
|
||||
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
|
||||
$this->wiaasDocTypeFilter = sanitize_key($this->wiaasDocTypeFilter);
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Wiaas_Field_Order_Bundle_Document() );
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Field_Order_Bundle_Installation_Date extends GF_Field_Date {
|
||||
|
||||
public $type ='wiaas_order_bundle_installation_date';
|
||||
|
||||
public $inputType = 'date';
|
||||
|
||||
public $dateType = 'datepicker';
|
||||
|
||||
public function get_input_type() {
|
||||
return 'date';
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Bundle Install Date', 'wiaas' );
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GF_Fields::register( new Wiaas_Field_Order_Bundle_Installation_Date() );
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Field_Order_Bundle extends GF_Field_Text {
|
||||
|
||||
public $type = 'wiaas_order_bundle';
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Bundle', 'wiaas' );
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
return $this->get_bundle_display_name($value);
|
||||
}
|
||||
|
||||
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
return $this->get_bundle_display_name($value);
|
||||
}
|
||||
|
||||
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
return $this->get_bundle_display_name($value);
|
||||
}
|
||||
|
||||
public function get_bundle_item($value) {
|
||||
|
||||
list($order_id, $item_id) = rgexplode('|', $value, 2);
|
||||
|
||||
if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) {
|
||||
|
||||
return $order->get_item($item_id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_bundle_display_name($value) {
|
||||
|
||||
$item = $this->get_bundle_item($value);
|
||||
|
||||
if (! empty($item)) {
|
||||
|
||||
return $item->get_name();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Wiaas_Field_Order_Bundle() );
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Field_Order_Document extends GF_Field_FileUpload {
|
||||
|
||||
public $type ='wiaas_order_document';
|
||||
|
||||
public $wiaasDocTypeFilter = 'install_guide';
|
||||
|
||||
public function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'wiaas_doc_type_filter',
|
||||
'multiple_files_setting',
|
||||
'conditional_logic_field_setting',
|
||||
'error_message_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'rules_setting',
|
||||
'file_extensions_setting',
|
||||
'file_size_setting',
|
||||
'visibility_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
);
|
||||
}
|
||||
|
||||
public function get_input_type() {
|
||||
return 'fileupload';
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Order Document', 'wiaas' );
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_download_url( $file, $force_download = false ) {
|
||||
|
||||
$upload_root = GFFormsModel::get_upload_url( $this->formId );
|
||||
$upload_root = trailingslashit( $upload_root );
|
||||
|
||||
// handle download for order documents not uploaded by gravity forms
|
||||
if ( strpos( $file, $upload_root ) === false ) {
|
||||
|
||||
return admin_url() . '?gf-wiaas-order-doc=' . urlencode($file);
|
||||
}
|
||||
|
||||
return parent::get_download_url( $file, true );
|
||||
}
|
||||
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
|
||||
$this->wiaasDocTypeFilter = sanitize_key($this->wiaasDocTypeFilter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GF_Fields::register( new Wiaas_Field_Order_Document() );
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Order_Installation_Select extends GF_Field_Select {
|
||||
|
||||
public $type = 'wiaas_order_installation_select';
|
||||
|
||||
|
||||
public function get_input_type() {
|
||||
return 'workflow_assignee_select';
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_field_input( $form, $value = '', $entry = null ) {
|
||||
|
||||
if ( empty($entry) ) {
|
||||
|
||||
return parent::get_field_input($form, $value, $entry);
|
||||
}
|
||||
|
||||
// get bundle item field
|
||||
$bundle_item_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order_bundle') )[0];
|
||||
|
||||
if (! empty($bundle_item_field) &&
|
||||
$bundle_item = $bundle_item_field->get_bundle_item($entry[$bundle_item_field->id])) {
|
||||
|
||||
$bundled_items = wc_pb_get_bundled_order_items($bundle_item);
|
||||
|
||||
$installation_items = array();
|
||||
|
||||
foreach ($bundled_items as $id => $bundled_item) {
|
||||
|
||||
$product = $bundled_item->get_product();
|
||||
|
||||
if ($product && Wiaas_Product_Category::is_installation($product)) {
|
||||
|
||||
$installation_items[] = $bundled_item;
|
||||
}
|
||||
}
|
||||
|
||||
$choices = array(
|
||||
array( 'value' => '0', 'text' => 'Select installation ...')
|
||||
);
|
||||
|
||||
$order_id = $bundle_item->get_order_id();
|
||||
|
||||
foreach ($installation_items as $installation_item) {
|
||||
|
||||
$choices[] = array(
|
||||
'value' => 'wiaas_installation_' . $order_id . '|' . $installation_item->get_id(),
|
||||
'text' => $installation_item->get_name()
|
||||
);
|
||||
}
|
||||
|
||||
$this->choices = $choices;
|
||||
}
|
||||
|
||||
return parent::get_field_input($form, $value, $entry);
|
||||
}
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Installation Select', 'wiaas' );
|
||||
}
|
||||
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
return $this->get_selected_installation_display_name($value);
|
||||
}
|
||||
|
||||
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
return $this->get_selected_installation_display_name($value);
|
||||
}
|
||||
|
||||
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
return $this->get_selected_installation_display_name($value);
|
||||
}
|
||||
|
||||
public function get_selected_installation($value) {
|
||||
|
||||
$value = $value ? str_replace('wiaas_installation_', '', $value) : '';
|
||||
|
||||
list ($order_id, $item_id) = explode('|', $value);
|
||||
|
||||
if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) {
|
||||
|
||||
return $order->get_item($item_id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_selected_installation_display_name($value) {
|
||||
|
||||
$item = $this->get_selected_installation($value);
|
||||
|
||||
return ! empty($item) ? $item->get_name() : '';
|
||||
}
|
||||
|
||||
public function post_convert_field() {
|
||||
|
||||
if ($this->is_form_editor()) {
|
||||
|
||||
$this->choices = array(
|
||||
array( 'value' => '0', 'text' => 'Select installation ...')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GF_Fields::register( new Wiaas_Order_Installation_Select() );
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Field_Order_Number extends GF_Field_Number {
|
||||
|
||||
public $type = 'wiaas_order';
|
||||
|
||||
function get_form_editor_field_settings() {
|
||||
return array(
|
||||
'conditional_logic_field_setting',
|
||||
'prepopulate_field_setting',
|
||||
'error_message_setting',
|
||||
'label_setting',
|
||||
'label_placement_setting',
|
||||
'admin_label_setting',
|
||||
'size_setting',
|
||||
'rules_setting',
|
||||
'visibility_setting',
|
||||
'duplicate_setting',
|
||||
'default_value_setting',
|
||||
'placeholder_setting',
|
||||
'description_setting',
|
||||
'css_class_setting',
|
||||
);
|
||||
}
|
||||
|
||||
public function sanitize_settings() {
|
||||
parent::sanitize_settings();
|
||||
}
|
||||
|
||||
|
||||
public function get_form_editor_field_title() {
|
||||
return esc_attr__( 'Order Number', 'wiaas' );
|
||||
}
|
||||
|
||||
public function add_button( $field_groups ) {
|
||||
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
|
||||
|
||||
return parent::add_button( $field_groups );
|
||||
}
|
||||
|
||||
public function get_form_editor_button() {
|
||||
return array(
|
||||
'group' => 'wiaas_order_fields',
|
||||
'text' => $this->get_form_editor_field_title(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
|
||||
return "#100000$value";
|
||||
}
|
||||
|
||||
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
|
||||
return "#100000$value";
|
||||
}
|
||||
|
||||
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
|
||||
return "#100000$value";
|
||||
}
|
||||
}
|
||||
|
||||
GF_Fields::register( new Wiaas_Field_Order_Number() );
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Merge_Tag_Customer_Order_Url extends Gravity_Flow_Merge_Tag {
|
||||
|
||||
/**
|
||||
* Name of the merge tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'customer_order_url';
|
||||
|
||||
|
||||
/**
|
||||
* The regular expression to use for the matching.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $regex = '/{customer_order_url(:(.*?))?}/';
|
||||
|
||||
|
||||
public function replace( $text ) {
|
||||
|
||||
$matches = $this->get_matches( $text );
|
||||
|
||||
if ( ! empty( $matches ) ) {
|
||||
|
||||
$entry = $this->entry;
|
||||
|
||||
$form = GFAPI::get_form($entry['form_id']);
|
||||
|
||||
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
|
||||
|
||||
if (empty($order_field)) {
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
$order_id = $entry[$order_field->id];
|
||||
|
||||
$url = WIAAS_CUSTOMER_INTERFACE . '/orders/' . $order_id;
|
||||
|
||||
$link = sprintf( '<a href="%s">%s</a>', $url, 'Order' );
|
||||
|
||||
foreach ( $matches as $match ) {
|
||||
$full_tag = $match[0];
|
||||
|
||||
$text = str_replace( $full_tag, $link, $text );
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
Gravity_Flow_Merge_Tags::register( new Wiaas_Merge_Tag_Customer_Order_Url );
|
||||
@@ -0,0 +1,465 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'GFForms' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
class Wiaas_Order_Fields {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'gform_field_standard_settings', array( __CLASS__, 'field_settings' ) );
|
||||
|
||||
add_filter('gform_fileupload_entry_value_file_path', array( __CLASS__, 'display_order_document_fields' ), 999, 2);
|
||||
|
||||
add_action('gform_post_update_entry', array(__CLASS__, 'maybe_map_entry_to_order'), 10, 2);
|
||||
|
||||
add_action('gform_after_update_entry', array(__CLASS__, 'maybe_apply_user_input_changes'), 10, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Workflow user input are handled separately in gravity flow. We get them here
|
||||
* and then try to apply changes to order
|
||||
*
|
||||
* @param $form
|
||||
* @param $entry_id
|
||||
* @param $original_entry
|
||||
*/
|
||||
public static function maybe_apply_user_input_changes($form, $entry_id, $original_entry) {
|
||||
|
||||
$entry = GFAPI::get_entry($entry_id);
|
||||
|
||||
self::maybe_map_entry_to_order($entry, $original_entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Persist workflow entry change to order
|
||||
*
|
||||
* @param $entry
|
||||
* @param $old_entry
|
||||
*/
|
||||
public static function maybe_map_entry_to_order($entry, $old_entry) {
|
||||
|
||||
$form = GFAPI::get_form($old_entry['form_id']);
|
||||
|
||||
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
|
||||
|
||||
if (empty($order_field)) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$order_id = $entry[$order_field->id];
|
||||
|
||||
// get order process entry
|
||||
$order = wc_get_order($order_id);
|
||||
$process_entry = Wiaas_Delivery_Process::get_order_delivery_process_entry($order_id);
|
||||
|
||||
if ( !$order || empty($process_entry) ) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// apply entry changes to order properties
|
||||
foreach ($form['fields'] as $field) {
|
||||
|
||||
$old_value = $old_entry[$field->id];
|
||||
$new_value = $entry[$field->id];
|
||||
|
||||
// check if field changed
|
||||
if ($old_value === $new_value || empty($new_value)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// save changes to order
|
||||
switch ($field->type) {
|
||||
|
||||
case 'wiaas_order_bundle_installation_date':
|
||||
/**
|
||||
* Persist bundle installation date
|
||||
*/
|
||||
|
||||
// get corresponding bundle field
|
||||
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
|
||||
|
||||
if (empty($bundle_field)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
|
||||
|
||||
if (empty($bundle_item)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item->update_meta_data('_wiaas_installation_date', $new_value);
|
||||
$bundle_item->save_meta_data();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle_document':
|
||||
/**
|
||||
* Persist delivery flow documents for bundle
|
||||
*/
|
||||
|
||||
// get corresponding bundle field
|
||||
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
|
||||
|
||||
if (empty($bundle_field)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
|
||||
|
||||
if (empty($bundle_item)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_documents = $bundle_item->get_meta('_wiaas_documents', true);
|
||||
if (empty($bundle_documents)) {
|
||||
$bundle_documents = array();
|
||||
}
|
||||
|
||||
$new_documents = $field->multipleFiles ? json_decode( $new_value ) : array( $new_value );
|
||||
if (! empty($old_value) ) {
|
||||
|
||||
$old_documents = $field->multipleFiles ? json_decode( $old_value ) : array( $old_value );
|
||||
$added_documents = array_diff($new_documents, $old_documents);
|
||||
} else {
|
||||
|
||||
$added_documents = $new_documents;
|
||||
}
|
||||
|
||||
|
||||
foreach ($added_documents as $added_document) {
|
||||
$info = pathinfo( $added_document );
|
||||
|
||||
$dir = wp_upload_dir();
|
||||
$relative_file_path = str_replace($dir['baseurl'] . '/', '', $added_document);
|
||||
|
||||
$bundle_documents[] = array(
|
||||
'key' => wp_generate_uuid4(),
|
||||
'name' => $info['filename'],
|
||||
'extension' => $info['extension'],
|
||||
'version' => $relative_file_path,
|
||||
'url' => $field->get_download_url( $added_document, true ),
|
||||
'type' => $field->wiaasDocTypeFilter
|
||||
);
|
||||
}
|
||||
|
||||
$bundle_item->update_meta_data('_wiaas_documents', $bundle_documents);
|
||||
$bundle_item->save_meta_data();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_document':
|
||||
/**
|
||||
* Persist delivery flow documents for order
|
||||
*/
|
||||
$new_documents = $field->multipleFiles ? json_decode( $new_value ) : array( $new_value );
|
||||
|
||||
if (! empty($old_value) ) {
|
||||
|
||||
$old_documents = $field->multipleFiles ? json_decode( $old_value ) : array( $old_value );
|
||||
$added_documents = array_diff($new_documents, $old_documents);
|
||||
} else {
|
||||
|
||||
$added_documents = $new_documents;
|
||||
}
|
||||
|
||||
$order_documents = $order->get_meta('_wiaas_other_documents', true);
|
||||
if (empty($order_documents)) {
|
||||
$order_documents = array();
|
||||
}
|
||||
|
||||
foreach ($added_documents as $added_document) {
|
||||
$info = pathinfo( $added_document );
|
||||
|
||||
$dir = wp_upload_dir();
|
||||
$relative_file_path = str_replace($dir['baseurl'] . '/', '', $added_document);
|
||||
|
||||
$order_documents[] = array(
|
||||
'key' => wp_generate_uuid4(),
|
||||
'name' => $info['filename'],
|
||||
'extension' => $info['extension'],
|
||||
'version' => $relative_file_path,
|
||||
'url' => $field->get_download_url( $added_document, true ),
|
||||
'type' => $field->wiaasDocTypeFilter
|
||||
);
|
||||
}
|
||||
|
||||
$order->update_meta_data('_wiaas_other_documents', $order_documents);
|
||||
$order->save_meta_data();
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_installation_select':
|
||||
/**
|
||||
* Persist installation for bundle
|
||||
*/
|
||||
|
||||
$selected_installation = $field->get_selected_installation($new_value);
|
||||
|
||||
if ( empty($selected_installation) ) {
|
||||
// no installation selected
|
||||
continue;
|
||||
}
|
||||
|
||||
// get corresponding bundle field
|
||||
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
|
||||
|
||||
if (empty($bundle_field)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
|
||||
|
||||
if (empty($bundle_item)) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundle_item->update_meta_data('_wiaas_installation', $selected_installation->get_id());
|
||||
$bundle_item->save_meta_data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Order Fields group to the form editor.
|
||||
*
|
||||
* @param array $field_groups The properties for the field groups.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function maybe_add_order_field_group( $field_groups ) {
|
||||
foreach ( $field_groups as $field_group ) {
|
||||
if ( $field_group['name'] == 'wiaas_order_fields' ) {
|
||||
return $field_groups;
|
||||
}
|
||||
}
|
||||
|
||||
$field_groups[] = array(
|
||||
'name' => 'wiaas_order_fields',
|
||||
'label' => __( 'Order Fields', 'wiaas' ),
|
||||
'fields' => array()
|
||||
);
|
||||
|
||||
return $field_groups;
|
||||
}
|
||||
|
||||
|
||||
public static function display_order_document_fields($file_path, $field) {
|
||||
|
||||
if (strpos($file_path, 'gf-download') === false &&
|
||||
strpos($file_path, 'gf-wiaas-order-doc') === false) {
|
||||
|
||||
$field = new Wiaas_Field_Order_Bundle_Document();
|
||||
|
||||
return $field->get_download_url($file_path);
|
||||
}
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom settings for form order fields
|
||||
*
|
||||
* @param int $position
|
||||
*/
|
||||
public static function field_settings( $position ) {
|
||||
if ( $position === 20 ) {
|
||||
// After Field description setting.
|
||||
?>
|
||||
|
||||
<li class="wiaas_doc_type_filter field_setting">
|
||||
|
||||
<label for="wiaas-doc-type-filter" class="section_label">
|
||||
<?php esc_html_e( 'Document Type', 'wiaas' ); ?>
|
||||
</label>
|
||||
<select id="wiaas-doc-type-filter" onchange="SetFieldProperty('wiaasDocTypeFilter',this.value);">
|
||||
<option value="configuration"><?php esc_html_e( 'Configuration', 'wiaas' ); ?></option>
|
||||
<option value="order_questionaire"><?php esc_html_e( 'Order Questionaire', 'wiaas' ); ?></option>
|
||||
<option value="installation_protocol"><?php esc_html_e( 'Installation protocol', 'wiaas' ); ?></option>
|
||||
<option value="install_guide"><?php esc_html_e( 'Installation Guide', 'wiaas' ); ?></option>
|
||||
<option value="customer_acceptance"><?php esc_html_e( 'Customer acceptance', 'wiaas' ); ?></option>
|
||||
</select>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="wiaas_installation_organization_filter field_setting">
|
||||
<input type="checkbox" id="wiaas-installation-organization-filter"
|
||||
onclick="var value = jQuery(this).is(':checked'); SetFieldProperty('wiaasOnlyInstallationOrg', value);""/>
|
||||
<label for="wiaas-installation-organization-filter" class="inline">
|
||||
<?php esc_html_e( 'Only installation', 'wiaas' ); ?>
|
||||
</label>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new entry for order delivery process action form
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param array $form
|
||||
* @param int|null $bundle_item_id
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function map_order_to_entry($order_id, $form, $bundle_item_id = null) {
|
||||
|
||||
if (empty($form['fields']) ||
|
||||
empty(GFCommon::get_fields_by_type( $form, array('wiaas_order')) ) ) {
|
||||
// form does not have order field so cannot be mapped
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$entry = array();
|
||||
|
||||
foreach ($form['fields'] as $field) {
|
||||
|
||||
switch ($field->type) {
|
||||
|
||||
case 'wiaas_order':
|
||||
|
||||
$entry[(string) $field->id] = $order->get_id();
|
||||
|
||||
break;
|
||||
|
||||
case 'workflow_user':
|
||||
$entry[(string) $field->id] = $order->get_customer_id(); // save customer if needed
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle':
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($bundle_item)) {
|
||||
|
||||
$entry[(string) $field->id] = $order->get_id() . '|' . $bundle_item->get_id();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_bundle_document':
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($bundle_item)) {
|
||||
|
||||
$documents = wiaas_get_standard_package_order_item_documents($order, $bundle_item_id);
|
||||
|
||||
$filtered_documents = array();
|
||||
|
||||
foreach ($documents as $document) {
|
||||
|
||||
if ($document['type'] === $field->wiaasDocTypeFilter) {
|
||||
|
||||
$filtered_documents[] = $document;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty($filtered_documents) && $field->isRequired ) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty ($filtered_documents) && ! $field->multipleFiles) {
|
||||
|
||||
$document = $filtered_documents[0];
|
||||
|
||||
$entry[$field->id] = $document['version'];
|
||||
|
||||
} else if (! empty ($filtered_documents) ) {
|
||||
|
||||
$versions = array();
|
||||
foreach ($filtered_documents as $filtered_document) {
|
||||
$versions[] = $filtered_document['version'];
|
||||
}
|
||||
|
||||
$entry[$field->id] = json_encode($versions);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'wiaas_order_installation_select':
|
||||
|
||||
$bundle_item = $order->get_item($bundle_item_id);
|
||||
|
||||
if ( empty($bundle_item) && $field->isRequired) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
// installation is already selected
|
||||
if (!empty($bundle_item->get_meta('_wiaas_installation', true))) {
|
||||
|
||||
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $bundle_item->get_meta('_wiaas_installation', true);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$bundled_items = wc_pb_get_bundled_order_items($bundle_item, $order);
|
||||
|
||||
$installation_items = array();
|
||||
|
||||
foreach ($bundled_items as $id => $bundled_item) {
|
||||
|
||||
$product = $bundled_item->get_product();
|
||||
|
||||
if ($product && Wiaas_Product_Category::is_installation($product)) {
|
||||
|
||||
$installation_items[] = $bundled_item;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($installation_items)) {
|
||||
// there is no data for required field so entry cannot be created
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($installation_items) === 1) {
|
||||
|
||||
$installation_item = $installation_items[0];
|
||||
|
||||
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $installation_item->get_id();
|
||||
|
||||
} else if (count($installation_items) > 1) {
|
||||
|
||||
// force admin to select installation
|
||||
$entry[(string) $field->id] = '0';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Order_Fields::init();
|
||||
@@ -12,9 +12,41 @@ class Wiaas_Document_Download {
|
||||
if ( isset($_GET['wiaasdoc']) ) {
|
||||
add_action( 'init', array( __CLASS__, 'admin_download' ) );
|
||||
}
|
||||
|
||||
if (isset($_GET['gf-wiaas-order-doc'])) {
|
||||
|
||||
add_action( 'init', array( __CLASS__, 'admin_gf_order_document_download' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle download of order documents by gravity flow steps for wordpress administration interface
|
||||
*
|
||||
*/
|
||||
public static function admin_gf_order_document_download() {
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) );
|
||||
}
|
||||
|
||||
// relative file path from upload dir for document
|
||||
$version = urldecode($_GET['gf-wiaas-order-doc']);
|
||||
|
||||
$file_path = wiaas_get_document_version_path($version);
|
||||
|
||||
if (!file_exists($file_path)) {
|
||||
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
|
||||
}
|
||||
|
||||
WC_Download_Handler::download_file_force(
|
||||
$file_path,
|
||||
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle document download for wordpress administration interface
|
||||
*
|
||||
* Since only REST api uses JWT Authentication this endpoint will work only for users
|
||||
* that are logged in directly to wordpress
|
||||
*/
|
||||
@@ -54,6 +86,48 @@ class Wiaas_Document_Download {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download order other document (not related to any order item)
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param string $document_key
|
||||
*/
|
||||
public static function download_order_other_document($order_id, $document_key) {
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order) {
|
||||
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
|
||||
}
|
||||
|
||||
$order_other_documents = wiaas_get_order_other_documents($order_id);
|
||||
|
||||
$order_document = null;
|
||||
|
||||
foreach ($order_other_documents as $order_other_document) {
|
||||
|
||||
if ($order_other_document['key'] === $document_key) {
|
||||
|
||||
$order_document = $order_other_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 document related to order item
|
||||
*
|
||||
@@ -62,7 +136,7 @@ class Wiaas_Document_Download {
|
||||
* @param $type
|
||||
* @param $document_key
|
||||
*/
|
||||
public static function download_order_item_document($order_id, $item_id, $type, $document_key) {
|
||||
public static function download_order_item_document($order_id, $item_id, $document_key) {
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order) {
|
||||
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
|
||||
@@ -77,7 +151,7 @@ class Wiaas_Document_Download {
|
||||
|
||||
$order_document = null;
|
||||
foreach ($item_documents as $item_document) {
|
||||
if ($item_document['key'] === $document_key && $item_document['type'] === $type) {
|
||||
if ($item_document['key'] === $document_key) {
|
||||
$order_document = $item_document;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -113,8 +113,6 @@ class Wiaas_Document {
|
||||
return false;
|
||||
}
|
||||
|
||||
error_log(gettype($visible));
|
||||
|
||||
update_post_meta($id, '_wiaas_doc_versions', array( $path ));
|
||||
|
||||
self::set_is_doc_visible($id, $visible);
|
||||
|
||||
@@ -26,6 +26,17 @@ function wiaas_documents_upload_dir() {
|
||||
* @return string
|
||||
*/
|
||||
function wiaas_get_document_version_path($version) {
|
||||
|
||||
// documents uploaded with gravity forms have relevant path to form entry upload folder
|
||||
if (strpos($version, 'gravity_forms') !== false) {
|
||||
|
||||
$wp_uploads = wp_upload_dir();
|
||||
$wp_uploads_dir = $wp_uploads['basedir'];
|
||||
|
||||
return $wp_uploads_dir . '/' . $version;
|
||||
|
||||
}
|
||||
|
||||
return wiaas_documents_upload_dir() . '/' . $version;
|
||||
}
|
||||
|
||||
@@ -182,9 +193,60 @@ function wiaas_get_standard_package_order_item_documents($order, $package_item_i
|
||||
|
||||
return array_map(function($doc) {
|
||||
// append document extension and name information
|
||||
$doc['extension'] = wiaas_get_doc_version_extension($doc['version']);
|
||||
$doc['extension'] = isset($doc['extension']) ? $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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve documents for order item
|
||||
*
|
||||
* @param $order_item
|
||||
* @param string|null $doc_type
|
||||
*
|
||||
* @return array {
|
||||
* $param string key Unique key used for frontend downloand
|
||||
* $param string name Document name visible in download link
|
||||
* $param string version Relative path from upload directory to physical document file
|
||||
* $param string type Document type
|
||||
*
|
||||
* @reference Wiaas_Document
|
||||
* }
|
||||
*/
|
||||
function wiaas_get_order_item_documents($order_item, $doc_type = null) {
|
||||
|
||||
$documents = empty($order_item['wiaas_documents']) ? array() : $order_item['wiaas_documents'];
|
||||
|
||||
if (empty($doc_type)) {
|
||||
return $documents;
|
||||
}
|
||||
|
||||
$filtered_documents = array();
|
||||
|
||||
foreach ($documents as $document) {
|
||||
|
||||
if ($document['type'] === $doc_type) {
|
||||
$filtered_documents[] = $document;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered_documents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve order other documents (not binded to any order item)
|
||||
*
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
function wiaas_get_order_other_documents($order_id) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$documents = $order->get_meta('_wiaas_other_documents', true);
|
||||
|
||||
return empty($documents) ? array() : $documents;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user