Compare commits
301 Commits
templates
...
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 | ||
|
|
ddf7d4452c | ||
|
|
554dc37a2d | ||
|
|
afab22a30b | ||
|
|
dc1a1c64d2 | ||
|
|
2d7b6c55e6 | ||
|
|
d7103df6dc | ||
|
|
b7ac53d195 | ||
|
|
f14d35b1aa | ||
|
|
e810dd086a | ||
|
|
8789eb1426 | ||
|
|
bd724d12c2 | ||
|
|
803e62ea69 | ||
|
|
a5168d3487 | ||
|
|
d7c34c3b0b | ||
|
|
55dc87e174 | ||
|
|
9f3fe44bb1 | ||
|
|
ba2629ca22 | ||
|
|
14eda981b7 | ||
|
|
8df4ec3dc7 | ||
|
|
17acc9d96a | ||
|
|
4bdad78ed8 | ||
|
|
f3d911e5b1 | ||
|
|
e4a7b28301 | ||
|
|
84ba574bcb | ||
|
|
4f31cc94e8 | ||
|
|
bc74b504db | ||
|
|
8d2b1e52b4 | ||
|
|
63c1ee945f | ||
|
|
1e9f959b16 | ||
|
|
afe4ac1676 | ||
|
|
c7e8a526e0 | ||
|
|
ac9c89e8eb | ||
|
|
ea63870704 | ||
|
|
accc359cbe | ||
|
|
57d61918b9 | ||
|
|
a830a47d31 | ||
|
|
61109e9bf0 | ||
|
|
c6a1f9837d | ||
|
|
089bea5ce4 | ||
|
|
b53fbe5402 | ||
|
|
84cd11f9c9 | ||
|
|
a2656173c2 | ||
|
|
9a8e05e341 | ||
|
|
246788207b | ||
|
|
360b24c6ec | ||
|
|
d11860223f | ||
|
|
c537557daf | ||
|
|
c102b6a5ad | ||
|
|
f41252ea23 | ||
|
|
c5c07cbfae | ||
|
|
7ceac97fed | ||
|
|
ab9ee2cb0d | ||
|
|
451f9fb2eb | ||
|
|
b028fb3f04 | ||
|
|
3ad210f883 | ||
|
|
4c760b12c3 | ||
|
|
ea9a47fd39 | ||
|
|
925896c469 | ||
|
|
2cd4a77a34 | ||
|
|
174517a161 | ||
|
|
dc1311340f | ||
|
|
f1c99c28ae | ||
|
|
6f6fb1115a | ||
|
|
93d03a96ee | ||
|
|
21d96a0e55 | ||
|
|
6afffc7eca | ||
|
|
5f744f016e | ||
|
|
0e59272689 | ||
|
|
aa8aa42164 | ||
|
|
415c5d8747 | ||
|
|
12805678b1 | ||
|
|
e1a1b4dc49 | ||
|
|
4ecadc8bcc | ||
|
|
eab040b13d | ||
|
|
fdc01b974e | ||
|
|
11c26aeee1 | ||
|
|
9c4539acfe | ||
|
|
8cc2a7c8bc | ||
|
|
c13983d6df | ||
|
|
0065b25fef | ||
|
|
d8c38ec089 | ||
|
|
cbf1de3403 | ||
|
|
41e92e2390 | ||
|
|
5da2353d04 | ||
|
|
4159f12854 | ||
|
|
3fa75daafd | ||
|
|
c637880245 | ||
|
|
fa2b691996 | ||
|
|
393158808a | ||
|
|
0787cf834f | ||
|
|
522417ca28 | ||
|
|
498f5526a9 | ||
|
|
31115b7c6a | ||
|
|
af2da3eed0 | ||
|
|
d36398f2ab | ||
|
|
32379f7f47 | ||
|
|
82e4579e88 | ||
|
|
b93aed107b | ||
|
|
5d91576fb7 | ||
|
|
c322c8ac78 | ||
|
|
90402d3e1d | ||
|
|
84916a01ed | ||
|
|
b98f3c979c | ||
|
|
a901da55fc | ||
|
|
8a9af7ed8c | ||
|
|
39cb851a55 | ||
|
|
e6e487f312 | ||
|
|
d26569a8be | ||
|
|
aae23e4ea3 | ||
|
|
a79ef1044c | ||
|
|
b974eab225 | ||
|
|
b3cff5d095 | ||
|
|
4ce7b86ea9 | ||
|
|
bc61e2e706 | ||
|
|
9da31990fd | ||
|
|
f63e118579 | ||
|
|
cf92f62703 | ||
|
|
6e5f2af5a3 | ||
|
|
7c2a77b75d | ||
|
|
85deb1d9f8 | ||
|
|
cae148ebce |
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
|
||||
@@ -2,6 +2,8 @@ FROM php:7.0-apache
|
||||
|
||||
ARG API_URL
|
||||
|
||||
ARG WIAAS_CUSTOMER_INTERFACE
|
||||
|
||||
ARG MYSQL_DATABASE
|
||||
ARG MYSQL_USER
|
||||
ARG MYSQL_PASSWORD
|
||||
@@ -16,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}
|
||||
@@ -35,7 +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}
|
||||
|
||||
RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo
|
||||
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 libpng-dev
|
||||
|
||||
COPY docker/php/composer.phar /usr/local/bin/composer
|
||||
RUN chmod 755 /usr/local/bin/composer
|
||||
@@ -46,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
|
||||
|
||||
@@ -55,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
|
||||
|
||||
|
||||
64
backend/app/plugins/wiaas/assets/css/menu.css
Normal file
64
backend/app/plugins/wiaas/assets/css/menu.css
Normal file
@@ -0,0 +1,64 @@
|
||||
#wpadminbar #wp-admin-bar-wiaas-view-as .ab-icon {
|
||||
float: none;
|
||||
margin-left: 10px;
|
||||
color: rgba(240,245,250,0.7) !important;
|
||||
}
|
||||
#wpadminbar #wp-admin-bar-wiaas-view-as .ab-label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
#wpadminbar #wp-admin-bar-wiaas-view-as a:not(:hover) .ab-icon:before {
|
||||
color: rgba(240,245,250,0.7) !important;
|
||||
}
|
||||
|
||||
#createuser .acf-taxonomy-field, #your-profile .acf-taxonomy-field {
|
||||
width: 25em;
|
||||
}
|
||||
|
||||
.wc-order-preview footer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
11
backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css
Normal file
11
backend/app/plugins/wiaas/assets/css/wiaas-admin-cl.css
Normal file
@@ -0,0 +1,11 @@
|
||||
#posts-filter .tablenav .actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#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 {
|
||||
@@ -120,4 +110,25 @@
|
||||
|
||||
#wiaas_package_option_groups_list .wiaas_option_group h3 {
|
||||
background-color:#F9F9F9;
|
||||
}
|
||||
|
||||
#createuser label[for="role"], #createuser label[for="url"], #createuser #role, #createuser #url{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#your-profile label[for="role"], #your-profile label[for="url"],#your-profile #role, #your-profile #url{
|
||||
display: none;
|
||||
}
|
||||
|
||||
#adminmenu #toplevel_page_wiaas-cl-packages div.wp-menu-image::before {
|
||||
font-family: WooCommerce!important;
|
||||
content: '\e006';
|
||||
}
|
||||
|
||||
.wiaas-package-error {
|
||||
color: #a00 !important;
|
||||
}
|
||||
|
||||
table.wp-list-table .column-price {
|
||||
width: auto !important;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.wc-order-preview-address {
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
|
||||
$('#tabs').each(function() {
|
||||
var disabled = $( this ).data('disabled') || '';
|
||||
|
||||
$( this ).tabs({
|
||||
disabled: [ disabled ]
|
||||
});
|
||||
});
|
||||
|
||||
$('#wiaas_add_cl_customer_extras').click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var customer_id = $('#wiaas_cl_customers').val();
|
||||
|
||||
if (!customer_id || customer_id === '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(window.ajaxurl, {
|
||||
action: 'wiaas_create_cl_customer_extras',
|
||||
_ajax_nonce: $('#wiaas_create_cl_customer_extras_nonce').val(),
|
||||
customer_id: customer_id,
|
||||
package_id: $('#wiaas_cl_package_id').val()
|
||||
}).done( function (result) {
|
||||
$('#tabs-2').append(result);
|
||||
|
||||
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', true );
|
||||
});
|
||||
|
||||
$('#wiaas_cl_customers').val('0');
|
||||
});
|
||||
|
||||
$('#wiaas_package_extras').delegate('.wiaas_remove_cl_extras', 'click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var customer_id = $( this ).data('customer_id');
|
||||
|
||||
$('#extras_customer_' + customer_id).remove();
|
||||
|
||||
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', false );
|
||||
|
||||
$('#wiaas_cl_customers').val('0');
|
||||
});
|
||||
|
||||
$('#wiaas_package_extras').delegate('.wiaas-cl-extra-input', 'change', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var val = parseFloat($( this ).val());
|
||||
var target = '#' + $( this).data('target');
|
||||
|
||||
if (isNaN(val)) {
|
||||
|
||||
$(target).val('Invalid!');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var type = $( this).data('type');
|
||||
|
||||
if (type === 'fixed') {
|
||||
$(target).text( $(target).data('base') + val);
|
||||
}
|
||||
|
||||
if (type === 'recurrent' || type === 'services') {
|
||||
$(target).data(type, val);
|
||||
|
||||
$(target).text( $(target).data('base') + $(target).data('recurrent') + $(target).data('services'));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
});
|
||||
@@ -1,76 +1,23 @@
|
||||
jQuery(function ($) {
|
||||
|
||||
var $edit_in_cart = $('.bundle_edit_in_cart'),
|
||||
$group_mode_select = $('select#_wc_pb_group_mode'),
|
||||
$bundled_products_panel = $('#bundled_product_data'),
|
||||
$bundled_products_toolbar = $bundled_products_panel.find('.toolbar'),
|
||||
$template_products_container_hardware = $('.wiaas-template-items_hardware'),
|
||||
$template_products_container_software = $('.wiaas-template-items_software'),
|
||||
$template_products_container_services = $('.wiaas-template-items_services'),
|
||||
$template_products_container_isntallation = $('.wiaas-template-items_installation'),
|
||||
var $template_categories_container_hardware = $('.wiaas-template-items_hardware'),
|
||||
$template_categories_container_software = $('.wiaas-template-items_software'),
|
||||
$template_categories_container_services = $('.wiaas-template-items_services'),
|
||||
$template_categories_container_isntallation = $('.wiaas-template-items_installation'),
|
||||
|
||||
$template_products = $('.wc-bundled-item',
|
||||
$template_products_container_services,
|
||||
$template_products_container_software,
|
||||
$template_products_container_hardware,
|
||||
$template_products_container_isntallation),
|
||||
$template_categories = $('.wc-bundled-item',
|
||||
$template_categories_container_services,
|
||||
$template_categories_container_software,
|
||||
$template_categories_container_hardware,
|
||||
$template_categories_container_isntallation),
|
||||
|
||||
$template_search_hardware = $('#wiaastemplate_products_hardware'),
|
||||
$template_search_software = $('#wiaastemplate_products_software'),
|
||||
$template_search_services = $('#wiaastemplate_products_services'),
|
||||
$template_search_installation = $('#wiaastemplate_products_installation'),
|
||||
bundled_product_objects = {},
|
||||
bundled_products_add_count = $template_products.length,
|
||||
block_params = {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
};
|
||||
template_category_objects = {},
|
||||
template_category_add_count = $template_categories.length;
|
||||
|
||||
$.fn.wc_bundles_select2 = function () {
|
||||
$(document.body).trigger('wc-enhanced-select-init');
|
||||
};
|
||||
|
||||
// Bundle type move stock msg up.
|
||||
$('.bundle_stock_msg').appendTo('._manage_stock_field .description');
|
||||
|
||||
// Simple type options are valid for bundles.
|
||||
$('.show_if_simple:not(.hide_if_bundle)').addClass('show_if_bundle');
|
||||
|
||||
$('body').on('woocommerce-product-type-change', function (event, select_val) {
|
||||
|
||||
if ('bundle' === select_val) {
|
||||
|
||||
$('.show_if_external').hide();
|
||||
$('.show_if_bundle').show();
|
||||
|
||||
$('input#_manage_stock').change();
|
||||
|
||||
$('#_nyp').change();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$group_mode_select.change(function () {
|
||||
if ($.inArray($group_mode_select.val(), wc_bundles_admin_params.group_modes_with_parent) === -1) {
|
||||
$edit_in_cart.hide();
|
||||
} else {
|
||||
$edit_in_cart.show();
|
||||
}
|
||||
});
|
||||
|
||||
// Downloadable support.
|
||||
$('input#_downloadable').change(function () {
|
||||
$('select#product-type').change();
|
||||
});
|
||||
|
||||
// Trigger product type change.
|
||||
$('select#product-type').change();
|
||||
|
||||
// Trigger group mode change.
|
||||
$group_mode_select.change();
|
||||
|
||||
|
||||
init_event_handlers();
|
||||
@@ -81,52 +28,50 @@ jQuery(function ($) {
|
||||
$template_search_hardware
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('hardware', $template_search_hardware, $template_products_container_hardware)
|
||||
addSearchedTemplateCategory('hardware', $template_search_hardware, $template_categories_container_hardware)
|
||||
});
|
||||
|
||||
$template_search_software
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('software', $template_search_software, $template_products_container_software)
|
||||
addSearchedTemplateCategory('software', $template_search_software, $template_categories_container_software)
|
||||
});
|
||||
|
||||
|
||||
$template_search_installation
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('services', $template_search_installation, $template_products_container_isntallation)
|
||||
addSearchedTemplateCategory('installation', $template_search_installation, $template_categories_container_isntallation)
|
||||
});
|
||||
|
||||
|
||||
$template_search_services
|
||||
|
||||
.on('change', function () {
|
||||
addSearchedProduct('installation', $template_search_services, $template_products_container_services)
|
||||
addSearchedTemplateCategory('services', $template_search_services, $template_categories_container_services)
|
||||
});
|
||||
|
||||
|
||||
function addSearchedProduct(options, search, container) {
|
||||
var bundled_product_ids = search.val(),
|
||||
bundled_product_id = bundled_product_ids && bundled_product_ids.length > 0 ? bundled_product_ids.shift() : false;
|
||||
function addSearchedTemplateCategory(options, search, container) {
|
||||
var template_category_ids = search.val(),
|
||||
template_category_id = template_category_ids && template_category_ids.length > 0 ? template_category_ids.shift() : false;
|
||||
|
||||
var template_category_title =search.text();
|
||||
|
||||
if (!bundled_product_id) {
|
||||
if (!template_category_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
search.val([]).change();
|
||||
|
||||
$bundled_products_panel.block(block_params);
|
||||
|
||||
bundled_products_add_count++;
|
||||
template_category_add_count++;
|
||||
|
||||
var data = {
|
||||
action: 'wiaas_add_template_product',
|
||||
post_id: woocommerce_admin_meta_boxes.post_id,
|
||||
id: bundled_products_add_count,
|
||||
id: template_category_add_count,
|
||||
title: template_category_title,
|
||||
product_id: bundled_product_id,
|
||||
template_category_id: template_category_id,
|
||||
security: wc_bundles_admin_params.add_bundled_product_nonce,
|
||||
options: options,
|
||||
};
|
||||
@@ -140,13 +85,11 @@ jQuery(function ($) {
|
||||
container.append(response.markup);
|
||||
|
||||
var $added = $('.wiaas-template-item', container).last(),
|
||||
added_id = 'bundled_item_' + bundled_products_add_count;
|
||||
added_id = 'bundled_item_' + template_category_add_count;
|
||||
|
||||
$added.data('bundled_item_id', added_id);
|
||||
$added.wc_bundles_select2();
|
||||
|
||||
$bundled_products_panel.trigger('wc-bundles-added-bundled-product');
|
||||
|
||||
} else if (response.message !== '') {
|
||||
window.alert(response.message);
|
||||
}
|
||||
@@ -161,8 +104,6 @@ jQuery(function ($) {
|
||||
}
|
||||
search.text('');
|
||||
|
||||
$bundled_products_panel.unblock();
|
||||
|
||||
});
|
||||
|
||||
}, 250);
|
||||
@@ -170,7 +111,7 @@ jQuery(function ($) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$template_products_container_isntallation
|
||||
$template_categories_container_isntallation
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -181,15 +122,13 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_products_container_hardware
|
||||
$template_categories_container_hardware
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -200,15 +139,13 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_products_container_software
|
||||
$template_categories_container_software
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -219,15 +156,13 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
});
|
||||
|
||||
$template_products_container_services
|
||||
$template_categories_container_services
|
||||
|
||||
// Remove Item.
|
||||
.on('click', 'a.remove_row', function (e) {
|
||||
@@ -238,9 +173,7 @@ jQuery(function ($) {
|
||||
$el.find('*').off();
|
||||
$el.remove();
|
||||
|
||||
delete bundled_product_objects[el_id];
|
||||
|
||||
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
|
||||
delete template_category_objects[el_id];
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
@@ -0,0 +1,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();
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Wiaas_Admin_CM_Packages
|
||||
*
|
||||
*/
|
||||
class Wiaas_Admin_CL_Packages {
|
||||
|
||||
/**
|
||||
* Handles output of Commercial Lead packages page in admin panel.
|
||||
*
|
||||
* Shows list of packages available for sale and packages sold by current commercial lead.
|
||||
* Enables adding package to commercial lead catalogue and setting package specific prices
|
||||
* for current commercial lead.
|
||||
*
|
||||
*/
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
|
||||
|
||||
add_action( 'admin_head', array( __CLASS__, 'menu_highlight' ) );
|
||||
|
||||
add_filter( 'manage_product_posts_columns', array( __CLASS__, 'define_list_table_products_columns' ), 999 );
|
||||
|
||||
add_filter( 'bulk_actions-edit-product', array( __CLASS__, 'define_list_table_products_bulk_actions' ), 999 );
|
||||
|
||||
add_filter( 'views_edit-product', array( __CLASS__, 'define_list_table_products_views' ), 999 );
|
||||
|
||||
add_filter( 'post_row_actions', array( __CLASS__, 'define_list_table_products_row_actions' ), 999, 2 );
|
||||
|
||||
add_filter( 'list_table_primary_column', array( __CLASS__, 'define_list_table_products_primary_column' ), 999, 2 );
|
||||
|
||||
add_action( 'manage_product_posts_custom_column', array( __CLASS__, 'render_list_table_products_columns' ), 10, 2 );
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
|
||||
}
|
||||
|
||||
public static function add_cl_packages_menu() {
|
||||
add_submenu_page(
|
||||
'edit.php?post_type=product',
|
||||
__( 'Products', 'wiaas' ),
|
||||
null,
|
||||
'manage_wiaas_cl_products',
|
||||
'wiaas-cl-package',
|
||||
array(__CLASS__, 'output_package')
|
||||
);
|
||||
}
|
||||
|
||||
public static function menu_highlight() {
|
||||
global $parent_file;
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ($screen->id === 'admin_page_wiaas-cl-product') {
|
||||
|
||||
$parent_file = 'edit.php?post_type=product';
|
||||
}
|
||||
}
|
||||
|
||||
public static function output_package() {
|
||||
wp_enqueue_script( 'jquery-ui-tabs' );
|
||||
|
||||
$package_id = absint( $_GET['cl_package_id'] );
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
if (!$package) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($_POST['wiaas_save_cl_extras_nonce']) && ! empty($_POST['cl_extras'])) {
|
||||
if (wp_verify_nonce($_POST['wiaas_save_cl_extras_nonce'], 'wiaas_save_cl_extras')) {
|
||||
self::_handle_cl_extras_update($package_id);
|
||||
}
|
||||
}
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
|
||||
$bundled_items_per_category = array();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$category = Wiaas_Product_Category::get_category($bundled_item->product);
|
||||
if (isset($category)) {
|
||||
if ($category ==='hardware' || $category === 'software') {
|
||||
$category = 'products';
|
||||
}
|
||||
$bundled_items_per_category[$category] ?: array();
|
||||
$bundled_items_per_category[$category][] = $bundled_item;
|
||||
}
|
||||
}
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$cl_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
$cl_extras = Wiaas_Package_CL_Pricing::get_extras($cl_id, $package_id);
|
||||
|
||||
$has_default_cl_extras = ! empty($cl_extras);
|
||||
|
||||
// default values for catalogue package
|
||||
if (! $has_default_cl_extras) {
|
||||
$cl_extras = array();
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
$cl_extras[$type.'_default'] = array(
|
||||
'visible' => true,
|
||||
'fixed' => 0,
|
||||
'services' => 0,
|
||||
'recurrent' => 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$package_cl_extra_types = array_keys($cl_extras);
|
||||
|
||||
$customer_ids_with_extras = array();
|
||||
foreach ($package_cl_extra_types as $package_cl_extra_type) {
|
||||
$customer_id_with_extras = explode('_customer_', $package_cl_extra_type)[1];
|
||||
|
||||
if (isset($customer_id_with_extras) && ($customer_id_with_extras = absint($customer_id_with_extras)) > 0) {
|
||||
$customer_ids_with_extras[] = $customer_id_with_extras;
|
||||
}
|
||||
}
|
||||
$customer_ids_with_extras = array_unique($customer_ids_with_extras);
|
||||
|
||||
require 'views/html-cl-package-details.php';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @section Customize display of list table products for commercial lead
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define columns for commercial lead view
|
||||
* @param array $columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_columns($columns) {
|
||||
$cl_columns = array();
|
||||
|
||||
$cl_columns['thumb'] = $columns['thumb'];
|
||||
$cl_columns['wiaas_cl_name'] = $columns['name'];
|
||||
$cl_columns['taxonomy-product_tag'] = __( 'Reference', 'wiaas' );
|
||||
$cl_columns['taxonomy-package_type'] = __('Type', 'wiaas');
|
||||
$cl_columns['taxonomy-package_status'] = __('Status', 'wiaas');
|
||||
$cl_columns['taxonomy-product_country'] = $columns['taxonomy-product_country'];
|
||||
$cl_columns['date'] = $columns['date'];
|
||||
|
||||
return $cl_columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide list table products bulk actions for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_bulk_actions() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide list table products views for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_views() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show only ID in table products views for commercial lead view
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function define_list_table_products_row_actions($actions, $post) {
|
||||
if ($post->post_type === 'product') {
|
||||
return array( 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $post->ID ) );
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define custom primary column in list table products for commercial lead view
|
||||
*
|
||||
* @param $default
|
||||
* @param $screen_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function define_list_table_products_primary_column($default, $screen_id) {
|
||||
if ( 'edit-product' === $screen_id ) {
|
||||
return 'wiaas_cl_name';
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
public static function render_list_table_products_columns($column, $post_id) {
|
||||
if ($column === 'wiaas_cl_name') {
|
||||
|
||||
$package = wc_get_product($post_id);
|
||||
|
||||
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-cl-package&cl_package_id=' . absint( $package->get_id() ) );
|
||||
|
||||
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) . '">' . esc_html( $package->get_title() ) . '</a></strong>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// PRIVATE HANDLERS
|
||||
|
||||
private static function _handle_cl_extras_update($package_id) {
|
||||
$cl_extras = wp_unslash($_POST['cl_extras']);
|
||||
|
||||
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
|
||||
|
||||
$posted_cl_extras = array();
|
||||
|
||||
foreach ($cl_extras as $cl_extra) {
|
||||
|
||||
$customer_id = isset($cl_extra['customer']) ? absint($cl_extra['customer']) : 0;
|
||||
$type = sanitize_key($cl_extra['type']);
|
||||
|
||||
$fixed_extra = isset($cl_extra['fixed']) ? floatval($cl_extra['fixed']) : 0;
|
||||
$services_extra = isset($cl_extra['services']) ? floatval($cl_extra['services']) : 0;
|
||||
$recurrent_extra = isset($cl_extra['recurrent']) ? floatval($cl_extra['recurrent']) : 0;
|
||||
|
||||
$extra_type = $customer_id > 0 ? $type.'_customer_'.$customer_id : $type.'_default';
|
||||
|
||||
if (in_array($type, $pay_types)) {
|
||||
$posted_cl_extras[$extra_type] = array(
|
||||
'type' => $type,
|
||||
'visible' => $cl_extra['visible'] === 'on',
|
||||
'fixed' => $fixed_extra,
|
||||
'services' => $services_extra,
|
||||
'recurrent' => $recurrent_extra,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Package_CL_Pricing::set_extras(
|
||||
wiaas_get_current_user_organization_id(),
|
||||
$package_id,
|
||||
$posted_cl_extras
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL_Packages::init();
|
||||
@@ -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,237 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
#tabs-navigation {
|
||||
height: 30px;
|
||||
}
|
||||
#tabs-navigation > li {
|
||||
float: left;
|
||||
line-height: 30px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#tabs-navigation > li.ui-state-active > a {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#tabs-navigation > li.ui-state-disabled > a {
|
||||
color: #ccc;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#tabs-navigation > li > a {
|
||||
text-decoration: none;
|
||||
padding: .5em;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead {
|
||||
background: #f2f2f2;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead td {
|
||||
vertical-align: middle;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > thead i {
|
||||
position: absolute;
|
||||
vertical-align: top;
|
||||
right: -8px;
|
||||
top: -8px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td:first-child {
|
||||
max-width: 100px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices > tbody > tr > td:nth-child(2) label {
|
||||
float: left;;
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
.wiaas-configured-prices input[type='text'] {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#managed_36 > td:nth-child(2) > div:last-child {
|
||||
position: relative;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
#managed_36 > td:nth-child(2) > div:last-child > span {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 70px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
</script>
|
||||
|
||||
<div class="wrap">
|
||||
<div id="poststuff">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
<div>
|
||||
<?php
|
||||
foreach ($bundled_items_per_category as $category => $category_bundled_items) {
|
||||
echo sprintf(
|
||||
'<strong style="text-transform: uppercase;" class="text-uppercase">%s (%s)</strong>',
|
||||
esc_attr( $category ),
|
||||
esc_attr(count($category_bundled_items)) );
|
||||
foreach ($category_bundled_items as $bundled_item) {
|
||||
$title = $bundled_item->product->get_title();
|
||||
echo sprintf( '<p>%s x %s</p>', esc_attr($bundled_item->get_quantity('max')), esc_attr( $title ) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="postbox-container-2" class="postbox-container">
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
<h1 style="padding: 0;"><?php echo $package->get_name(); ?></h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (! empty($package->get_short_description())) {
|
||||
?>
|
||||
<div class="postbox">
|
||||
<?php wp_editor( $package->get_short_description(), 'content', array(
|
||||
'_content_editor_dfw' => $_content_editor_dfw,
|
||||
'drag_drop_upload' => false,
|
||||
'media_buttons' => false,
|
||||
'quicktags' => false,
|
||||
'tabfocus_elements' => 'content-html',
|
||||
'tinymce' => array(
|
||||
'resize' => false,
|
||||
'wp_autoresize_on' => true,
|
||||
'add_unload_trigger' => false,
|
||||
'wp_keep_scroll_position' => ! $is_IE,
|
||||
'readonly'=> true,
|
||||
'toolbar' => false,
|
||||
),
|
||||
) ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="panel">
|
||||
|
||||
<div class="wrap">
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('EPR', 'wiaas') ?></strong>
|
||||
<span><?php esc_html_e('= Extra package recurrent commission', 'wiaas') ?></span>
|
||||
</div>
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('ESR') ?></strong>
|
||||
<span><?php esc_html_e('= Extra services and support recurrent commission', 'wiaas') ?></span>
|
||||
</div>
|
||||
<div>
|
||||
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
|
||||
<strong><?php esc_html_e('Extra commission', 'wiaas') ?></strong>
|
||||
<span><?php esc_html_e('= EPR + ESR', 'wiaas') ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="tabs" data-disabled="<?php echo $has_default_cl_extras ? '' : '1' ; ?>">
|
||||
<ul id="tabs-navigation">
|
||||
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
|
||||
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
|
||||
</ul>
|
||||
|
||||
<form id="wiaas_package_extras" action="" method="post">
|
||||
<input type="hidden" name="page" value="wiaas-cl-package"/>
|
||||
<input type="hidden" id="wiaas_cl_package_id" name="cl_package_id" value="<?php echo esc_attr($package->get_id()) ?>"/>
|
||||
|
||||
<div id="tabs-1">
|
||||
|
||||
<?php require 'html-cl-package-prices.php'; ?>
|
||||
|
||||
</div>
|
||||
<div id="tabs-2">
|
||||
|
||||
<div class="form-group">
|
||||
<select id="wiaas_cl_customers" class="form-control">
|
||||
<option selected value="0" disabled> Select customer ...</option>
|
||||
<?php
|
||||
$customers = wiaas_get_customers();
|
||||
foreach ($customers as $id => $name) {
|
||||
// shik current organization if it has role of customer
|
||||
if ($id === $cl_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
?>
|
||||
<option
|
||||
<?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
|
||||
id="wiaas_cl_customer_<?php esc_attr_e($id, 'wiaas') ?>"
|
||||
value="<?php esc_attr_e($id, 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($name, 'wiaas') ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<?php wp_nonce_field( 'wiaas_create_cl_customer_extras', 'wiaas_create_cl_customer_extras_nonce' ); ?>
|
||||
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// Render customer specific prices if any
|
||||
foreach ($customer_ids_with_extras as $customer_id) {
|
||||
require 'html-cl-package-prices.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php wp_nonce_field( 'wiaas_save_cl_extras', 'wiaas_save_cl_extras_nonce' ); ?>
|
||||
<?php submit_button( __( 'Save', 'wiaas' ), 'primary', 'submit' ); ?>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<br class="clear" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
|
||||
|
||||
?>
|
||||
|
||||
<table id="<?php esc_attr_e($id, 'wiaas') ?>" style="margin-top: 20px;" class="widefat wiaas-configured-prices">
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
echo '<h4>'. esc_html(wiaas_get_organization_name($customer_id)). '</h4>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td><?php esc_html_e('Minimal sell price', 'wiaas') ?></td>
|
||||
<td><?php esc_html_e('Extra commision', 'wiaas') ?></td>
|
||||
<td><?php esc_html_e('Default price', 'wiaas') ?></td>
|
||||
<td><?php esc_html_e('Visible?', 'wiaas') ?>
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
?>
|
||||
<i
|
||||
data-customer_id="<?php esc_attr_e($customer_id, 'wiaas') ?>"
|
||||
class="dashicons dashicons-dismiss wiaas_remove_cl_extras"
|
||||
></i>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
|
||||
$extra_type = isset($customer_id) ? $type.'_customer_'.$customer_id : $type.'_default';
|
||||
|
||||
?>
|
||||
<input
|
||||
type="hidden"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][type]"
|
||||
value="<?php esc_attr_e($type, 'wiaas')?>"
|
||||
>
|
||||
|
||||
<?php
|
||||
if (isset($customer_id)) {
|
||||
?>
|
||||
<input
|
||||
type="hidden"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][customer]"
|
||||
value="<?php esc_attr_e($customer_id, 'wiaas')?>"
|
||||
>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<tr id="<?php esc_attr_e($extra_type, 'wias')?>">
|
||||
<td>
|
||||
<strong><?php esc_html_e($configured_price['payment_type']) ?></strong>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<div class="form-control">
|
||||
<label>Fixed:</label>
|
||||
<input type="text" value="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>" readonly>
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label>Monthly:</label>
|
||||
<input type="text" value="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>" readonly>
|
||||
<?php
|
||||
if($configured_price['package_pay_period'] > 0) {
|
||||
echo sprintf( '<span>(%s for services)</span>', esc_attr( $configured_price['minimal_services_price'] ) );
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="fixed"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][fixed]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['fixed'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
</div>
|
||||
<?php
|
||||
if($configured_price['package_pay_period'] > 0) {
|
||||
?>
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_recurrent_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="recurrent"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][recurrent]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
<label><?php esc_html_e('(EPR)', 'wiaas') ?></label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="form-control">
|
||||
<label>+</label>
|
||||
<input
|
||||
class="wiaas-cl-extra-input"
|
||||
data-target="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-type="services"
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][services]"
|
||||
value="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||
type="text"
|
||||
>
|
||||
<label><?php esc_html_e('(ESR)', 'wiaas') ?></label>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div> =
|
||||
<strong
|
||||
id="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-base="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>"
|
||||
>
|
||||
<?php esc_html_e($configured_price['minimal_fixed_price'] + $cl_extras[$extra_type]['fixed'], 'wiaas') ?>
|
||||
</strong>
|
||||
</div>
|
||||
<div> =
|
||||
<strong
|
||||
id="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
|
||||
data-base="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>"
|
||||
data-recurrent="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
|
||||
data-services="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
|
||||
>
|
||||
<?php
|
||||
esc_html_e($configured_price['minimal_recurrent_price'] +
|
||||
$cl_extras[$extra_type]['recurrent'] +
|
||||
$cl_extras[$extra_type]['services'], 'wiaas')
|
||||
?>
|
||||
</div>
|
||||
</td>
|
||||
<td class="form-group">
|
||||
<input
|
||||
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][visible]"
|
||||
<?php checked($cl_extras[$extra_type]['visible'], true, true) ?>
|
||||
type="checkbox"
|
||||
>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
add_action('wp_ajax_wiaas_create_cl_customer_extras', 'wiaas_ajax_create_cl_customer_extras');
|
||||
|
||||
function wiaas_ajax_create_cl_customer_extras() {
|
||||
check_ajax_referer('wiaas_create_cl_customer_extras');
|
||||
|
||||
$customer_id = absint($_POST['customer_id']);
|
||||
$package_id = absint($_POST['package_id']);
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
|
||||
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
$cl_extras = array();
|
||||
|
||||
foreach ($configured_prices as $type => $configured_price) {
|
||||
$cl_extras[$type.'_customer_'.$customer_id] = array(
|
||||
'type' => $type,
|
||||
'visible' => true,
|
||||
'fixed' => 0,
|
||||
'services' => 0,
|
||||
'recurrent' => 0
|
||||
);
|
||||
}
|
||||
|
||||
require_once 'views/html-cl-package-prices.php';
|
||||
|
||||
die();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,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();
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Wiaas_Admin_CL {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_action('init', array(__CLASS__, 'init_admin_cl'));
|
||||
}
|
||||
|
||||
public static function init_admin_cl() {
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
$role = $current_user->roles[0];
|
||||
|
||||
$is_cl = $role === 'commercial_lead';
|
||||
|
||||
if ($is_cl) {
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-customers.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-orders.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_script( 'wiaas_admin_cl_packages', $plugin_url . '/assets/js/wiaas-admin-cl-packages.js' );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_cl', $plugin_url . '/assets/css/wiaas-admin-cl.css' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_CL::init();
|
||||
@@ -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();
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Documents {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/documents/class-wiaas-admin-product-documents.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/documents/class-wiaas-admin-document-editor.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/documents/wiaas-admin-document-ajax.php';
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Documents::init();
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Order_Projects {
|
||||
|
||||
public static function init() {
|
||||
|
||||
// Add is available fields to create and edit forms
|
||||
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
|
||||
add_action( 'shop_order_project_edit_form_fields', array( __CLASS__, 'edit_is_available_field' ) );
|
||||
|
||||
// Add is available column
|
||||
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'update_table_headers' ) );
|
||||
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'update_table_column_content' ), 10, 3 );
|
||||
|
||||
// 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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlighting orders menu when shop orders page selected
|
||||
*/
|
||||
public static function admin_menu_highlight() {
|
||||
global $plugin_page;
|
||||
|
||||
if ( isset( $_GET['taxonomy'] ) && ( $_GET['taxonomy'] === 'shop_order_project' ) ) {
|
||||
$plugin_page = 'edit.php?post_type=shop_order';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add is available field to order project creation form
|
||||
*/
|
||||
public static function add_is_available_field() {
|
||||
?>
|
||||
<div class="form-field form-required">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="postform"
|
||||
style="float:left; margin-top: 4px; margin-right: 10px;"
|
||||
id="is_available"
|
||||
name="is_available"
|
||||
/>
|
||||
<label for="is_available"><?php _e( 'Is Available?', 'wiaas' ); ?></label>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add is available field to order project edit form
|
||||
* @param $order_project
|
||||
*/
|
||||
public static function edit_is_available_field($order_project) {
|
||||
?>
|
||||
<tr class="form-field">
|
||||
<th scope="row" valign="top"><label><?php _e( 'Is Available?', 'wiaas' ); ?></label></th>
|
||||
<td>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="checkbox"
|
||||
id="is_available"
|
||||
name="is_available"
|
||||
<?php
|
||||
checked( true, Wiaas_Order_Project::is_order_project_available($order_project), true )
|
||||
?>
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Update table headers for order projects
|
||||
* Will add `is available` and `wiaas count` columns and remove default count column
|
||||
*
|
||||
* @param array $columns Available order project table headers
|
||||
*
|
||||
* @return array Edited order project table headers
|
||||
*/
|
||||
public static function update_table_headers($columns) {
|
||||
$columns['wiaas_is_available'] = __( 'Is Available?', 'wiaas' );
|
||||
|
||||
$columns['wiaas_count'] = __('Count', 'wiaas');
|
||||
|
||||
unset($columns['posts']);
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render content for order project table column
|
||||
* Will add content for `is available` and `wiaas count` columns
|
||||
*
|
||||
* @param string $columns Row content for order projects table
|
||||
* @param string $column Current column header
|
||||
* @param int $id Order project id
|
||||
*
|
||||
* @return string Edited row content with appended is available info
|
||||
*/
|
||||
public static function update_table_column_content($columns, $column, $id) {
|
||||
if ($column === 'wiaas_is_available') {
|
||||
$is_available = Wiaas_Order_Project::is_order_project_available($id);
|
||||
$columns .= $is_available ? 'Yes' : 'No';
|
||||
}
|
||||
|
||||
if ($column === 'wiaas_count') {
|
||||
$term = get_term($id, 'shop_order_project');
|
||||
$args = array(
|
||||
'shop_order_project' => $term->slug,
|
||||
'post_type' => 'shop_order'
|
||||
);
|
||||
$columns .= "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$term->count</a>";
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save posted is available field for created or edited order project
|
||||
* @param $term_id
|
||||
* @param string $tt_id
|
||||
* @param string $taxonomy
|
||||
*/
|
||||
public static function save_is_available_field($term_id, $tt_id = '', $taxonomy = '') {
|
||||
if ( 'shop_order_project' === $taxonomy ) {
|
||||
Wiaas_Order_Project::set_is_order_project_available($term_id, $_POST['is_available'] === 'on');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Order_Projects::init();
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Organization {
|
||||
|
||||
public static function init() {
|
||||
// role switcher for organization
|
||||
add_action( 'admin_bar_menu', array( __CLASS__, 'add_role_switcher_menu' ), 10, 2 );
|
||||
|
||||
// change user role if requested
|
||||
add_action('admin_init', array(__CLASS__, 'maybe_change_user_role'));
|
||||
|
||||
add_filter('manage_users_columns', array(__CLASS__, 'manage_users_table_columns'));
|
||||
add_filter('views_users', array(__CLASS__, 'hide_users_table_list_navigation'));
|
||||
|
||||
add_filter('get_role_list', array(__CLASS__, 'get_role_list_for_user'), 10, 2);
|
||||
|
||||
// hide woocommerce meta fields form customer user profile
|
||||
add_filter('woocommerce_customer_meta_fields', array(__CLASS__, 'hide_woocommerce_customer_fields'));
|
||||
|
||||
// save related customers when organization form data has been saved by acf
|
||||
add_action('acf/save_post', array(__CLASS__, 'maybe_save_related_customers'), 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() {
|
||||
return array();
|
||||
}
|
||||
|
||||
public static function hide_users_table_list_navigation() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve only customer organization as options to link customers to commercial lead
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_customer_organizations($args) {
|
||||
|
||||
$args['meta_key'] = '_wiaas_organization_roles';
|
||||
$args['meta_value'] = 'customer';
|
||||
$args['meta_compare'] = 'LIKE';
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves related customers if organization new/edit form has been submited
|
||||
* Customer ids are collected from posted data of linked customers acf field and saved
|
||||
*
|
||||
* @param string $id in format `term_{$organization_id}`
|
||||
*/
|
||||
public static function maybe_save_related_customers($id) {
|
||||
if ($_POST['taxonomy'] === Wiaas_User_Organization::TAXONOMY_NAME && ! empty($_POST['acf'])) {
|
||||
|
||||
$field = get_field_object('_wiaas_organization_customers', $id);
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
$customer_organization_ids = $_POST['acf'][$field['key']];
|
||||
|
||||
$customer_organization_ids = is_array($customer_organization_ids) ?
|
||||
wp_parse_id_list($customer_organization_ids) :
|
||||
array();
|
||||
|
||||
Wiaas_Shop::set_shop_customers($id, $customer_organization_ids);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads related customers for linked customers acf field on organization edit form
|
||||
*
|
||||
* @param array $value
|
||||
* @param string $id in format `term_{$organization_id}`
|
||||
* @param array $field acf field details
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function load_related_customer_organizations($value, $id, $field) {
|
||||
//get organization id
|
||||
$id = absint(str_replace('term_', '', $id));
|
||||
|
||||
$customers = wp_list_pluck(
|
||||
Wiaas_Shop::get_shop_customers($id),
|
||||
'customer_id');
|
||||
|
||||
return $customers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render user organization roles as available user roles on user list
|
||||
* @param $role_list
|
||||
* @param $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get_role_list_for_user($role_list, $user) {
|
||||
$organization_id = wiaas_get_user_organization_id($user->ID);
|
||||
|
||||
if (! empty($organization_id)) {
|
||||
$organization_roles = wiaas_get_organization_roles($organization_id);
|
||||
|
||||
foreach ($organization_roles as $organization_role) {
|
||||
$role_list[$organization_role] = translate_user_role( wp_roles()->role_names[ $organization_role ] );
|
||||
}
|
||||
|
||||
if (! empty($organization_role)) {
|
||||
unset($role_list['none']);
|
||||
}
|
||||
}
|
||||
|
||||
return $role_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize columns for users table list view
|
||||
*
|
||||
* @param array $defaults
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_users_table_columns( $defaults = array() ) {
|
||||
|
||||
$defaults['role'] = __('Roles', 'wiaas');
|
||||
|
||||
unset($defaults['posts']);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds organization roles switcher menu to admin bar
|
||||
*
|
||||
* @param $admin_bar
|
||||
*/
|
||||
public static function add_role_switcher_menu($admin_bar) {
|
||||
if (is_super_admin()) {
|
||||
$roles = array( 'administrator' );
|
||||
} else {
|
||||
$organization_id = wiaas_get_current_user_organization_id();
|
||||
$roles = wiaas_get_organization_roles($organization_id);
|
||||
}
|
||||
|
||||
$user = wp_get_current_user();
|
||||
$current_role = $user->roles[0];
|
||||
|
||||
// Add menu item.
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'wiaas-view-as',
|
||||
'parent' => 'top-secondary',
|
||||
'title' => '<span>' .
|
||||
__( 'View as:', 'wiaas' ) .
|
||||
'</span>' .
|
||||
'<span style="margin-left: 6px; font-weight: bold;">'.
|
||||
__(translate_user_role( wp_roles()->role_names[ $current_role ] ), 'wiaas') .
|
||||
'</span>' .
|
||||
'<i style="float: right;" class="ab-icon dashicons dashicons-arrow-down"></i>',
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'title' => __( 'View As', 'wiaas' ),
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$role_name = translate_user_role( wp_roles()->role_names[ $role ] );
|
||||
|
||||
if ($role === $current_role) {
|
||||
// highlight current role
|
||||
$title = '<span class="ab-label">' . __( $role_name, 'wiaas' ) . '</span>';
|
||||
|
||||
$url = false;
|
||||
|
||||
} else if ($role === 'customer') {
|
||||
// set external link for customer role
|
||||
$title = '<span>' . __( $role_name, 'wiaas' ) . '</span>';
|
||||
$title .= '<span class="ab-icon dashicons dashicons-external"></span>';
|
||||
|
||||
$url = WIAAS_CUSTOMER_INTERFACE;
|
||||
|
||||
$target = '_blank';
|
||||
|
||||
} else {
|
||||
$title = '<span>' . __( $role_name, 'wiaas' ) . '</span>';
|
||||
|
||||
$url = wp_nonce_url(admin_url(), 'wiaas-set-role', 'wiaas-set-role-nonce');
|
||||
$url = add_query_arg( 'wiaas-role', $role, $url );
|
||||
|
||||
$target = '_parent';
|
||||
}
|
||||
|
||||
$admin_bar->add_menu( array(
|
||||
'id' => 'wiaas_'.$role,
|
||||
'parent' => 'wiaas-view-as',
|
||||
'title' => $title,
|
||||
'href' => $url,
|
||||
'meta' => array(
|
||||
'title' => __( $role_name, 'wiaas' ),
|
||||
'target' => $target
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Process organization role switch request if needed
|
||||
*
|
||||
*/
|
||||
public static function maybe_change_user_role() {
|
||||
if (! empty($_GET['wiaas-set-role-nonce']) && ! empty($_GET['wiaas-role'])) {
|
||||
if (wp_verify_nonce($_GET['wiaas-set-role-nonce'], 'wiaas-set-role')) {
|
||||
$role_name = sanitize_key($_GET['wiaas-role']);
|
||||
|
||||
$role = wp_roles()->get_role($role_name);
|
||||
|
||||
if (! empty($role) && $role_name !== 'customer') {
|
||||
// get current user
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
update_user_meta($current_user->ID, '_wiaas_admin_role', $role->name);
|
||||
|
||||
// switch user role
|
||||
$current_user->set_role($role->name);
|
||||
}
|
||||
}
|
||||
|
||||
wp_safe_redirect( admin_url('index.php') );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Organization::init();
|
||||
@@ -7,15 +7,45 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
class Wiaas_Admin_Package {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-linked-packages.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-package-types.php';
|
||||
|
||||
add_action( '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);
|
||||
}
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Editor for wiaas document post screen
|
||||
*
|
||||
* Class Wiaas_Admin_Document_Editor
|
||||
*/
|
||||
class Wiaas_Admin_Document_Editor {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
||||
|
||||
add_action( 'save_post', array( __CLASS__, 'save' ), 1, 2 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add wiaas document editor metaboxes
|
||||
*/
|
||||
public static function add_meta_boxes() {
|
||||
|
||||
add_meta_box( 'wiaas_document_details', __( 'Details', 'wiaas' ), array(
|
||||
__CLASS__,
|
||||
'document_info'
|
||||
), 'wiaas_doc', 'normal', 'low');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save wiaas document informations
|
||||
* @param $post_id
|
||||
* @param $post
|
||||
*/
|
||||
public static function save ($post_id, $post) {
|
||||
if ( empty( $post_id ) || empty( $post ) || empty( $_POST ) ) {
|
||||
return;
|
||||
}
|
||||
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
||||
return;
|
||||
}
|
||||
if ( is_int( wp_is_post_revision( $post ) ) ) {
|
||||
return;
|
||||
}
|
||||
if ( is_int( wp_is_post_autosave( $post ) ) ) {
|
||||
return;
|
||||
}
|
||||
if ( empty( $_POST['wiaas_doc_nonce'] ) || ! wp_verify_nonce( $_POST['wiaas_doc_nonce'], 'save_wiaas_doc' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $post->post_type != 'wiaas_doc' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// unset nonce because it's only valid of 1 post
|
||||
unset( $_POST['wiaas_doc_nonce'] );
|
||||
|
||||
if (isset($_POST['wiaas_doc_version']) && $_POST['wiaas_doc_version'] !== '') {
|
||||
$version = sanitize_text_field($_POST['wiaas_doc_version']);
|
||||
|
||||
if(wiaas_document_version_exists($version)) {
|
||||
Wiaas_Document::add_document_version($post_id, $version);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['wiaas_doc_type'])) {
|
||||
Wiaas_Document::set_doc_type($post_id, sanitize_key($_POST['wiaas_doc_type']));
|
||||
}
|
||||
|
||||
Wiaas_Document::set_is_doc_visible($post_id, $_POST['wiaas_doc_visible'] === 'on');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render wiaas document info metabox
|
||||
*/
|
||||
public static function document_info() {
|
||||
global $post;
|
||||
|
||||
$parent_post_type = $post->post_type;
|
||||
$document_id = $post->ID;
|
||||
|
||||
$ajax_action = 'wiaas_upload_file';
|
||||
|
||||
require 'views/html-document-info.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Admin_Document_Editor::init();
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Product_Documents {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'add_linked_documents_tab' ) );
|
||||
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'linked_documents_tab' ) );
|
||||
|
||||
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
|
||||
|
||||
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add upload and link document metabox to product screen
|
||||
*/
|
||||
public static function add_meta_boxes() {
|
||||
add_meta_box( 'wiaas_upload_and_link_document', __( 'Upload and link document', 'wiaas' ), array(
|
||||
__CLASS__,
|
||||
'upload_and_link_document'
|
||||
), 'product', 'side');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render upload and link document metabox to product screen
|
||||
*/
|
||||
public static function upload_and_link_document() {
|
||||
|
||||
$ajax_action = 'wiaas_quick_add_document';
|
||||
|
||||
require 'views/html-document-form.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add linked documents tabs for product screen
|
||||
*
|
||||
* @param array $tabs
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function add_linked_documents_tab($tabs) {
|
||||
$tabs['wiaas_documents'] = array(
|
||||
'label' => __( 'Linked Documents', 'wiaas' ),
|
||||
'target' => 'wiaas_documents',
|
||||
'class' => array('show_if_bundle', 'show_if_simple'),
|
||||
'priority' => 20,
|
||||
);
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render linked documents tab content for product screen
|
||||
*/
|
||||
public static function linked_documents_tab() {
|
||||
|
||||
global $post;
|
||||
|
||||
$documents_ids = wiaas_get_object_attached_documents($post->ID);
|
||||
|
||||
include 'views/html-product-documents.php';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save linked document for product
|
||||
*
|
||||
* @param int $package_id
|
||||
*/
|
||||
public static function process_meta_box($package_id) {
|
||||
$documents = isset($_POST['wiaas_attached_documents']) && is_array($_POST['wiaas_attached_documents']) ?
|
||||
$_POST['wiaas_attached_documents'] : array();
|
||||
|
||||
wiaas_attach_documents_to_object($package_id, $documents);
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Product_Documents::init();
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* int $id ID of the attached document
|
||||
*/
|
||||
|
||||
$doc_info = Wiaas_Document::get_doc_info($id);
|
||||
$type = isset($doc_info['type']) && is_array($doc_info['type']) ? $doc_info['type']['name'] : ' - ';
|
||||
|
||||
$visible = Wiaas_Document::is_doc_visible($id);
|
||||
|
||||
?>
|
||||
|
||||
<tr id="wiaas_attached_document_<?php echo esc_attr($id); ?>">
|
||||
<td width="1%">
|
||||
<?php
|
||||
if ($visible) {
|
||||
echo '<span class="dashicons dashicons-visibility"></span>';
|
||||
} else {
|
||||
echo '<span class="dashicons dashicons-hidden"></span>';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<div>
|
||||
<input type="hidden" name="wiaas_attached_documents[]" value="<?php echo esc_attr($id); ?>" />
|
||||
<b>
|
||||
<?php esc_html_e($doc_info['name'], 'wiaas'); ?>
|
||||
</b>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<span>
|
||||
<?php esc_html_e($type, 'wiaas'); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td width="1%"><a href="<?php echo esc_attr($doc_info['url']) ?>" download>
|
||||
<span class="dashicons dashicons-download"></span>
|
||||
</a>
|
||||
</td>
|
||||
<td width="1%">
|
||||
<button
|
||||
data-id="<?php echo esc_attr($id); ?>"
|
||||
class="button wiaas-remove-attached-document">
|
||||
<small><?php esc_html_e('Remove', 'wiaas'); ?></small>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
$is_update = isset($document_id);
|
||||
|
||||
global $post;
|
||||
|
||||
$insert_new_document = $post->post_type !== 'wiaas_doc';
|
||||
|
||||
?>
|
||||
|
||||
<style>
|
||||
|
||||
#wiaas_document_form .form-group {
|
||||
margin-bottom:15px;
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
#wiaas_document_form .form-control {
|
||||
width: 100%;
|
||||
height: 34px;
|
||||
padding:6px 12px;
|
||||
border: 1px solid #d5d5d5;
|
||||
|
||||
}
|
||||
|
||||
#wiaas_document_form #plupload-browse-button {
|
||||
color: #444 !important;
|
||||
background-color: #FFFFFF !important;
|
||||
border-color: #CCCCCC !important;
|
||||
text-transform: uppercase !important;
|
||||
letter-spacing: 1px !important;
|
||||
border-radius: 2px !important;
|
||||
}
|
||||
|
||||
#wiaas_document_form #plupload-upload-ui {
|
||||
height: 230px;
|
||||
}
|
||||
|
||||
#wiaas_document_form #drag-drop-area {
|
||||
max-height: 200px;
|
||||
}
|
||||
|
||||
#wiaas_document_form .drag-drop .drag-drop-inside {
|
||||
margin: 50px auto 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function ($) {
|
||||
<?php
|
||||
|
||||
if ($insert_new_document) {
|
||||
$nonce = wp_create_nonce('wiaas_quick_add_document');
|
||||
$action = 'wiaas_quick_add_document';
|
||||
} else {
|
||||
$nonce = wp_create_nonce('wiaas_upload_file');
|
||||
$action = 'wiaas_upload_file';
|
||||
}
|
||||
|
||||
$plupload_init = array(
|
||||
'runtimes' => 'html5,silverlight,flash,html4',
|
||||
'browse_button' => 'plupload-browse-button',
|
||||
'container' => 'plupload-upload-ui',
|
||||
'drop_element' => 'drag-drop-area',
|
||||
'file_data_name' => 'wiaas_file',
|
||||
'multiple_queues' => false,
|
||||
'url' => admin_url('admin-ajax.php'),
|
||||
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
|
||||
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
|
||||
'filters' => array(array(
|
||||
'title' => __('Allowed Files'),
|
||||
'extensions' => join(',', Wiaas_Document_Upload::allowed_extensions()))
|
||||
),
|
||||
'multipart' => true,
|
||||
'urlstream_upload' => true,
|
||||
// additional post data to send to our ajax hook
|
||||
'multipart_params' => array(
|
||||
'_ajax_nonce' => $nonce,
|
||||
'action' => $action,
|
||||
'type' => 'wiaas_doc'
|
||||
),
|
||||
);
|
||||
|
||||
if(get_option('__wpdm_chunk_upload',0) == 1){
|
||||
$plupload_init['chunk_size'] = get_option('__wpdm_chunk_size', 1024).'kb';
|
||||
$plupload_init['max_retries'] = 3;
|
||||
} else
|
||||
$plupload_init['max_file_size'] = wp_max_upload_size().'b';
|
||||
?>
|
||||
|
||||
// create the uploader and pass the config from above
|
||||
var uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
|
||||
|
||||
// checks if browser supports drag and drop upload, makes some css adjustments if necessary
|
||||
uploader.bind('Init', function(up){
|
||||
var uploaddiv = jQuery('#plupload-upload-ui');
|
||||
|
||||
if(up.features.dragdrop){
|
||||
uploaddiv.addClass('drag-drop');
|
||||
jQuery('#drag-drop-area')
|
||||
.bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
|
||||
.bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
|
||||
|
||||
}else{
|
||||
uploaddiv.removeClass('drag-drop');
|
||||
jQuery('#drag-drop-area').unbind('.wp-uploader');
|
||||
}
|
||||
});
|
||||
|
||||
uploader.init();
|
||||
|
||||
// a file was added in the queue
|
||||
uploader.bind('FilesAdded', function(up, files){
|
||||
//var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
|
||||
|
||||
<?php
|
||||
if ($insert_new_document) {
|
||||
?>
|
||||
var params = uploader.getOption('multipart_params');
|
||||
params['doc_title'] = $('#wiaas_new_doc_title').val();
|
||||
params['doc_type'] = $('#wiaas_new_doc_type').val();
|
||||
params['doc_visible'] = $('#wiaas_new_doc_visible').is(':checked');
|
||||
|
||||
uploader.setOption('multipart_params', params);
|
||||
|
||||
plupload.each(files, function(file){
|
||||
jQuery('#wiaas_selected_file').val(file.name);
|
||||
});
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
uploader.refresh();
|
||||
uploader.start();
|
||||
});
|
||||
|
||||
$("#wiaas_document_add_version").click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
uploader.start();
|
||||
});
|
||||
|
||||
// a file was uploaded
|
||||
uploader.bind('FileUploaded', function(up, file, response) {
|
||||
|
||||
response = response.response;
|
||||
|
||||
var infoContainer = jQuery('#wiaas_upload_info');
|
||||
|
||||
if (response.substring(0, 6) === 'ERROR:') {
|
||||
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 {
|
||||
?>
|
||||
$('#wiaas_uploaded_file').val(response);
|
||||
jQuery('#publish').click();
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="wiaas_document_form">
|
||||
|
||||
<?php
|
||||
if ($insert_new_document) {
|
||||
?>
|
||||
<p class="form-group">
|
||||
<input
|
||||
id="wiaas_new_doc_title"
|
||||
type="text"
|
||||
placeholder="Title"
|
||||
class="form-control input-lg" />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<p class="form-group">
|
||||
<select
|
||||
id="wiaas_new_doc_type"
|
||||
name="wiaas_doc_type"
|
||||
class="form-control input-lg">
|
||||
<?php
|
||||
$all_doc_types = Wiaas_Document::get_available_doc_types();
|
||||
|
||||
if (!$insert_new_document) {
|
||||
$selected_doc_type = Wiaas_Document::get_doc_type($post->ID);
|
||||
$selected_doc_type = is_array($selected_doc_type) ? $selected_doc_type['id'] : '';
|
||||
}
|
||||
|
||||
foreach ($all_doc_types as $doc_type) {
|
||||
if (!$doc_type['is_special_type']) {
|
||||
?>
|
||||
<option
|
||||
value="<?php echo $doc_type['id'] ?>"
|
||||
<?php selected($doc_type['id'], $selected_doc_type, true)?>
|
||||
>
|
||||
<?php esc_html_e($doc_type['name'], 'wiaas') ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p class="form-group">
|
||||
<input
|
||||
id="wiaas_new_doc_visible"
|
||||
name="wiaas_doc_visible"
|
||||
<?php if (!$insert_new_document)
|
||||
checked(Wiaas_Document::is_doc_visible($post->ID), true, true) ?>
|
||||
type="checkbox"
|
||||
/>
|
||||
<label><?php echo __( 'Visible to customer?', 'wiaas' ); ?></label>
|
||||
</p>
|
||||
|
||||
<input id="wiaas_uploaded_file" name="wiaas_doc_version" type="hidden">
|
||||
|
||||
<div>
|
||||
<div id="plupload-upload-ui" class="hide-if-no-js">
|
||||
<div id="drag-drop-area" style="height:240px">
|
||||
<div class="drag-drop-inside">
|
||||
<p class="drag-drop-info"><?php _e( 'Drop file here', 'wiaas' ); ?></p>
|
||||
|
||||
<p><?php echo _x( 'or', 'Drop file here *or* select file', 'wiaas' ); ?></p>
|
||||
|
||||
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button"
|
||||
value="<?php esc_attr_e( 'Select File', 'wiaas' ); ?>"
|
||||
class="button"/></p>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_upload_info">
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* int $document_id ID of the document
|
||||
*/
|
||||
?>
|
||||
|
||||
<style>
|
||||
|
||||
#wiaas_document_info table {
|
||||
margin-top: 25px;
|
||||
}
|
||||
|
||||
#wiaas_document_info table > thead {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
#wiaas_document_info table b {
|
||||
color: #72777c;
|
||||
}
|
||||
|
||||
#tagsdiv-wiaas_doc_type {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#wiaas_document_new_version {
|
||||
max-width: 320px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
<div id="wiaas_document_info">
|
||||
|
||||
<?php echo wp_nonce_field('save_wiaas_doc', 'wiaas_doc_nonce') ?>
|
||||
|
||||
<div id="wiaas_document_new_version">
|
||||
<?php
|
||||
|
||||
require 'html-document-form.php';
|
||||
|
||||
?>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><b>Versions</b></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="wiaas_doc_versions">
|
||||
<?php
|
||||
$versions = Wiaas_Document::get_document_versions($document_id);
|
||||
|
||||
foreach ($versions as $index => $version) {
|
||||
?>
|
||||
<tr>
|
||||
<td><?php esc_html_e('#' . ($index + 1), 'wiaas') ?></td>
|
||||
<td><?php
|
||||
esc_html_e(
|
||||
wiaas_get_doc_version_filename($version).'.'.wiaas_get_doc_version_extension($version),
|
||||
'wiaas')
|
||||
?></td>
|
||||
<td>
|
||||
<a
|
||||
href="<?php echo esc_attr(Wiaas_Document::get_doc_download_link($document_id, $index)) ?>"
|
||||
download>
|
||||
<span class="dashicons dashicons-download"></span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Wiaas Linked Packages Editor
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<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"
|
||||
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">
|
||||
<div class="form-field">
|
||||
<div style="margin:20px">
|
||||
<table id="wiaas_attached_documents" class="widefat wp-list-table">
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($documents_ids as $id) {
|
||||
require 'html-attached-document.php';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
add_action( 'wp_ajax_wiaas_upload_file', 'wiaas_ajax_upload_document_version' );
|
||||
add_action( 'wp_ajax_wiaas_quick_add_document', 'wiaas_ajax_quick_add_document' );
|
||||
add_action( 'wp_ajax_wiaas_link_document', 'wiaas_ajax_link_document' );
|
||||
|
||||
add_action( 'wp_ajax_wiaas_json_search_documents','wiaas_ajax_json_search_documents' );
|
||||
|
||||
|
||||
/**
|
||||
* Upload document version file with ajax
|
||||
*/
|
||||
function wiaas_ajax_upload_document_version() {
|
||||
check_ajax_referer('wiaas_upload_file');
|
||||
|
||||
if (!isset($_FILES['wiaas_file']) || empty($_FILES['wiaas_file'])) {
|
||||
echo "ERROR: No file present!";
|
||||
die();
|
||||
}
|
||||
|
||||
$version = Wiaas_Document_Upload::upload_document_version('wiaas_file');
|
||||
|
||||
if (is_wp_error($version)) {
|
||||
echo 'ERROR:' . $version->get_error_message();
|
||||
die();
|
||||
}
|
||||
|
||||
echo $version;
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick add new document and return attachment view for it
|
||||
*/
|
||||
function wiaas_ajax_quick_add_document() {
|
||||
check_ajax_referer('wiaas_quick_add_document');
|
||||
|
||||
//validate file
|
||||
if (!isset($_FILES['wiaas_file']) || empty($_FILES['wiaas_file'])) {
|
||||
echo "ERROR: No file present!";
|
||||
die();
|
||||
}
|
||||
|
||||
// Upload document version file
|
||||
$version = Wiaas_Document_Upload::upload_document_version('wiaas_file');
|
||||
|
||||
// Upload failed so return the error
|
||||
if (is_wp_error($version)) {
|
||||
echo 'ERROR:' . $version->get_error_message();
|
||||
die();
|
||||
}
|
||||
|
||||
// Get document title
|
||||
$title = isset($_POST['doc_title']) && $_POST['doc_title'] !== '' ?
|
||||
sanitize_text_field($_POST['doc_title']) :
|
||||
pathinfo( $version, PATHINFO_FILENAME );
|
||||
|
||||
// Try to create new document
|
||||
$id = Wiaas_Document::add_document(
|
||||
$title,
|
||||
$version,
|
||||
$_POST['doc_visible'] === 'true');
|
||||
|
||||
// Document creation failed so return the error
|
||||
if (!$id) {
|
||||
echo "ERROR: Document could not be created!";
|
||||
die();
|
||||
}
|
||||
|
||||
// If document type is sent then assign new document to it
|
||||
if (isset($_POST['doc_type'])) {
|
||||
Wiaas_Document::set_doc_type( $id, sanitize_key($_POST['doc_type']) );
|
||||
}
|
||||
|
||||
require 'views/html-attached-document.php';
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render attacment view for linked document
|
||||
*/
|
||||
function wiaas_ajax_link_document() {
|
||||
check_ajax_referer('wiaas_link_document');
|
||||
|
||||
$id = absint($_GET['id']);
|
||||
|
||||
require 'views/html-attached-document.php';
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*Search wiaas documents by name
|
||||
*/
|
||||
function wiaas_ajax_json_search_documents() {
|
||||
check_ajax_referer('wiaas_json_search_documents');
|
||||
|
||||
$q = ( ! empty( $_GET['query'] ) ? sanitize_text_field($_GET['query']) : '' );
|
||||
|
||||
$result = Wiaas_Document::search($q);
|
||||
|
||||
wp_send_json( $result );
|
||||
}
|
||||
@@ -28,20 +28,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
function showDownloadableFiles() {
|
||||
$('#general_product_data').find('.show_if_downloadable').each(function() {
|
||||
$(this).show();
|
||||
$(this).removeClass('hidden');
|
||||
$(this).removeClass('show_if_downloadable');
|
||||
$(this).addClass('show_if_simple');
|
||||
$(this).addClass('show_if_bundle');
|
||||
|
||||
$(this).find('._download_limit_field, ._download_expiry_field').hide();
|
||||
});
|
||||
}
|
||||
|
||||
showDownloadableFiles();
|
||||
|
||||
handlePackageTypeToolsVisiblity();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -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,46 +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']);
|
||||
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>
|
||||
@@ -6,13 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
<?php
|
||||
|
||||
$value = $pricing_rule['minimal_services_price'];
|
||||
if ($pricing_rule['principal_amount'] > 0 && $pay_type['package_pay_period'] > 0) {
|
||||
$value += wiaas_PMT(
|
||||
Wiaas_Pricing::INTEREST_RATE,
|
||||
$pay_type['package_pay_period'],
|
||||
$pricing_rule['principal_amount']);
|
||||
}
|
||||
$value = $pricing_rule['minimal_recurrent_price'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
|
||||
@@ -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,209 +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_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,24 +4,13 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
$("#general_product_data").find('.pricing').addClass('hide_if_bundle');
|
||||
$("#general_product_data").find('.pricing').removeClass('show_if_bundle');
|
||||
|
||||
if ($('#product-type').val() === 'bundle') {
|
||||
$("#general_product_data .pricing").hide();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_checkbox(
|
||||
array(
|
||||
'id' => '_wiaas_recurring_price',
|
||||
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
|
||||
'data_type' => 'price',
|
||||
'label' => __( $product->get_category_ids()[0], 'wiaas' ),
|
||||
'label' => __( 'Is recurring?', 'wiaas' ),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -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();
|
||||
@@ -3,27 +3,35 @@
|
||||
class Wiaas_Admin_Template_Selection {
|
||||
|
||||
public static function init() {
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'create_custom_meta_box'), 100);
|
||||
add_action('woocommerce_process_product_meta_bundle', array(__CLASS__, 'save_custom_content_meta_box'), 10, 1);
|
||||
add_action('add_meta_boxes', array(__CLASS__, 'create_template_meta_box'), 100);
|
||||
add_action('woocommerce_process_product_meta_bundle', array(__CLASS__, 'save_template_content_meta_box'), 10, 1);
|
||||
|
||||
// Processes and saves type-specific data.
|
||||
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'validate_bundle'), 11);
|
||||
|
||||
}
|
||||
|
||||
public static function create_custom_meta_box() {
|
||||
/**
|
||||
* Renders template selection meta box
|
||||
*/
|
||||
public static function create_template_meta_box() {
|
||||
add_meta_box(
|
||||
'template_product_meta_box',
|
||||
__('Choose package template <em>(optional)</em>', 'cmb'),
|
||||
'Wiaas_Admin_Template_Selection::add_custom_content_meta_box',
|
||||
'Wiaas_Admin_Template_Selection::add_template_content_meta_box',
|
||||
'product',
|
||||
'normal',
|
||||
'high'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static function add_custom_content_meta_box($post) {
|
||||
/**
|
||||
* Fill in the value of template selection dropdown,
|
||||
* and render template categories of the selected template
|
||||
*
|
||||
* @param $post WP_Post object
|
||||
*/
|
||||
public static function add_template_content_meta_box($post) {
|
||||
|
||||
$value = get_post_meta($post->ID, '_select_template', true);
|
||||
|
||||
@@ -48,150 +56,147 @@ 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['service']);
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
public static function get_categories_from_templates($products_form_template) {
|
||||
/**
|
||||
* Extract template categories for all of the main product categories
|
||||
* (software , hardware, services, installation) and combine them in one array
|
||||
*
|
||||
* @param $categories_form_template
|
||||
* @return array of Wiaas_Template_Category_Object
|
||||
*/
|
||||
public static function get_categories_from_templates($categories_form_template) {
|
||||
|
||||
$all_template_categories = array();
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['hardware']));
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['service']));
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['installation']));
|
||||
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['software']));
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['hardware']));
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['services']));
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['installation']));
|
||||
|
||||
$all_template_categories = array_merge($all_template_categories,
|
||||
WC_Product_Template::extract_template_product_categories($categories_form_template['software']));
|
||||
|
||||
return $all_template_categories;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the template product meta_data from selected template
|
||||
*
|
||||
* @param $selected_template integer an id of selected template
|
||||
* @return array of template categories
|
||||
*/
|
||||
public static function show_template_products($selected_template) {
|
||||
|
||||
|
||||
if (empty($selected_template)) {
|
||||
return;
|
||||
return array();
|
||||
|
||||
} else {
|
||||
$template_products_hardware = (get_post_meta($selected_template, '_template_items_hardware', true));
|
||||
$template_products_service = (get_post_meta($selected_template, '_template_items_service', true));
|
||||
$template_products_installation = (get_post_meta($selected_template, '_template_items_installation', true));
|
||||
$template_products_software = (get_post_meta($selected_template, '_template_items_software', true));
|
||||
|
||||
$template_products_hardware = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_hardware');
|
||||
|
||||
$template_products_services = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_services');
|
||||
|
||||
$template_products_installation = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_installation');
|
||||
|
||||
$template_products_software = WC_Product_Template::get_template_categories_from_meta(
|
||||
$selected_template, '_template_items_software');
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'hardware' => $template_products_hardware,
|
||||
'service' => $template_products_service,
|
||||
'services' => $template_products_services,
|
||||
'installation' => $template_products_installation,
|
||||
'software' => $template_products_software
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static function render_template_products($template_products) {
|
||||
/**
|
||||
* 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, $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');
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_product_categories($category_meta) {
|
||||
$category_objects = array();
|
||||
|
||||
/**
|
||||
* Save selected template
|
||||
*
|
||||
* @param $post_id WP_Post
|
||||
*/
|
||||
|
||||
if (empty($category_meta)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($category_meta as $meta) {
|
||||
|
||||
if (!empty($meta)) {
|
||||
|
||||
|
||||
$category_template_id = $meta['template_category_id'];
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$meta['template_category_title'],
|
||||
$meta['quantity']);
|
||||
|
||||
$category_objects[$category_template_id] = $template_category_object;
|
||||
}
|
||||
|
||||
}
|
||||
return empty($category_objects) ? null : $category_objects;
|
||||
}
|
||||
|
||||
public static function get_bundled_product_categories($bundled_items) {
|
||||
|
||||
$template_category_objects = array();
|
||||
foreach ($bundled_items as $item_id => $item) {
|
||||
$item_data = $item->get_data();
|
||||
$post_terms = wp_get_object_terms($item->get_product_id(), 'template_category', array('fields' => 'id=>name'));
|
||||
|
||||
if (!empty($post_terms) && !is_wp_error($post_terms)) {
|
||||
|
||||
$cat = '';
|
||||
$category_template_id = '';
|
||||
|
||||
foreach ($post_terms as $id => $term) {
|
||||
$cat = $term;
|
||||
$category_template_id = $id;
|
||||
}
|
||||
|
||||
$template_category_object = new Wiaas_Template_Category_Object(
|
||||
$category_template_id,
|
||||
$cat,
|
||||
$item_data['quantity_max']);
|
||||
$template_category_objects[$category_template_id] = $template_category_object;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $template_category_objects;
|
||||
}
|
||||
|
||||
|
||||
function save_custom_content_meta_box($post_id) {
|
||||
function save_template_content_meta_box($post_id) {
|
||||
$selected_template = $_POST['_select_template'];
|
||||
if (!empty($selected_template))
|
||||
update_post_meta($post_id, '_select_template', esc_attr($selected_template));
|
||||
else {
|
||||
update_post_meta($post_id, '_select_template', '');
|
||||
}
|
||||
|
||||
WC_Product_Template::bind_selected_template_to_product($selected_template, $post_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the template categories from bundle products and selected template
|
||||
* Compare template categories and quantities that are required by the template with those in bundle products
|
||||
*
|
||||
* Admin error is added if validation is not satisfied
|
||||
*
|
||||
* @param $product WC_Product_Bundle
|
||||
*/
|
||||
public static function validate_bundle($product) {
|
||||
|
||||
|
||||
if ($product->get_type() == 'bundle') {
|
||||
$selected_template = $_POST['_select_template'];
|
||||
$bundled_items = $product->get_bundled_items('view');
|
||||
$products_form_template = self::show_template_products($selected_template);
|
||||
$template_categories_form_template = self::show_template_products($selected_template);
|
||||
|
||||
$missing_categories = array();
|
||||
$insufficient_product_quantities = array();
|
||||
$missing_template_categories = array();
|
||||
$insufficient_template_category_quantities = array();
|
||||
|
||||
|
||||
$categories_form_template = self::get_categories_from_templates($products_form_template);
|
||||
$categories_form_bundle = self::get_bundled_product_categories($bundled_items);
|
||||
$categories_form_template = self::get_categories_from_templates($template_categories_form_template);
|
||||
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
|
||||
$bundle_category_keys = array_keys($categories_form_bundle);
|
||||
|
||||
|
||||
if (!empty($categories_form_template)) {
|
||||
|
||||
foreach ($categories_form_template as $category) {
|
||||
@@ -200,7 +205,7 @@ class Wiaas_Admin_Template_Selection {
|
||||
|
||||
if (!in_array($template_cat_id, $bundle_category_keys)) {
|
||||
|
||||
array_push($missing_categories, $category->name);
|
||||
array_push($missing_template_categories, $category->name);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -208,37 +213,25 @@ class Wiaas_Admin_Template_Selection {
|
||||
$quantity_from_template = $category->quantity;
|
||||
|
||||
if ((int)($quantity_from_template) !== $product_from_bundle_quantity) {
|
||||
array_push($insufficient_product_quantities, $category->name);
|
||||
array_push($insufficient_template_category_quantities, $category->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$categories_message = implode(',', $missing_categories);
|
||||
$quantity_message = implode(',', $insufficient_product_quantities);
|
||||
$template_categories_message = implode(',', $missing_template_categories);
|
||||
$quantity_message = implode(',', $insufficient_template_category_quantities);
|
||||
|
||||
if (!empty($missing_categories)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $categories_message, 'woocommerce-product-bundles'));
|
||||
if (!empty($missing_template_categories)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $template_categories_message, 'woocommerce-product-bundles'));
|
||||
}
|
||||
|
||||
if (!empty($insufficient_product_quantities)) {
|
||||
if (!empty($insufficient_template_category_quantities)) {
|
||||
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories with different quantities: ' . $quantity_message, 'woocommerce-product-bundles'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function get_category_ids_form_bundle($product) {
|
||||
$products_form_budnle = $product->get_bundled_data_items();
|
||||
$product_ids = array();
|
||||
|
||||
foreach ($products_form_budnle as $product) {
|
||||
array_push($product_ids, $product->get_id());
|
||||
}
|
||||
|
||||
return self::get_product_categories($product_ids);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Template_Selection::init();
|
||||
|
||||
@@ -21,6 +21,10 @@ class Wiaas_Template_Admin_Ajax {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An ajax callback action for handling template selection
|
||||
*/
|
||||
|
||||
public static function ajax_handle_template_selection() {
|
||||
|
||||
$selected_template_id = intval($_POST['selected_template']);
|
||||
@@ -34,7 +38,7 @@ class Wiaas_Template_Admin_Ajax {
|
||||
if (!empty($template_products)) {
|
||||
ob_start();
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['hardware']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['service']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['services']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['installation']);
|
||||
Wiaas_Admin_Template_Selection::render_template_products($template_products['software']);
|
||||
|
||||
@@ -53,7 +57,7 @@ class Wiaas_Template_Admin_Ajax {
|
||||
check_ajax_referer('wc_bundles_add_bundled_product', 'security');
|
||||
|
||||
$loop = intval($_POST['id']);
|
||||
$product_id = intval($_POST['product_id']);
|
||||
$template_category_id = intval($_POST['template_category_id']);
|
||||
$title = $_POST['title'];
|
||||
$options = $_POST['options'];
|
||||
|
||||
@@ -70,16 +74,17 @@ class Wiaas_Template_Admin_Ajax {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Handles adding template categories search.
|
||||
*/
|
||||
public static function ajax_wiaas_template_category_search() {
|
||||
|
||||
$term = ($_POST['term']);
|
||||
$term = wp_unslash($_GET['term']);
|
||||
$response = array();
|
||||
|
||||
|
||||
$terms = get_terms(array(
|
||||
'taxonomy' => 'template_category',
|
||||
'name__like' => $term
|
||||
'name__like' => $term,
|
||||
'hide_empty' => false
|
||||
));
|
||||
|
||||
foreach ($terms as $t) {
|
||||
|
||||
@@ -7,11 +7,9 @@ class Wiaas_template {
|
||||
|
||||
public static function init() {
|
||||
add_filter('product_type_selector', array(__CLASS__, 'add_template_product_type'));
|
||||
add_action('admin_footer', array(__CLASS__, 'templates_custom_js'));
|
||||
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'custom_product_tabs'));
|
||||
add_action('woocommerce_product_data_panels', array(__CLASS__, 'wiaastemplate_product_tab_content_all'));
|
||||
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'save_wiaastemplate'));
|
||||
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'hide_attributes_data_panel'));
|
||||
add_action('woocommerce_process_product_meta_wiaastemplate', array(__CLASS__, 'save_wiaastemplate'));
|
||||
|
||||
// Enqueue scripts.
|
||||
@@ -35,7 +33,7 @@ class Wiaas_template {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to product type drop down.
|
||||
* Add template product type drop down.
|
||||
*/
|
||||
function add_template_product_type($types) {
|
||||
|
||||
@@ -48,27 +46,7 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Show pricing fields for template product.
|
||||
*/
|
||||
function templates_custom_js() {
|
||||
|
||||
if ('product' != get_post_type()) :
|
||||
return;
|
||||
endif;
|
||||
|
||||
?>
|
||||
<script type='text/javascript'>
|
||||
jQuery(document).ready(function () {
|
||||
jQuery('.options_group.pricing').addClass('show_if_simple_template').show();
|
||||
});
|
||||
|
||||
</script><?php
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a custom product tab.
|
||||
* Add template product, hardware, services, installation and software tabs product tab.
|
||||
*/
|
||||
function custom_product_tabs($tabs) {
|
||||
|
||||
@@ -100,6 +78,10 @@ class Wiaas_template {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content do template tabs
|
||||
*/
|
||||
|
||||
public static function wiaastemplate_product_tab_content_all() {
|
||||
|
||||
self::wiaastemplate_product_tab_content('hardware');
|
||||
@@ -110,8 +92,11 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Contents of the template options product tab.
|
||||
* Html contents of the template options product tab.
|
||||
*
|
||||
* @param $options string main wiaas category
|
||||
*/
|
||||
|
||||
public static function wiaastemplate_product_tab_content($options) {
|
||||
|
||||
global $post;
|
||||
@@ -128,7 +113,7 @@ class Wiaas_template {
|
||||
|
||||
foreach ($template_items as $item) {
|
||||
|
||||
$product_id = $item['template_category_id'];
|
||||
$template_category_id = $item['template_category_id'];
|
||||
$title = $item['template_category_title'];
|
||||
$quantity = $item['quantity'];
|
||||
|
||||
@@ -142,7 +127,7 @@ class Wiaas_template {
|
||||
<select class="wiaas-term-search" id="wiaastemplate_products<?php echo '_' . $options ?>" style="width: 250px;"
|
||||
name="template_product"
|
||||
data-placeholder="<?php _e('Add product to template…', 'wiaas'); ?>"
|
||||
data-action="woocommerce_json_search_products" multiple="multiple" data-limit="500">
|
||||
multiple="multiple" data-limit="500">
|
||||
<option></option>
|
||||
</select>
|
||||
<?php echo wc_help_tip(__('Search for a product and add it to this template by clicking its name in the results list.', 'wiaas')); ?>
|
||||
@@ -154,7 +139,7 @@ class Wiaas_template {
|
||||
|
||||
|
||||
/**
|
||||
* Save the custom fields.
|
||||
* Save the template categories that are bind to template.
|
||||
*/
|
||||
function save_wiaastemplate($post_id) {
|
||||
|
||||
@@ -163,14 +148,21 @@ class Wiaas_template {
|
||||
$posted_template_data_installation = isset($_POST['template_data_installation']) ? $_POST['template_data_installation'] : false;
|
||||
$posted_template_data_software = isset($_POST['template_data_software']) ? $_POST['template_data_software'] : false;
|
||||
|
||||
self::save_template_product_meta($post_id, $posted_template_data_hardware, 'hardware');
|
||||
self::save_template_product_meta($post_id, $posted_template_data_services, 'services');
|
||||
self::save_template_product_meta($post_id, $posted_template_data_installation, 'installation');
|
||||
self::save_template_product_meta($post_id, $posted_template_data_software, 'software');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_hardware, 'hardware');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_services, 'services');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_installation, 'installation');
|
||||
self::process_and_save_template_product_meta($post_id, $posted_template_data_software, 'software');
|
||||
|
||||
}
|
||||
|
||||
public static function save_template_product_meta($post_id, $posted_template_data, $option) {
|
||||
/**
|
||||
* Get extract posted data and save them to meta
|
||||
*
|
||||
* @param $post_id integer id of the template
|
||||
* @param $posted_template_data mixed
|
||||
* @param $option string indicating main wiaas category
|
||||
*/
|
||||
public static function process_and_save_template_product_meta($post_id, $posted_template_data, $option) {
|
||||
$processed_template_data = array();
|
||||
|
||||
// Sort posted data by menu order.
|
||||
@@ -178,24 +170,24 @@ class Wiaas_template {
|
||||
|
||||
foreach ($posted_template_data as $data) {
|
||||
|
||||
$product_id = isset($data['product_id']) ? absint($data['product_id']) : false;
|
||||
$product_title = isset($data['product_title']) ? $data['product_title'] : false;
|
||||
$template_category_id = isset($data['template_category_id']) ? absint($data['template_category_id']) : false;
|
||||
$template_category_title = isset($data['template_category_title']) ? $data['template_category_title'] : false;
|
||||
$quantity = isset($data['quantity']) ? absint($data['quantity']) : false;
|
||||
|
||||
|
||||
$item_data = array(
|
||||
|
||||
'template_category_id' => $product_id,
|
||||
'template_category_title' => trim($product_title),
|
||||
'template_category_id' => $template_category_id,
|
||||
'template_category_title' => trim($template_category_title),
|
||||
'quantity' => $quantity
|
||||
|
||||
);
|
||||
|
||||
$processed_template_data[$product_id] = $item_data;
|
||||
$processed_template_data[$template_category_id] = $item_data;
|
||||
|
||||
}
|
||||
|
||||
update_post_meta($post_id, '_template_items_' . $option, $processed_template_data);
|
||||
WC_Product_Template::save_template_product_meta($post_id, $option, $processed_template_data);
|
||||
}
|
||||
|
||||
public static function menu_sort_order($a, $b) {
|
||||
@@ -205,21 +197,6 @@ class Wiaas_template {
|
||||
return isset($a['menu_order']) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hide Attributes data panel.
|
||||
*/
|
||||
function hide_attributes_data_panel($tabs) {
|
||||
|
||||
$tabs['advanced']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
$tabs['shipping']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
$tabs['linked_product']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
$tabs['attribute']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
|
||||
|
||||
return $tabs;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_template::init();
|
||||
|
||||
@@ -18,8 +18,8 @@ if (!defined('ABSPATH')) {
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][item_id]" class="item_id" value="<?php echo $item_id; ?>" /><?php
|
||||
}
|
||||
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][product_title]" class="product_title" value="<?php echo $title; ?>" /><?php
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][product_id]" class="product_id" value="<?php echo $product_id; ?>" />
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][template_category_title]" class="product_title" value="<?php echo $title; ?>" /><?php
|
||||
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][template_category_id]" class="product_id" value="<?php echo $template_category_id; ?>" />
|
||||
|
||||
</div><?php
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,348 +6,333 @@ class Wiaas_Cart_API {
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $namespace = 'wiaas/cart';
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
private static $rest_base = 'cart';
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'count', array(
|
||||
'methods' => 'GET',
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/count', array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array(__CLASS__, 'get_cart_count'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'items', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_cart_items'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/items', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array(__CLASS__, 'get_cart_items'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array(__CLASS__, 'add_package_to_cart'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'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(
|
||||
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
),
|
||||
'addons_ids' => array(
|
||||
'description' => __( 'Wiaas package addons IDs.', 'wiaas' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'documents', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_cart_documents'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/items/(?P<key>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'key' => array(
|
||||
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array(__CLASS__, 'remove_package_from_cart'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array(__CLASS__, 'update_package_quantity'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'quantity' => array(
|
||||
'description' => __( 'New quantity cart package item.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'add', array(
|
||||
'methods' => 'post',
|
||||
'callback' => array(__CLASS__, 'add_package_to_cart'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
) );
|
||||
register_rest_route(self::$namespace, '/' . self::$rest_base . '/documents', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array(__CLASS__, 'get_cart_documents'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array(__CLASS__, 'upload_cart_document'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'doc_type' => array(
|
||||
'description' => __( 'Category of uploaded document.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'required' => true
|
||||
),
|
||||
'package_key' => array(
|
||||
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'required' => true
|
||||
),
|
||||
'type' => array(
|
||||
'default' => 'wiaas_doc'
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
register_rest_route( self::$namespace, 'remove', array(
|
||||
'methods' => 'post',
|
||||
'callback' => array(__CLASS__, 'remove_package_from_cart'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
) );
|
||||
register_rest_route(self::$namespace, '/' . self::$rest_base . '/items/(?P<key>[\w-]+)/documents/(?P<type>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'key' => array(
|
||||
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __( 'Cart document Type.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array(__CLASS__, 'download_cart_document'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'document_key' => array(
|
||||
'description' => __( 'Unique key identifier for cart document.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'required' => true
|
||||
),
|
||||
)
|
||||
),
|
||||
));
|
||||
|
||||
register_rest_route( self::$namespace, 'update-quantity', array(
|
||||
'methods' => 'post',
|
||||
'callback' => array(__CLASS__, 'update_package_quantity'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base . '/checkout', array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array(__CLASS__, 'checkout'),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'vat' => array(
|
||||
'description' => __( 'Vat Code for new order.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
'company' => array(
|
||||
'description' => __( 'Company name for new order.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
'reference' => array(
|
||||
'description' => __( 'Location details for new order.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
'tender' => array(
|
||||
'description' => __( 'Invoice reference for new order.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
'project_id' => array(
|
||||
'description' => __( 'Order project ID for new order.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'delivery_address_id' => array(
|
||||
'description' => __( 'ID of delivery address for new order.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'billing_address_id' => array(
|
||||
'description' => __( 'ID of billing address for new order.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
)
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'place-order', array(
|
||||
'methods' => 'post',
|
||||
'callback' => array(__CLASS__, 'place_order'),
|
||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
||||
) );
|
||||
}
|
||||
|
||||
public static function permission_check() {
|
||||
if (!is_user_logged_in()) {
|
||||
return new WP_Error( 'wiaas_rest_authorization_required',
|
||||
__( 'Sorry, only authorized users can access!', 'wiaas' ),
|
||||
array( 'status' => rest_authorization_required_code() ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cart count
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function get_cart_count() {
|
||||
$items = WC()->cart->get_cart_contents();
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
if (isset($item['_wiaas_standard_package'])) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'count' => $count,
|
||||
return rest_ensure_response(array(
|
||||
'count' => Wiaas_Cart::get_cart_packages_count(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cart items
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function get_cart_items() {
|
||||
$items = WC()->cart->get_cart_contents();
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
if (!isset($item['_wiaas_standard_package'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$package = wc_get_product($item['product_id']);
|
||||
|
||||
// Retrieve package addons
|
||||
$addon_cart_items = wiaas_get_cart_item_addons($item);
|
||||
$additional_packages = array();
|
||||
|
||||
foreach ($addon_cart_items as $addon_cart_item) {
|
||||
$additional_package = wc_get_product($addon_cart_item['product_id']);
|
||||
$additional_packages[] = array(
|
||||
'idAdditionalPackage' => $additional_package->get_id(),
|
||||
'packageName' => $additional_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixedExtra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrentExtra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||
'servicesExtra' => $addon_cart_item['_wiaas_payment']['services_extra'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Retrieve package options
|
||||
$option_cart_items = wiaas_get_cart_item_options($item);
|
||||
$package_options = array();
|
||||
foreach ($option_cart_items as $option_cart_item) {
|
||||
$option_package = wc_get_product($option_cart_item['product_id']);
|
||||
$package_options[] = array(
|
||||
'idOptionPackage' => $option_package->get_id(),
|
||||
'groupName' => $option_cart_item['_wiaas_option_group_name'],
|
||||
'packageName' => $option_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixedExtra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrentExtra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||
'servicesExtra' => $option_cart_item['_wiaas_payment']['services_extra'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$totalPrices = Wiaas_Cart::get_cart_item_total($item);
|
||||
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
return rest_ensure_response(array(
|
||||
'items' => Wiaas_Cart::get_cart_packages(),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
$result[] = array(
|
||||
'idPackage' => $item['product_id'],
|
||||
'key' => $item['key'],
|
||||
'packageName' => $package->get_title(),
|
||||
'additionalPackages' => $additional_packages,
|
||||
'areAdditionalAvailable' => true,
|
||||
'areOptionsAvailable' => true,
|
||||
'bids' => array(),
|
||||
'commercialLead' => 'Coor Service Management',
|
||||
'country' => array(
|
||||
'currency' => $country['currency']
|
||||
),
|
||||
'options' => $package_options,
|
||||
'quantity' => $item['quantity'],
|
||||
/**
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function add_package_to_cart($request) {
|
||||
|
||||
'idPayType' => $item['_wiaas_payment']['id'],
|
||||
'payType' => $item['_wiaas_payment']['payment_type'],
|
||||
'periodUnit' => $item['_wiaas_payment']['period_unit'],
|
||||
'idPrice' => $item['_wiaas_payment']['id'],
|
||||
'fixedPrice' => $item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrentPrice' => $item['_wiaas_payment']['recurrent_extra'],
|
||||
'servicesPrice' => $item['_wiaas_payment']['services_extra'],
|
||||
|
||||
'totalPrices' => array(
|
||||
'fixedPrice' => $totalPrices['fixed_extra'],
|
||||
'recurrentPrice' => $totalPrices['recurrent_extra'],
|
||||
'servicesPrice' => $totalPrices['services_extra'],
|
||||
),
|
||||
|
||||
'status' => 'available',
|
||||
'idCommercialLead' => 14,
|
||||
);
|
||||
}
|
||||
return new WP_REST_Response(
|
||||
array(
|
||||
'cartItems' => $result,
|
||||
'items' => $items,
|
||||
'totalPrice' => ''
|
||||
)
|
||||
$success = Wiaas_Cart::add_package_to_cart(
|
||||
$request['package_id'],
|
||||
$request['price_id'],
|
||||
$request['cl_id'],
|
||||
$request['addons_ids'],
|
||||
$request['options_ids']
|
||||
);
|
||||
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cart documents
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function get_cart_documents() {
|
||||
return new WP_REST_Response(array(
|
||||
'areFilesUploaded' => true,
|
||||
'templates' => array(),
|
||||
'uploaded' => array()
|
||||
));
|
||||
}
|
||||
public static function remove_package_from_cart($request) {
|
||||
|
||||
/**
|
||||
* Add package to cart
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
* @return WP_REST_Response
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function add_package_to_cart() {
|
||||
$package_id = $_POST['package_id'];
|
||||
$success = Wiaas_Cart::remove_package_from_cart($request['key']);
|
||||
|
||||
$success = WC()->cart->add_to_cart($package_id, 1, 0, array(), array(
|
||||
'_wiaas_standard_package' => true
|
||||
));
|
||||
|
||||
if ($success) {
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'success',
|
||||
'message' => 'PACKAGE_ADDED'
|
||||
)
|
||||
)
|
||||
));
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'error',
|
||||
'message' => 'PACKAGE_ALREADY_IN_CART'
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove package from cart
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
*/
|
||||
public static function remove_package_from_cart() {
|
||||
$package_cart_key = $_POST['package_item_key'];
|
||||
|
||||
$success = WC()->cart->remove_cart_item($package_cart_key);
|
||||
|
||||
if ($success) {
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'success',
|
||||
'message' => 'PACKAGE_REMOVED_FROM_CART'
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'error',
|
||||
'message' => 'INVALID_PACKAGE_FOR_REMOVE'
|
||||
)
|
||||
)
|
||||
));
|
||||
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update package quantity in cart
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function update_package_quantity() {
|
||||
$package_item_key = $_POST['package_item_key'];
|
||||
$new_quantity = $_POST['quantity'];
|
||||
public static function update_package_quantity($request) {
|
||||
|
||||
$success = WC()->cart->set_quantity($package_item_key, $new_quantity, true);
|
||||
$success = Wiaas_Cart::update_package_quantity($request['key'], $request['quantity']);
|
||||
|
||||
if ($success) {
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'success',
|
||||
'message' => 'QUANTITY_UPDATED'
|
||||
)
|
||||
)
|
||||
));
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'error',
|
||||
'message' => 'QUANTITY_NOT_UPDATED'
|
||||
)
|
||||
)
|
||||
));
|
||||
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||
}
|
||||
|
||||
/**
|
||||
* Placing order as part of checkout process
|
||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
||||
* @return WP_REST_Response
|
||||
* @throws Exception
|
||||
* Retrive cart documents info
|
||||
*
|
||||
* @return mixed|WP_REST_Response
|
||||
*/
|
||||
public static function place_order() {
|
||||
public static function get_cart_documents() {
|
||||
return rest_ensure_response( Wiaas_Cart::get_cart_documents());
|
||||
}
|
||||
|
||||
$details = $_POST['details'];
|
||||
$vat_code = $_POST['vat'];
|
||||
$company_name = $_POST['companyName'];
|
||||
$delivery_address = $_POST['delivery'];
|
||||
$billing_address = $_POST['billing'];
|
||||
/**
|
||||
* Upload document to cart
|
||||
* @param WP_REST_Request $request
|
||||
*
|
||||
* @return mixed|WP_REST_Response
|
||||
*/
|
||||
public static function upload_cart_document($request) {
|
||||
$success = Wiaas_Cart::upload_cart_document($request['doc_type'], $request['package_key']);
|
||||
|
||||
$order_id = WC()->checkout()->create_order(array());
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
// set order currency
|
||||
$line_items = $order->get_items();
|
||||
foreach ($line_items as $line_item) {
|
||||
if (isset($line_item['wiaas_currency'])) {
|
||||
$order->set_currency($line_item['wiaas_currency']);
|
||||
break;
|
||||
}
|
||||
if (!$success) {
|
||||
return (wc_notice_count('error') > 0) ?
|
||||
wiaas_api_cart_error_notices() :
|
||||
wiaas_api_generate_error('UPLOAD_ERROR');
|
||||
}
|
||||
|
||||
$order->set_shipping_city($delivery_address['city']);
|
||||
$order->set_shipping_country($delivery_address['countryName']);
|
||||
$order->set_shipping_address_1($delivery_address['detailedAddress']);
|
||||
$order->set_shipping_postcode($delivery_address['zipCode']);
|
||||
return wiaas_api_notice('FILE_UPLOADED', 'success');
|
||||
}
|
||||
|
||||
$order->set_billing_city($billing_address['city']);
|
||||
$order->set_billing_country($billing_address['countryName']);
|
||||
$order->set_billing_address_1($billing_address['detailedAddress']);
|
||||
$order->set_billing_postcode($billing_address['zipCode']);
|
||||
$order->set_billing_first_name($billing_address['firstName']);
|
||||
$order->set_billing_last_name($billing_address['lastName']);
|
||||
|
||||
$order->payment_complete();
|
||||
/**
|
||||
* Download cart document
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_cart_document($request) {
|
||||
Wiaas_Document_Download::download_cart_document(
|
||||
$request['key'],
|
||||
$request['type'],
|
||||
$request['document_key']);
|
||||
}
|
||||
|
||||
|
||||
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
|
||||
add_post_meta($order_id, '_wiaas_company_name', $company_name);
|
||||
add_post_meta($order_id, '_wiaas_project_id', $details['idProject']);
|
||||
add_post_meta($order_id, '_wiaas_reference', $details['reference']);
|
||||
add_post_meta($order_id, '_wiaas_tender', $details['tender']);
|
||||
/**
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function checkout($request) {
|
||||
|
||||
// $order->get_li
|
||||
Wiaas_Checkout::process_checkout($request->get_body_params());
|
||||
|
||||
WC()->cart->empty_cart( true );
|
||||
if (wc_notice_count('error') > 0) {
|
||||
return wiaas_api_cart_error_notices();
|
||||
}
|
||||
|
||||
return new WP_REST_Response(array(
|
||||
'messages' => array(
|
||||
array(
|
||||
'code' => 'success',
|
||||
'message' => 'ORDER_PLACED'
|
||||
)
|
||||
),
|
||||
'details' => $details
|
||||
));
|
||||
return wiaas_api_notice('ORDER_PLACED', 'success');
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -17,26 +16,101 @@ class Wiaas_Document_API {
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'download-package-file', array(
|
||||
register_rest_route( self::$namespace, 'documents', array(
|
||||
'methods' => 'GET',
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'callback' => array(__CLASS__, 'download_package_file'),
|
||||
'args' => array(
|
||||
'document_id' => array(
|
||||
'description' => __( 'Document ID.', 'wiaas' ),
|
||||
'type' => 'integer',
|
||||
'sanitize_callback' => 'absint',
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, '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',
|
||||
)
|
||||
),
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'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
|
||||
),
|
||||
'key' => array(
|
||||
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'required' => true
|
||||
),
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
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
|
||||
),
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Download package document
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_package_file() {
|
||||
$document_id = $_GET['document_id'];
|
||||
$package_id = $_GET['package_id'];
|
||||
public static function download_package_file($request) {
|
||||
$document_id = $request['document_id'];
|
||||
|
||||
$package = wc_get_product($package_id);
|
||||
Wiaas_Document_Download::download_document($document_id);
|
||||
}
|
||||
|
||||
$file = $package->get_file($document_id);
|
||||
/**
|
||||
* Download order item document
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_order_item_document($request) {
|
||||
Wiaas_Document_Download::download_order_item_document(
|
||||
$request['id'],
|
||||
$request['item_id'],
|
||||
$request['key']);
|
||||
}
|
||||
|
||||
if ($file) {
|
||||
WC_Download_Handler::download_file_force($package->get_file_download_path($document_id), $file->get_name());
|
||||
}
|
||||
/**
|
||||
* Download order document
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
*/
|
||||
public static function download_order_other_document($request) {
|
||||
Wiaas_Document_Download::download_order_other_document($request['id'], $request['key']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Order_Projects_API {
|
||||
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
private static $rest_base = 'order-projects';
|
||||
|
||||
public static function register_routes() {
|
||||
|
||||
register_rest_route( self::$namespace, '/' . self::$rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( __CLASS__, 'get_order_projects' ),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( __CLASS__, 'create_order_project' ),
|
||||
'permission_callback' => 'is_user_logged_in',
|
||||
'args' => array(
|
||||
'name' => array(
|
||||
'type' => 'string',
|
||||
'description' => __( 'Order project name.', 'wiaas' ),
|
||||
'required' => true,
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'validate_callback' => function($param, $request, $key) {
|
||||
if ($param === '') {
|
||||
return new WP_Error(
|
||||
'rest_invalid_param',
|
||||
'Order project name cannot be empty!'
|
||||
);
|
||||
}
|
||||
if (strlen($param) > 100) {
|
||||
return new WP_Error(
|
||||
'rest_invalid_param',
|
||||
'Order project name cannot be longer than 100 characters!'
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves available order projects
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function get_order_projects() {
|
||||
$projects = Wiaas_Order_Project::get_available_order_projects();
|
||||
|
||||
return rest_ensure_response($projects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new available order project
|
||||
*
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public static function create_order_project($request) {
|
||||
$name = $request['name'];
|
||||
|
||||
$success = Wiaas_Order_Project::add_order_project($name);
|
||||
if ($success) {
|
||||
return wiaas_api_notice('PROJECT_ADDED', 'success');
|
||||
}
|
||||
|
||||
return wiaas_api_notice('INVALID_DATA', 'error');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?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.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public function __construct() {
|
||||
|
||||
include_once dirname( __FILE__ ) . '/../user/class-wiaas-customer.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'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses/(?P<address_id>\d+)', array(
|
||||
'methods' => 'DELETE',
|
||||
'callback' => array(__CLASS__, 'delete_customer_profile_address'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/billing-addresses', array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(__CLASS__, 'update_customer_billing_addresses'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/billing-addresses/(?P<address_id>\d+)', array(
|
||||
'methods' => 'DELETE',
|
||||
'callback' => array(__CLASS__, 'delete_customer_billing_addresses'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/personal-info', array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(__CLASS__, 'update_customer_personal_info'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/company-info', array(
|
||||
'methods' => 'PUT',
|
||||
'callback' => array(__CLASS__, 'update_customer_company_info'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
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){
|
||||
$customer_id = $request['id'];
|
||||
$params = $request->get_body_params();
|
||||
$new_address = json_decode($params['profile_address']);
|
||||
|
||||
if (!Wiaas_Customer::update_customer_profile_addresses($customer_id, $new_address)){
|
||||
return wiaas_api_notice('PROFILE_ADDRESS_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PROFILE_ADDRESS_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
public static function delete_customer_profile_address(WP_REST_Request $request){
|
||||
$customer_id = $request['id'];
|
||||
$address_id = $request['address_id'];
|
||||
|
||||
if (!Wiaas_Customer::delete_customer_profile_address($customer_id, $address_id)){
|
||||
return wiaas_api_notice('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
return wiaas_api_notice('ADDRESS_REMOVED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
public static function update_customer_billing_addresses(WP_REST_Request $request){
|
||||
$customer_id = $request['id'];
|
||||
$params = $request->get_body_params();
|
||||
$new_address = json_decode($params['billing_address']);
|
||||
|
||||
if (!Wiaas_Customer::update_customer_billing_addresses($customer_id, $new_address)){
|
||||
return wiaas_api_notice('BILLING_ADDRESS_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
return wiaas_api_notice('BILLING_ADDRESS_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||
|
||||
}
|
||||
|
||||
public static function delete_customer_billing_addresses(WP_REST_Request $request){
|
||||
$customer_id = $request['id'];
|
||||
$address_id = $request['address_id'];
|
||||
|
||||
if (!Wiaas_Customer::delete_customer_billing_address($customer_id, $address_id)){
|
||||
return wiaas_api_notice('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
return wiaas_api_notice('ADDRESS_REMOVED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
public static function update_customer_personal_info(WP_REST_Request $request){
|
||||
$customer_id = $request['id'];
|
||||
$params = $request->get_body_params();
|
||||
|
||||
$first_name = $params['first_name'];
|
||||
$last_name = $params['last_name'];
|
||||
$phone = $params['phone'];
|
||||
$name = $first_name . ' ' . $last_name;
|
||||
|
||||
if (!is_string($name) || strlen($name) === 1){
|
||||
return wiaas_api_notice('ADD_NAME', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
if (!is_string($phone) || strlen($phone) < 1){
|
||||
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));
|
||||
}
|
||||
|
||||
return wiaas_api_notice('PROFILE_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
public static function update_customer_company_info(WP_REST_Request $request){
|
||||
$customer_id = $request['id'];
|
||||
$params = $request->get_body_params();
|
||||
|
||||
$company_name = $params['company_name'];
|
||||
$vat_code = $params['vat_code'];
|
||||
|
||||
|
||||
if (!is_string($company_name) || strlen($company_name) < 1){
|
||||
return wiaas_api_notice('ADD_COMPANY_NAME', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
if (!is_string($vat_code) || strlen($vat_code) < 1){
|
||||
return wiaas_api_notice('ADD_VAT', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
if (!Wiaas_Customer::update_customer_company_info($customer_id, $company_name, $vat_code)){
|
||||
return wiaas_api_notice('COMPANY_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||
}
|
||||
|
||||
return wiaas_api_notice('COMPANY_UPDATED', 'success', 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) {
|
||||
@@ -93,211 +102,79 @@ class Wiass_REST_Delivery_Process_API {
|
||||
);
|
||||
}
|
||||
|
||||
$response = new WP_REST_Response( $data );
|
||||
return rest_ensure_response($data);
|
||||
}
|
||||
|
||||
return $response;
|
||||
public function get_customer_questionnaires(WP_REST_Request $request) {
|
||||
|
||||
$order_id = absint($request['order_id']);
|
||||
|
||||
$data = Wiaas_Delivery_Process::get_customer_questionnaires_data($order_id);
|
||||
|
||||
return rest_ensure_response($data);
|
||||
}
|
||||
|
||||
public function upload_customer_questionnaire(WP_REST_Request $request) {
|
||||
|
||||
$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){
|
||||
$entry = GFAPI::get_entry($request['entry_id']);
|
||||
if (is_wp_error($entry)){
|
||||
return self::generate_error('Customer acceptance entry not found', 404);
|
||||
}
|
||||
|
||||
$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_acceptance_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;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'documents' => $acceptance_documents,
|
||||
'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
|
||||
'status' => $acceptance_status,
|
||||
'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
|
||||
);
|
||||
|
||||
return new WP_REST_Response($result);
|
||||
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 self::generate_error('Customer acceptance entry not found', 404);
|
||||
}
|
||||
public static function submit_customer_acceptance(WP_REST_Request $request) {
|
||||
|
||||
$status = $request['actionType'];
|
||||
$reason = $request['declineReason'];
|
||||
$status = $request['action_type'];
|
||||
$reason = $request['decline_reason'];
|
||||
|
||||
if (!in_array($status, self::ACCEPTABLE_STATUS)){
|
||||
return self::generate_wiaas_response('ACCEPTANCE_STATUS_MISSING', 'error');
|
||||
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 self::generate_wiaas_response('DECLINE_REASON_EMPTY', 'error');
|
||||
return wiaas_api_notice('DECLINE_REASON_EMPTY', 'error');
|
||||
}
|
||||
|
||||
if (!$installation_declined && (count($uploaded_files)===0)){
|
||||
return self::generate_wiaas_response('ACCEPTANCE_NOT_UPLOADED', 'error');
|
||||
|
||||
$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 self::generate_wiaas_response('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 self::generate_wiaas_response('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 self::generate_wiaas_response('INSTALLATION_DECLINED', 'success');
|
||||
return wiaas_api_notice('INSTALLATION_DECLINED', 'success');
|
||||
}
|
||||
return self::generate_wiaas_response('INSTALLATION_ACCEPTED', '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 self::generate_wiaas_response('NO_FILES_UPLOADED', 'error');
|
||||
public static function upload_customer_acceptance(WP_REST_Request $request){
|
||||
|
||||
$order_id = $request['order_id'];
|
||||
|
||||
$success = Wiaas_Delivery_Process::upload_customer_acceptance_document($order_id);
|
||||
|
||||
|
||||
if ($success) {
|
||||
return wiaas_api_notice('FILE_UPLOADED','success');
|
||||
}
|
||||
|
||||
$entry = GFAPI::get_entry($request['entry_id']);
|
||||
if (is_wp_error($entry)){
|
||||
return self::generate_error('Customer acceptance entry not found', 404);
|
||||
}
|
||||
|
||||
$form = GFAPI::get_form($entry['form_id']);
|
||||
$form_upload_path = GFFormsModel::get_upload_path( $form['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 self::generate_wiaas_response('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 self::generate_wiaas_response('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 self::generate_wiaas_response('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 self::generate_wiaas_response('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 )) {
|
||||
return self::generate_wiaas_response('FILE_UPLOADED','success');
|
||||
}
|
||||
|
||||
return self::generate_wiaas_response('NOT_UPLOADED', 'error');
|
||||
}
|
||||
|
||||
//Helper function
|
||||
private static function generate_error($message, $code = 500){
|
||||
$error = array(
|
||||
'status' => $code,
|
||||
'message' => $message,
|
||||
);
|
||||
|
||||
$result = new WP_REST_Response($error);
|
||||
$result->set_status($code);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function generate_wiaas_response($message, $code, $data = NULL){
|
||||
$response = array(
|
||||
'messages' => [
|
||||
array(
|
||||
'code' => $code,
|
||||
'message' => $message
|
||||
)
|
||||
],
|
||||
'data' => $data
|
||||
);
|
||||
|
||||
return new WP_REST_Response($response);
|
||||
return wiaas_api_notice('NOT_UPLOADED', 'error');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class Wiass_REST_User_API {
|
||||
/**
|
||||
* Endpoint namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $namespace = 'wiaas';
|
||||
|
||||
public function __construct() {
|
||||
include_once dirname( __FILE__ ) . '/../class-wiaas-countries.php';
|
||||
}
|
||||
|
||||
|
||||
public static function register_routes() {
|
||||
register_rest_route( self::$namespace, 'user/validate-token', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => array(__CLASS__, 'validate_token'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
|
||||
register_rest_route( self::$namespace, 'user/get-countries', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => array(__CLASS__, 'get_countries'),
|
||||
'permission_callback' => 'is_user_logged_in'
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
public static function validate_token() {
|
||||
$user = wp_get_current_user();
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'userInfo' => array(
|
||||
'wiaas_id_user' => $user->ID,
|
||||
'wiaas_is_company_admin' => 1, //TODO: don't hardcode this
|
||||
'wiaas_user_full_name' => $user->first_name . ' ' . $user->last_name,
|
||||
'wiaas_user_type' => $user->roles,
|
||||
'wiaas_username' => $user->data->user_login
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public static function get_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();
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Generates REST API notice response
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $code
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_notice($message, $code, $data = null) {
|
||||
return rest_ensure_response(array(
|
||||
'messages' => [
|
||||
array(
|
||||
'code' => $code,
|
||||
'message' => $message
|
||||
)
|
||||
],
|
||||
'data' => $data
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc error notices
|
||||
*
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_error_notices($data = null) {
|
||||
return wiaas_api_cart_notices('error', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc warning notices
|
||||
*
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_warning_notices($data = null) {
|
||||
return wiaas_api_cart_notices('notice', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates REST API notice responses with wc notices
|
||||
*
|
||||
* @param string $types Notice types (error, success)
|
||||
* @param array|null $data
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_cart_notices($types, $data = null) {
|
||||
|
||||
$types = is_array($types) ? $types : array( $types );
|
||||
|
||||
$messages = array();
|
||||
foreach ($types as $type) {
|
||||
$messages = array_merge($messages, wc_get_notices($type));
|
||||
}
|
||||
wc_clear_notices();
|
||||
|
||||
$messages = array_map(function($message) {
|
||||
return array(
|
||||
'code' => 'error',
|
||||
'message' => $message
|
||||
);
|
||||
}, $messages);
|
||||
|
||||
return rest_ensure_response(array(
|
||||
'messages' => $messages,
|
||||
'data' => $data
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate REST API error
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
function wiaas_api_generate_error($message, $code = 500) {
|
||||
$response = rest_ensure_response(array(
|
||||
'status' => $code,
|
||||
'message' => $message,
|
||||
));
|
||||
$response->set_status($code);
|
||||
return $response;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Cart_Documents {
|
||||
|
||||
private static $document_types = array(
|
||||
'template_questionaire' => 'template_agreement',
|
||||
'order_questionaire' => 'order_agreement'
|
||||
);
|
||||
|
||||
public static function get_cart_documents() {
|
||||
$packages_data = Wiaas_Cart::get_cart_packages();
|
||||
|
||||
$templates = array();
|
||||
|
||||
foreach ($packages_data as $package_data) {
|
||||
$package = wc_get_product($packages_data['package_id']);
|
||||
|
||||
$documents = $package->get_downloads();
|
||||
}
|
||||
|
||||
get_terms(array(
|
||||
'taxonomy' => 'wiaas_document_types',
|
||||
'include' => 'template_questionaire, order_questionaire'
|
||||
));
|
||||
}
|
||||
|
||||
private static function _get_packages_templates($packages) {
|
||||
$documents_ids = array_map(function($package) {
|
||||
return array_keys($package->get_downloads());
|
||||
}, $packages);
|
||||
|
||||
wp_get_object_terms($documents_ids, 'wiaas_document_types', array(
|
||||
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatize access control for product and packages
|
||||
*
|
||||
* @param int $post_id
|
||||
* @param WP_Post $post
|
||||
*/
|
||||
public static function maybe_handle_product_access($post_id, $post) {
|
||||
|
||||
// $post_id and $post are required
|
||||
if ( empty( $post_id ) || empty( $post ) || $post->post_type !== 'product') {
|
||||
return;
|
||||
}
|
||||
|
||||
$product = wc_get_product($post_id);
|
||||
|
||||
$access_group = null;
|
||||
|
||||
// if product is not bundle or it not completed set it visible only for admin
|
||||
if ($product->get_type() !== 'bundle' ||
|
||||
$product->get_status() !== 'publish' ||
|
||||
empty(Wiaas_Package_Pricing::get_package_prices($product))) {
|
||||
|
||||
$access_group = Groups_Group::read_by_name('admin');
|
||||
} else {
|
||||
|
||||
$access_group = Groups_Group::read_by_name('Registered');
|
||||
}
|
||||
|
||||
if ($access_group) {
|
||||
Groups_Post_Access::update(
|
||||
array(
|
||||
'post_id' => $product->get_id(),
|
||||
'groups_read' => $access_group->group_id
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignees order to corresponding user organization when order is created.
|
||||
*
|
||||
* @param int $order_id
|
||||
*/
|
||||
public static function assign_order_to_organization($order_id) {
|
||||
// assign order to customer organization
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
// assign order to commercial lead organization
|
||||
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
|
||||
if ($commercial_lead_id) {
|
||||
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,18 +1,50 @@
|
||||
<?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';
|
||||
// Admin documents
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
|
||||
// Admin organization interface
|
||||
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
|
||||
// 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 );
|
||||
}
|
||||
|
||||
|
||||
public static function enqueue_scripts() {
|
||||
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
|
||||
|
||||
wp_enqueue_style( 'wiaas_admin_packages', $plugin_url . '/assets/css/wiaas-admin-package.css' );
|
||||
|
||||
wp_enqueue_script( 'wiaas_admin_packages', $plugin_url . '/assets/js/wiaas-admin-package.js' );
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin::init();
|
||||
|
||||
@@ -34,13 +34,32 @@ class Wiaas_API {
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-delivery-process-api.php';
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-cart-api.php';
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-document-api.php';
|
||||
|
||||
#User controller
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-user-api.php';
|
||||
|
||||
#Customer controller
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-customer.php';
|
||||
|
||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-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';
|
||||
|
||||
}
|
||||
|
||||
public static function register_rest_routes() {
|
||||
$controllers = array(
|
||||
'Wiass_REST_Delivery_Process_API',
|
||||
'Wiaas_Cart_API',
|
||||
'Wiaas_Document_API'
|
||||
'Wiaas_Document_API',
|
||||
'Wiass_REST_User_API',
|
||||
'Wiaas_REST_Customer_API',
|
||||
'Wiaas_Order_Projects_API',
|
||||
'Wiaas_Support_Api',
|
||||
);
|
||||
|
||||
foreach ( $controllers as $controller ) {
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handles user authentication for wiaas
|
||||
*
|
||||
* User roles are inherited from organization
|
||||
*
|
||||
* Class Wiaas_Authentication
|
||||
*/
|
||||
class Wiaas_Authentication {
|
||||
|
||||
const SUPER_ADMIN_USER_ID = 1;
|
||||
|
||||
public static function init() {
|
||||
// authenticate current user
|
||||
add_action('determine_current_user', array(__CLASS__, 'authenticate_current_user'), 999);
|
||||
|
||||
// authenticates user on login
|
||||
add_filter( 'authenticate', array( __CLASS__, 'authenticate_user_on_login' ), 999, 3);
|
||||
|
||||
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 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
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
global $current_user;
|
||||
|
||||
if (empty($current_user)) {
|
||||
|
||||
$current_user = new WP_User($user_id);
|
||||
}
|
||||
|
||||
$rest_api_slug = rest_get_url_prefix();
|
||||
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if ( empty($role) || ! user_can($user_id, 'wiaas_' . $role)) {
|
||||
// not available roles for user
|
||||
$current_user->set_role('');
|
||||
|
||||
return new WP_Error('wiaas_authentication_error', 'No set permissions!', array(
|
||||
'status' => 403,
|
||||
));
|
||||
}
|
||||
|
||||
// authenticate valid admin panel user
|
||||
$current_user->set_role($role);
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
$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) {
|
||||
|
||||
$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,
|
||||
)) :
|
||||
$user;
|
||||
}
|
||||
|
||||
/**
|
||||
* ADMIN PANEL AUTHENTICATION
|
||||
*/
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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';
|
||||
}
|
||||
|
||||
if (empty($role)) {
|
||||
return new WP_Error('wiaas_authentication_error', 'No permissions!', array(
|
||||
'status' => 403,
|
||||
));
|
||||
}
|
||||
|
||||
update_user_meta($user->ID, '_wiaas_admin_role', $role);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Wiaas_Authentication::init();
|
||||
@@ -6,121 +6,301 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
|
||||
/**
|
||||
* TODO: This implementation is temporary and will probably be changed during implementation of currently pending cart task
|
||||
* Handles Wiaas Cart specific tasks
|
||||
*
|
||||
* Class Wiaas_Cart
|
||||
*/
|
||||
class Wiaas_Cart {
|
||||
|
||||
private static $cart_doc_types = array(
|
||||
'template_questionaire' => 'order_questionaire',
|
||||
'template_agreement' => 'order_agreement'
|
||||
);
|
||||
|
||||
|
||||
public static function init() {
|
||||
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
|
||||
|
||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||
|
||||
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
|
||||
|
||||
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 options and addons to cart.
|
||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve cart documents (templates and uploded documents)
|
||||
* @return array
|
||||
*/
|
||||
public static function get_cart_documents() {
|
||||
$templates = self::_get_cart_templates();
|
||||
$uploaded_documents = self::_get_cart_uploaded_documents();
|
||||
|
||||
$has_pending_uploads = false;
|
||||
|
||||
foreach ($templates as $type => $package_documents) {
|
||||
$uploaded_type = self::$cart_doc_types[$type];
|
||||
|
||||
if (!isset($uploaded_documents[$uploaded_type])) {
|
||||
$has_pending_uploads = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$uploaded_package_documents = $uploaded_documents[$uploaded_type];
|
||||
|
||||
foreach ($package_documents as $package_id => $package_document) {
|
||||
if (!isset($uploaded_package_documents[$package_id])) {
|
||||
$has_pending_uploads = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'templates' => $templates,
|
||||
'uploaded' => $uploaded_documents,
|
||||
'pending' => $has_pending_uploads
|
||||
);
|
||||
}
|
||||
|
||||
/** Uploaded document for cart
|
||||
*
|
||||
* @param $doc_type
|
||||
* @param $package_item_key
|
||||
*
|
||||
* @return string | WP_Error
|
||||
*/
|
||||
public static function upload_cart_document($doc_type, $package_item_key) {
|
||||
try {
|
||||
$result = Wiaas_Document_Upload::upload_document_version();
|
||||
|
||||
// File upload failed
|
||||
if (is_wp_error($result)) {
|
||||
$code = $result->get_error_code();
|
||||
|
||||
if ($code === 'wiaas_upload_error_missing_file' || $code === 'wiaas_upload_error_invalid_extension') {
|
||||
wc_add_notice($result->get_error_message(), 'error');
|
||||
} else {
|
||||
wc_add_notice('File upload failed!', 'error');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// save uploaded cart documents info to cart item
|
||||
WC()->cart->cart_contents[ $package_item_key ]['_wiaas_documents'][$doc_type] = array(
|
||||
'version' => $result,
|
||||
'key' => wp_generate_uuid4(),
|
||||
);;
|
||||
|
||||
// persist changes
|
||||
WC()->cart->calculate_totals();
|
||||
|
||||
return true;
|
||||
|
||||
} catch( Exception $e) {
|
||||
wc_add_notice('Could not upload cart document!', 'error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles adding standard wiaas package to cart along with selected addons and options
|
||||
*
|
||||
* Extend cart item data with wiaas package payment info and addons and options
|
||||
*
|
||||
* Every package cart item will be extended with its payment info but only standard package type
|
||||
* will be extended with addons and options arrays
|
||||
*
|
||||
* @param $cart_item_data
|
||||
* @param $package_id
|
||||
* @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 array
|
||||
* @return bool TRUE if all packages are succesfully added to cart, FALSE otherwise
|
||||
*/
|
||||
public static function add_cart_item_data($cart_item_data, $package_id) {
|
||||
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
|
||||
if (self::_is_package_in_cart($package_id)) {
|
||||
wc_add_notice('Package already in cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
$is_valid = isset( $_POST[ 'price_id' ]) &&
|
||||
WC_Product_Factory::get_product_type( $package_id ) === 'bundle';
|
||||
//Check if package exists
|
||||
$package = wc_get_product( $package_id );
|
||||
if (!$package) {
|
||||
wc_add_notice('Package does not exists!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$is_valid) {
|
||||
return $cart_item_data;
|
||||
//Check if package is available for adding to cart
|
||||
if (Wiaas_Package_Status::get_package_status($package_id) !== Wiaas_Package_Status::AVAILABLE){
|
||||
wc_add_notice('Package cannot be purchased at the moment!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Retrieve package country
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
if (empty($country)) {
|
||||
wc_add_notice('Package cannot be added do cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// Retrieve package price
|
||||
$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
|
||||
$wiaas_cart_item_data = array(
|
||||
'_wiaas_standard_package' => true,
|
||||
'_wiaas_addon_items' => array(),
|
||||
'_wiaas_option_items' => array(),
|
||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||
'_wiaas_documents' => array()
|
||||
);
|
||||
|
||||
$cart_item_key = WC()->cart->add_to_cart($package_id, 1, 0, array(), $wiaas_cart_item_data);
|
||||
|
||||
if (!$cart_item_key) {
|
||||
wc_add_notice('Package could not be added to cart!', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add selected additional packages and options
|
||||
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids);
|
||||
|
||||
// Trigger calculation of total prices after additional packages are added
|
||||
WC()->cart->calculate_totals();
|
||||
|
||||
return true;
|
||||
|
||||
} catch( Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove given package item key from cart
|
||||
*
|
||||
* @param string $package_cart_item_key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function remove_package_from_cart($package_cart_item_key) {
|
||||
|
||||
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||
|
||||
if (!$cart_item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$package_type = Wiaas_Package_Type::get_package_type($package_id);
|
||||
$package_addon_item_keys = $cart_item['_wiaas_addon_items'];
|
||||
$package_option_item_keys = $cart_item['_wiaas_option_items'];
|
||||
|
||||
$package = wc_get_product( $package_id );
|
||||
$success = WC()->cart->remove_cart_item($package_cart_item_key);
|
||||
|
||||
switch ($package_type) {
|
||||
case 'standard':
|
||||
if ($success) {
|
||||
foreach ($package_addon_item_keys as $package_addon_item_key) {
|
||||
WC()->cart->remove_cart_item($package_addon_item_key);
|
||||
}
|
||||
|
||||
$cart_item['_wiaas_standard_package'] = true;
|
||||
|
||||
// Prepare addons additional data for later use.
|
||||
if ( ! isset( $cart_item_data['_wiaas_addon_items'] ) ) {
|
||||
$cart_item_data['_wiaas_addon_items' ] = array();
|
||||
}
|
||||
// Prepare options additional data for later use.
|
||||
if ( ! isset( $cart_item_data['_wiaas_option_items'] ) ) {
|
||||
$cart_item_data['_wiaas_option_items' ] = array();
|
||||
}
|
||||
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
if (isset($country)) {
|
||||
$cart_item_data['_wiaas_currency'] = $country['currency'];
|
||||
}
|
||||
|
||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
break;
|
||||
case 'add_on':
|
||||
$parent_key = $cart_item_data['_wiaas_addon_for'];
|
||||
$parent_item = WC()->cart->get_cart_item($parent_key);
|
||||
|
||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($package, $parent_item['data']);
|
||||
break;
|
||||
case 'option':
|
||||
$parent_key = $cart_item_data['_wiaas_option_for'];
|
||||
$parent_item = WC()->cart->get_cart_item($parent_key);
|
||||
|
||||
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $package);
|
||||
$cart_item_data['_wiaas_option_group_name' ] = $option_group_name;
|
||||
|
||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price($package, $parent_item['data']);
|
||||
break;
|
||||
foreach ($package_option_item_keys as $package_option_item_key) {
|
||||
WC()->cart->remove_cart_item($package_option_item_key);
|
||||
}
|
||||
}
|
||||
|
||||
$selected_price_index = array_search($_POST['price_id'], array_column($package_prices, 'id'));
|
||||
|
||||
if (is_numeric($selected_price_index) && isset($package_prices[$selected_price_index])) {
|
||||
$cart_item_data['_wiaas_payment'] = $package_prices[$selected_price_index];
|
||||
}
|
||||
|
||||
return $cart_item_data;
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add selected package options and addons after parent standard package is added to cart
|
||||
* Update quantity of package in cart
|
||||
* @param string $package_cart_item_key
|
||||
* @param int $new_quantity
|
||||
*
|
||||
* @param $cart_item_key
|
||||
* @param $package_id
|
||||
* @param $quantity
|
||||
* @param $variation_id
|
||||
* @param $variation
|
||||
* @param $cart_item_data
|
||||
* @return bool
|
||||
*/
|
||||
public static function add_additional_packages_to_cart($cart_item_key, $package_id, $quantity, $variation_id, $variation, $cart_item_data) {
|
||||
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);
|
||||
|
||||
remove_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ));
|
||||
if (!$cart_item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::_add_options_to_cart($cart_item_key, $package_id, $cart_item_data);
|
||||
$package_addon_item_keys = $cart_item['_wiaas_addon_items'];
|
||||
$package_option_item_keys = $cart_item['_wiaas_option_items'];
|
||||
|
||||
self::_add_addons_to_cart($cart_item_key, $package_id, $cart_item_data);
|
||||
$success = WC()->cart->set_quantity($package_cart_item_key, $new_quantity, true);
|
||||
|
||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
|
||||
if ($success) {
|
||||
foreach ($package_addon_item_keys as $package_addon_item_key) {
|
||||
WC()->cart->set_quantity($package_addon_item_key, $new_quantity, true);
|
||||
}
|
||||
|
||||
foreach ($package_option_item_keys as $package_option_item_key) {
|
||||
WC()->cart->set_quantity($package_option_item_key, $new_quantity, true);
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update package cart item with `minimal_fixed_price` as its price
|
||||
* so resulting totals would be sum of these prices
|
||||
@@ -142,18 +322,26 @@ 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
|
||||
* @param $cart_item
|
||||
* @param $order
|
||||
*
|
||||
* @return array
|
||||
* @return WC_Order_Item
|
||||
*/
|
||||
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
|
||||
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
|
||||
|
||||
$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'];
|
||||
|
||||
@@ -171,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'])) {
|
||||
@@ -193,6 +378,70 @@ class Wiaas_Cart {
|
||||
if (isset($cart_item['_wiaas_addon_for'])) {
|
||||
$order_item->add_meta_data( '_wiaas_addon_for', $cart_item['_wiaas_addon_for'], true );
|
||||
}
|
||||
|
||||
// add documents associated with the item
|
||||
$cart_documents = isset($cart_item['_wiaas_documents']) ? $cart_item['_wiaas_documents'] : array();
|
||||
$attachment_document_ids = wiaas_get_object_attached_documents($cart_item['product_id']);
|
||||
$item_documents = array();
|
||||
|
||||
foreach ($cart_documents as $type => $cart_document) {
|
||||
$item_documents[] = array(
|
||||
'key' => $cart_document['key'],
|
||||
'version' => $cart_document['version'],
|
||||
'type' => $type
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($attachment_document_ids as $attachment_document_id) {
|
||||
$doc_info = Wiaas_Document::get_doc_info($attachment_document_id);
|
||||
|
||||
// add customer visible attachment documents to order
|
||||
if ($doc_info['visible'] || !$doc_info['type']) {
|
||||
$item_documents[] = array(
|
||||
'key' => wp_generate_uuid4(),
|
||||
'name' => $doc_info['name'],
|
||||
'version' => $doc_info['version'],
|
||||
'type' => $doc_info['type']['id'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($item_documents) > 0) {
|
||||
$order_item->add_meta_data( '_wiaas_documents', $item_documents, true );
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,10 +466,121 @@ class Wiaas_Cart {
|
||||
'_wiaas_option_for',
|
||||
'_wiaas_option_group_name',
|
||||
'_wiaas_standard_package',
|
||||
'_wiaas_currency',
|
||||
'_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
|
||||
*
|
||||
@@ -264,72 +624,335 @@ class Wiaas_Cart {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves count of wiaas standard packages in cart
|
||||
*
|
||||
* @return int Number of wiaas standard packages in cart
|
||||
*/
|
||||
public static function get_cart_packages_count() {
|
||||
$items = WC()->cart->get_cart_contents();
|
||||
|
||||
return array_reduce($items, function($count, $item) {
|
||||
if (isset($item['_wiaas_standard_package'])) {
|
||||
$count++;
|
||||
}
|
||||
return $count;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves packages data from cart
|
||||
* @return array
|
||||
*/
|
||||
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) {
|
||||
if (!isset($item['_wiaas_standard_package'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$package = wc_get_product($item['product_id']);
|
||||
|
||||
// Collect additional packages
|
||||
$additional_packages = array_map(
|
||||
function($addon_cart_item) {
|
||||
$additional_package = wc_get_product($addon_cart_item['product_id']);
|
||||
return array(
|
||||
'package_id' => $additional_package->get_id(),
|
||||
'package_name' => $additional_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixed_extra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrent_extra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||
'services_extra' => $addon_cart_item['_wiaas_payment']['services_extra'],
|
||||
)
|
||||
);
|
||||
},
|
||||
wiaas_get_cart_item_addons($item));
|
||||
|
||||
|
||||
// Collect package options
|
||||
$package_options = array_map(
|
||||
function($option_cart_item) {
|
||||
$option_package = wc_get_product($option_cart_item['product_id']);
|
||||
return array(
|
||||
'package_id' => $option_package->get_id(),
|
||||
'group_name' => $option_cart_item['_wiaas_option_group_name'],
|
||||
'package_name' => $option_package->get_title(),
|
||||
'prices' => array(
|
||||
'fixed_extra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrent_extra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||
'services_extra' => $option_cart_item['_wiaas_payment']['services_extra'],
|
||||
)
|
||||
);
|
||||
},
|
||||
wiaas_get_cart_item_options($item));
|
||||
|
||||
$package_items[] = array(
|
||||
'package_id' => $item['product_id'],
|
||||
'key' => $item['key'],
|
||||
'package_name' => $package->get_title(),
|
||||
'quantity' => $item['quantity'],
|
||||
|
||||
'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,
|
||||
'additional_packages' => $additional_packages,
|
||||
|
||||
'are_options_available' => true,
|
||||
'options' => $package_options,
|
||||
|
||||
'bids' => array(),
|
||||
|
||||
'payment_info' => array(
|
||||
'id' => $item['_wiaas_payment']['id'],
|
||||
'type' => $item['_wiaas_payment']['payment_type'],
|
||||
'period_unit' => $item['_wiaas_payment']['period_unit'],
|
||||
'fixed_extra' => $item['_wiaas_payment']['fixed_extra'],
|
||||
'recurrent_extra' => $item['_wiaas_payment']['recurrent_extra'],
|
||||
'services_extra' => $item['_wiaas_payment']['services_extra'],
|
||||
),
|
||||
|
||||
'total_prices' => Wiaas_Cart::get_cart_item_total($item),
|
||||
|
||||
'status' => 'available',
|
||||
);
|
||||
}
|
||||
|
||||
return $package_items;
|
||||
}
|
||||
|
||||
|
||||
//PRIVATE
|
||||
|
||||
/**
|
||||
* Add selected package options to cart
|
||||
* @param $cart_item_key
|
||||
* @param $package_id
|
||||
* @param $cart_item_data
|
||||
*
|
||||
* @throws Exception
|
||||
* Retrieve cart templates
|
||||
* @return array
|
||||
*/
|
||||
private static function _add_options_to_cart($cart_item_key, $package_id, $cart_item_data) {
|
||||
$is_option_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_option_items']);
|
||||
$has_selected_options = isset($_POST['options']) && is_array($_POST['options']);
|
||||
private static function _get_cart_templates() {
|
||||
$items = WC()->cart->get_cart_contents();
|
||||
|
||||
if ($is_option_parent && $has_selected_options) {
|
||||
$documents_ids = array();
|
||||
|
||||
$options_ids = $_POST['options'];
|
||||
// Retrieve all document ids attached to cart content
|
||||
foreach ($items as $key => $item) {
|
||||
if (!isset($item['_wiaas_standard_package'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($options_ids as $option_id) {
|
||||
$option_package = wc_get_product($option_id);
|
||||
if (is_object($option_package)) {
|
||||
$package_documents_ids = get_post_meta(
|
||||
$item['product_id'],
|
||||
'_wiaas_attached_documents',
|
||||
true);
|
||||
|
||||
$option_cart_item_key = WC()->cart->add_to_cart($option_id, 1, 0, array(), array(
|
||||
'_wiaas_option_for' => $cart_item_key
|
||||
));
|
||||
|
||||
if ($option_cart_item_key) {
|
||||
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_option_items'][] = $option_cart_item_key;
|
||||
}
|
||||
}
|
||||
foreach ($package_documents_ids as $package_document_id) {
|
||||
$package_document_id = absint($package_document_id);
|
||||
$documents_ids[$package_document_id] ?: array();
|
||||
$documents_ids[$package_document_id][] = $item['product_id'];
|
||||
}
|
||||
}
|
||||
|
||||
// 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), // templates only
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
$cart_documents = array();
|
||||
|
||||
foreach ($retrieved_items as $retrieved_item) {
|
||||
|
||||
$doc_info = Wiaas_Document::get_doc_info($retrieved_item->ID);
|
||||
$type = $doc_info['type']['id'];
|
||||
|
||||
$cart_documents[$type] ?: array();
|
||||
|
||||
$package_ids = $documents_ids[$doc_info['id']] ?: array();
|
||||
foreach ($package_ids as $package_id) {
|
||||
$cart_documents[$type][$package_id] = array(
|
||||
'id' => $doc_info['id'],
|
||||
'name' => $doc_info['name'],
|
||||
'type' => $type,
|
||||
'extension' => $doc_info['extension']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $cart_documents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add selected package addons to cart
|
||||
*
|
||||
* @param $cart_item_key
|
||||
* @param $package_id
|
||||
* @param $cart_item_data
|
||||
*
|
||||
* @throws Exception
|
||||
* Retrieve cart uploaded documents
|
||||
* @return array
|
||||
*/
|
||||
private static function _add_addons_to_cart($cart_item_key, $package_id, $cart_item_data) {
|
||||
private static function _get_cart_uploaded_documents() {
|
||||
$items = WC()->cart->get_cart_contents();
|
||||
|
||||
$is_addon_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_addon_items']);
|
||||
$has_selected_addons = isset($_POST['addons']) && is_array($_POST['addons']);
|
||||
$cart_documents = array();
|
||||
|
||||
if ($is_addon_parent && $has_selected_addons) {
|
||||
$addons_ids = $_POST['addons'];
|
||||
foreach ($items as $key => $item) {
|
||||
if (!isset($item['_wiaas_standard_package'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
$addon_package = wc_get_product($addon_id);
|
||||
if (is_object($addon_package)) {
|
||||
$package_id = $item['product_id'];
|
||||
|
||||
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id, 1, 0, array(), array(
|
||||
'_wiaas_addon_for' => $cart_item_key
|
||||
));
|
||||
$documents = isset($item['_wiaas_documents']) ? $item['_wiaas_documents'] : array();
|
||||
|
||||
if ($addon_cart_item_key) {
|
||||
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_addon_items'][] = $addon_cart_item_key;
|
||||
}
|
||||
}
|
||||
foreach ($documents as $type => $document) {
|
||||
$cart_documents[$type] ?: array();
|
||||
$cart_documents[$type][$package_id] = array(
|
||||
'key' => $document['key'],
|
||||
'name' => wiaas_get_doc_version_filename($document['version']),
|
||||
'type' => $type,
|
||||
'extension' => wiaas_get_doc_version_extension($document['version'])
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $cart_documents;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add selected package options and addons after parent standard package is added to cart
|
||||
*
|
||||
* @param string $package_cart_item_key
|
||||
* @param int $price_id
|
||||
* @param int $shop_owner_id
|
||||
* @param array $addons_ids
|
||||
* @param array $options_ids
|
||||
*
|
||||
* @throws Exception if any of the addons or options cannot be added to cart
|
||||
*/
|
||||
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
|
||||
|
||||
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||
|
||||
$addon_items_keys = array();
|
||||
$option_items_keys = array();
|
||||
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
|
||||
// Try adding package addons to cart
|
||||
foreach ($addons_ids as $addon_id) {
|
||||
//Check if addon package exists
|
||||
$addon_package = wc_get_product($addon_id);
|
||||
if (!$addon_package) {
|
||||
throw new Exception( __( 'Sorry, additional package does not exist.', 'wiaas' ) );
|
||||
}
|
||||
|
||||
// Retrieve addon package price
|
||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price(
|
||||
$addon_package,
|
||||
$parent_item['data'],
|
||||
$customer_id,
|
||||
$shop_owner_id
|
||||
);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Initialize additional cart item data for wiaas addon packages
|
||||
$wiaas_addon_cart_item_data = array(
|
||||
'_wiaas_addon_for' => $package_cart_item_key,
|
||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null
|
||||
);
|
||||
|
||||
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id,
|
||||
1,
|
||||
0,
|
||||
array(),
|
||||
$wiaas_addon_cart_item_data
|
||||
);
|
||||
|
||||
if (!$addon_cart_item_key) {
|
||||
throw new Exception( __( 'Sorry, additional package could not be added to cart.', 'wiaas' ) );
|
||||
}
|
||||
|
||||
$addon_items_keys[] = $addon_cart_item_key;
|
||||
}
|
||||
|
||||
// Try adding package options to cart
|
||||
foreach ($options_ids as $option_id) {
|
||||
//Check if option package exists
|
||||
$option_package = wc_get_product($option_id);
|
||||
if (!$option_package) {
|
||||
throw new Exception( __( 'Sorry, option package does not exist.', 'wiaas' ) );
|
||||
}
|
||||
|
||||
// Retrieve option package price
|
||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price(
|
||||
$option_package,
|
||||
$parent_item['data'],
|
||||
$customer_id,
|
||||
$shop_owner_id);
|
||||
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||
|
||||
// Retrieve option package group name
|
||||
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $option_package);
|
||||
|
||||
|
||||
// Initialize additional cart item data for wiaas option packages
|
||||
$wiaas_option_cart_item_data = array(
|
||||
'_wiaas_option_for' => $package_cart_item_key,
|
||||
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||
'_wiaas_option_group_name' => $option_group_name,
|
||||
);
|
||||
|
||||
$option_cart_item_key = WC()->cart->add_to_cart($option_id,
|
||||
1,
|
||||
0,
|
||||
array(),
|
||||
$wiaas_option_cart_item_data
|
||||
);
|
||||
|
||||
if (!$option_cart_item_key) {
|
||||
throw new Exception( __( 'Sorry, package option could not be added to cart.', 'wiaas' ) );
|
||||
}
|
||||
|
||||
$option_items_keys[] = $option_cart_item_key;
|
||||
}
|
||||
|
||||
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_addon_items'] = $addon_items_keys;
|
||||
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_option_items'] = $option_items_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if package is added to cart
|
||||
* @param int $package_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function _is_package_in_cart($package_id) {
|
||||
$cart_item = WC()->cart->get_cart_contents();
|
||||
|
||||
foreach ($cart_item as $item) {
|
||||
if($item['product_id'] === $package_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
102
backend/app/plugins/wiaas/includes/class-wiaas-checkout.php
Normal file
102
backend/app/plugins/wiaas/includes/class-wiaas-checkout.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Checkout {
|
||||
|
||||
public static function init(){
|
||||
add_action( 'woocommerce_check_cart_items', array(__CLASS__, 'validate_wiaas_packages'));
|
||||
}
|
||||
|
||||
public static function validate_wiaas_packages(){
|
||||
//check if any package became invalid
|
||||
$items = WC()->cart->get_cart();
|
||||
foreach($items as $item) {
|
||||
$item_id = $item['data']->get_id();
|
||||
if (wc_pb_is_bundle_container_cart_item($item) &&
|
||||
(Wiaas_Package_Status::get_package_status($item_id) !== Wiaas_Package_Status::AVAILABLE)){
|
||||
wc_add_notice( 'Package ' . $item['data']->get_title() . ' cannot be purchased at the moment', 'error' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the order checkout.
|
||||
*
|
||||
* @param array $data Posted data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function process_checkout($data) {
|
||||
try {
|
||||
|
||||
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
|
||||
wc_set_time_limit( 0 );
|
||||
|
||||
do_action( 'woocommerce_before_checkout_process' );
|
||||
|
||||
// Check if cart empty before proceeding
|
||||
if (WC()->cart->is_empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_checkout_process' );
|
||||
|
||||
// Validate cart items before proceeding
|
||||
WC()->checkout()->check_cart_items();
|
||||
|
||||
// if something is wrong bail out
|
||||
if(wc_notice_count( 'error' ) > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// try processing order
|
||||
$order_id = WC()->checkout()->create_order($data);
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
if ( is_wp_error( $order_id ) ) {
|
||||
throw new Exception( $order_id->get_error_message() );
|
||||
}
|
||||
|
||||
if ( ! $order ) {
|
||||
throw new Exception( __( 'Unable to create order.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
self::_add_wiaas_checkout_data($order, $data);
|
||||
|
||||
do_action( 'woocommerce_checkout_order_processed', $order_id, array(), $order );
|
||||
|
||||
//Change order status from default 'Pending payment' to open (custom wiaas status)
|
||||
$order->update_status('open');
|
||||
|
||||
WC()->cart->empty_cart( true );
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
wc_add_notice( $e->getMessage(), 'error' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional wiaas checkout info for order
|
||||
* @param $order
|
||||
* @param array $data
|
||||
*/
|
||||
private static function _add_wiaas_checkout_data($order, $data) {
|
||||
|
||||
// save additional wiaas order info
|
||||
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
|
||||
Wiaas_Order::set_order_company($order->get_id(), $data['company_name']);
|
||||
Wiaas_Order::set_order_reference($order->get_id(), $data['reference']);
|
||||
Wiaas_Order::set_order_tender($order->get_id(), $data['tender']);
|
||||
|
||||
// add order to project
|
||||
if (isset($data['project_id'])) {
|
||||
Wiaas_Order_Project::set_project_for_order($order->get_id(), $data['project_id']);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Checkout::init();
|
||||
@@ -12,25 +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(
|
||||
'name' => 'Sweden',
|
||||
'code' => 'se',
|
||||
private static $default_countries = array(
|
||||
'se' => array(
|
||||
'vat' => 9 ,
|
||||
'currency' => 'SEK'
|
||||
),
|
||||
'Denmark' => array(
|
||||
'name' => 'Denmark',
|
||||
'code' => 'dk',
|
||||
'dk' => array(
|
||||
'vat' => 9 ,
|
||||
'currency' => 'DKK'
|
||||
),
|
||||
'Finland' => array(
|
||||
'name' => 'Finland',
|
||||
'code' => 'fi',
|
||||
'fi' => array(
|
||||
'vat' => 9 ,
|
||||
'currency' => 'EUR'
|
||||
),
|
||||
@@ -41,6 +35,103 @@ class Wiaas_Countries {
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers product taxonomy for avaiable countries
|
||||
*/
|
||||
@@ -72,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']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,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,15 +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',
|
||||
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
|
||||
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
|
||||
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
|
||||
'20180826153509' => 'wiaas_create_broker_access_group',
|
||||
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
|
||||
'20180912101010' => 'wiaas_db_setup_default_cl'
|
||||
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
|
||||
'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') );
|
||||
|
||||
@@ -5,98 +5,21 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements Wiaas Document types
|
||||
* Implements Wiaas Documents
|
||||
*
|
||||
* Class Wiaas_Documents
|
||||
*/
|
||||
class Wiaas_Documents {
|
||||
|
||||
/**
|
||||
* Default available document types for wiaas
|
||||
* @var array
|
||||
*/
|
||||
private static $available_doc_types = array(
|
||||
'template_questionaire' => array(
|
||||
'name' => 'Template Questionaire',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'order_questionaire' => array(
|
||||
'name' => 'Order Questionaire',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'configuration' => array(
|
||||
'name' => 'Configuration',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'install_guide' => array(
|
||||
'name' => 'Install guide',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'customer_acceptance' => array(
|
||||
'name' => 'Customer acceptance',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'template_agreement' => array(
|
||||
'name' => 'Template Agreement',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'order_agreement' => array(
|
||||
'name' => 'Order Agreement',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'installation_protocol' => array(
|
||||
'name' => 'Installation protocol',
|
||||
'is_special_type' => true,
|
||||
),
|
||||
'statements' => array(
|
||||
'name' => 'Statements',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
'customer_acceptance_template' => array(
|
||||
'name' => 'Customer acceptance template',
|
||||
'is_special_type' => false,
|
||||
),
|
||||
);
|
||||
|
||||
public static function init() {
|
||||
add_action( 'init', array( __CLASS__, 'register_wiaas_document_types' ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers taxonomy and default values for wiaas document types
|
||||
*/
|
||||
public static function register_wiaas_document_types() {
|
||||
$labels = array(
|
||||
'name' => _x( 'Document type', 'taxonomy general name', 'wiaas' ),
|
||||
'singular_name' => _x( 'Document type', 'taxonomy singular name', 'wiaas' ),
|
||||
'menu_name' => _x( 'Document types', 'Admin menu name', 'wiaas' ),
|
||||
'search_items' => __( 'Search Document types', 'wiaas' ),
|
||||
'all_items' => __( 'All Document types', 'wiaas' ),
|
||||
'parent_item' => __( 'Parent Document type', 'wiaas' ),
|
||||
'parent_item_colon' => __( 'Parent Document type:', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit Document type', 'wiaas' ),
|
||||
'update_item' => __( 'Update Document type', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add New Document type', 'wiaas' ),
|
||||
'new_item_name' => __( 'New Document type Name', 'wiaas' ),
|
||||
);
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document.php';
|
||||
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'label' => __( 'Document types', 'wiaas' ),
|
||||
'labels' => $labels,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array( 'slug' => 'wiaas_document_types' ),
|
||||
);
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-upload.php';
|
||||
|
||||
register_taxonomy( 'wiaas_document_types', array( 'attachment' ), $args );
|
||||
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-download.php';
|
||||
|
||||
foreach (self::$available_doc_types as $key => $available_doc_type) {
|
||||
wp_insert_term($available_doc_type['name'], 'wiaas_document_types', array(
|
||||
'slug' => $key
|
||||
));
|
||||
}
|
||||
require_once dirname( __FILE__ ) . '/document/wiaas-document-functions.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,17 @@ class Wiaas_Order {
|
||||
private static $object_order_type = 'shop_order';
|
||||
|
||||
public static function init() {
|
||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||
|
||||
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
||||
require_once dirname( __FILE__ ) . '/order/wiaas-order-functions.php';
|
||||
|
||||
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);
|
||||
|
||||
@@ -25,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) {
|
||||
@@ -36,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
|
||||
@@ -115,6 +361,8 @@ class Wiaas_Order {
|
||||
$data = self::_append_order_process($data, $order, $request);
|
||||
|
||||
$data = self::_append_order_comments($data, $order, $request);
|
||||
|
||||
$data = self::_append_documents($data, $order, $request);
|
||||
}
|
||||
|
||||
$response->set_data($data);
|
||||
@@ -122,10 +370,95 @@ class Wiaas_Order {
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function set_order_vat($order_id, $vat_code) {
|
||||
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
|
||||
}
|
||||
|
||||
public static function get_order_vat($order_id) {
|
||||
return get_post_meta($order_id, '_wiaas_vat_code', true);
|
||||
}
|
||||
|
||||
public static function set_order_company($order_id, $company_name) {
|
||||
add_post_meta($order_id, '_wiaas_company_name', $company_name);
|
||||
}
|
||||
|
||||
public static function get_order_company($order_id) {
|
||||
return get_post_meta($order_id, '_wiaas_company_name', true);
|
||||
}
|
||||
|
||||
public static function set_order_reference($order_id, $reference) {
|
||||
add_post_meta($order_id, '_wiaas_reference', $reference);
|
||||
}
|
||||
|
||||
public static function get_order_reference($order_id) {
|
||||
return get_post_meta($order_id, '_wiaas_reference', true);
|
||||
}
|
||||
|
||||
public static function set_order_tender($order_id, $tender) {
|
||||
add_post_meta($order_id, '_wiaas_tender', $tender);
|
||||
}
|
||||
|
||||
public static function get_order_tender($order_id) {
|
||||
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
|
||||
@@ -133,26 +466,45 @@ class Wiaas_Order {
|
||||
* @param $request
|
||||
*/
|
||||
private static function _append_wiaas_order_details($data, $order, $request) {
|
||||
$data['reference'] = get_post_meta($order->get_id(), '_wiaas_reference', true);
|
||||
$data['reference'] = self::get_order_reference($order->get_id());
|
||||
$data['tender'] = self::get_order_tender($order->get_id());
|
||||
$data['vat'] = self::get_order_vat($order->get_id());
|
||||
$data['company_name'] = self::get_order_company($order->get_id());
|
||||
|
||||
$data['project_name'] = Wiaas_Order_Project::get_project_name_for_order($order->get_id());
|
||||
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
@@ -160,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;
|
||||
}
|
||||
@@ -202,7 +563,6 @@ class Wiaas_Order {
|
||||
|
||||
// add only product lines that represent product bundles
|
||||
if (isset($item['wiaas_standard_package'])) {
|
||||
|
||||
# get payment type info
|
||||
$product_line['payment_type'] = $item['wiaas_payment_type'];
|
||||
$product_line['service_price'] = floatval($item['wiaas_services_extra']);
|
||||
@@ -249,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;
|
||||
}
|
||||
}
|
||||
@@ -311,6 +677,30 @@ class Wiaas_Order {
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** Append downloadable documents from order products if single order is requested
|
||||
* @param $data
|
||||
* @param $order
|
||||
* @param $request
|
||||
*/
|
||||
private static function _append_documents($data, $order, $request) {
|
||||
|
||||
// Go trough available line items and append documents for wiaas standard packages line items
|
||||
foreach ($data['line_items'] as $index => $product_line) {
|
||||
$order_item = $order->get_item($product_line['id']);
|
||||
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class Wiaas_Package {
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-option-groups.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-type.php';
|
||||
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-status.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/package/wiaas-package-functions.php';
|
||||
|
||||
@@ -31,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);
|
||||
|
||||
@@ -44,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
|
||||
@@ -54,15 +62,11 @@ class Wiaas_Package {
|
||||
*/
|
||||
private static function _append_documents_info($data, $package, $request) {
|
||||
|
||||
unset($data['downloads']);
|
||||
|
||||
$data['documents'] = array_map(function($download) {
|
||||
return array(
|
||||
'id' => $download->get_id(),
|
||||
'name' => $download->get_name(),
|
||||
'extension' => $download->get_file_extension(),
|
||||
);
|
||||
}, array_values($package->get_downloads()));
|
||||
$data['documents'] = array_map(function($doc) {
|
||||
unset($doc['url']);
|
||||
unset($doc['version']);
|
||||
return $doc;
|
||||
}, wiaas_get_standard_package_documents($package, true));
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -96,6 +100,8 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_additional_packages($data, $package, $request) {
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = absint($request['shop_id']);
|
||||
|
||||
$data['additional_packages'] = array();
|
||||
$addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||
@@ -104,7 +110,7 @@ class Wiaas_Package {
|
||||
'id' => $addon->get_id(),
|
||||
'name' => $addon->get_name(),
|
||||
'description' => $addon->get_description(),
|
||||
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package),
|
||||
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package, $customer_id, $commercial_lead_id),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -125,7 +131,7 @@ class Wiaas_Package {
|
||||
'name' => $option_package->get_name(),
|
||||
'description' => $option_package->get_description(),
|
||||
'default' => $default_option_id === $option_package->get_id(),
|
||||
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package),
|
||||
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package, $customer_id, $commercial_lead_id),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -142,7 +148,10 @@ class Wiaas_Package {
|
||||
* @return array
|
||||
*/
|
||||
private static function _append_package_prices($data, $package, $request) {
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||
$customer_id = wiaas_get_current_user_organization_id();
|
||||
$commercial_lead_id = absint($request['shop_id']);
|
||||
|
||||
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -9,233 +9,240 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
*/
|
||||
class Wiaas_Pricing {
|
||||
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
/**
|
||||
* Wiaas interest rate
|
||||
*/
|
||||
const INTEREST_RATE = 0.58;
|
||||
|
||||
const COMMERCIAL_LEAD_NAME = 'Coor Service Management';
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-cl-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
|
||||
}
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
|
||||
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
|
||||
}
|
||||
/**
|
||||
* Calculates total cost for product
|
||||
* @param WC_Product_Simple $product
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_product_total_cost($product) {
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
/**
|
||||
* Calculates total cost for product
|
||||
* @param $product
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_product_total_cost($product) {
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
|
||||
return $product_price['is_recurring'] ?
|
||||
$product_price['price'] * $product_price['pay_period'] :
|
||||
$product_price['price'];
|
||||
}
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param WC_Product_Bundle $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
|
||||
/**
|
||||
* Calculates total cost for package
|
||||
* @param $package
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public static function get_package_total_cost($package) {
|
||||
$total_cost_per_category = array();
|
||||
|
||||
$total_cost_per_category = array();
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
|
||||
$bundled_items = $package->get_bundled_items();
|
||||
foreach ($bundled_items as $bundled_item) {
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
|
||||
$product = $bundled_item->product;
|
||||
$product_cat = Wiaas_Product_Category::get_category($product);
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
|
||||
if (!isset($total_cost_per_category[$product_cat])) {
|
||||
$total_cost_per_category[$product_cat] = 0;
|
||||
}
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
|
||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||
if (Wiaas_Product_Category::is_installation($product)) {
|
||||
$total_cost_per_category[$product_cat] = $total_cost_per_category[$product_cat] < $total_item_cost ?
|
||||
$total_item_cost :
|
||||
$total_cost_per_category[$product_cat];
|
||||
} else {
|
||||
$total_cost_per_category[$product_cat] += $total_item_cost;
|
||||
}
|
||||
}
|
||||
|
||||
if (Wiaas_Product_Category::is_installation($product)) {
|
||||
$total_cost_per_category[$product_cat] += $total_cost_per_category[$product_cat] < $total_item_cost ?
|
||||
$total_item_cost :
|
||||
$total_cost_per_category[$product_cat];
|
||||
} else {
|
||||
$total_cost_per_category[$product_cat] += $total_item_cost;
|
||||
}
|
||||
}
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
|
||||
return array_sum(array_values($total_cost_per_category));
|
||||
}
|
||||
/**
|
||||
* Calculates customer prices for wiaas standard package
|
||||
* @param WC_Product_Bundle $package
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id) {
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas standard package
|
||||
* @param $package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_standard_package_customer_prices($package) {
|
||||
return self::_get_package_customer_prices(
|
||||
$package,
|
||||
(100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100, // commercial lead commission
|
||||
self::get_package_total_cost($package), // total cost of package items
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
$cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100;
|
||||
$total_cost = self::get_package_total_cost($package);
|
||||
}
|
||||
|
||||
$customer_package_prices = array();
|
||||
/**
|
||||
* Calculates customer prices for wiaas addon package
|
||||
*
|
||||
* @param WC_Product_Bundle $addon_package
|
||||
* @param WC_Product_Bundle $parent_package
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_addon_package_customer_price($addon_package, $parent_package, $customer_id, $commercial_lead_id) {
|
||||
|
||||
foreach ($package_prices as $type => $package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$package_price,
|
||||
$cl_commision,
|
||||
$total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
|
||||
return $customer_package_prices;
|
||||
return self::_get_package_customer_prices(
|
||||
$addon_package,
|
||||
$parent_cl_commision, // commercial lead commission of parent package
|
||||
$parent_total_cost, // total cost of parent package items
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Calculates customer prices for wiaas option package
|
||||
*
|
||||
* @param WC_Product_Bundle $option_package
|
||||
* @param WC_Product_Bundle $parent_package
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_option_package_customer_price($option_package, $parent_package, $customer_id, $commercial_lead_id) {
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas addon package
|
||||
* @param $addon_package
|
||||
* @param $parent_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_addon_package_customer_price($addon_package, $parent_package) {
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
$addon_package_prices = Wiaas_Package_Pricing::get_package_prices($addon_package);
|
||||
return self::_get_package_customer_prices(
|
||||
$option_package,
|
||||
$parent_cl_commision, // commercial lead commission of parent package
|
||||
$parent_total_cost, // total cost of parent package items
|
||||
$customer_id,
|
||||
$commercial_lead_id);
|
||||
}
|
||||
|
||||
$customer_package_prices = array();
|
||||
|
||||
foreach ($addon_package_prices as $type => $addon_package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$addon_package_price,
|
||||
$parent_cl_commision,
|
||||
$parent_total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas option package
|
||||
* @param $option_package
|
||||
* @param $parent_package
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_option_package_customer_price($option_package, $parent_package) {
|
||||
// PRIVATE SECTION
|
||||
|
||||
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
|
||||
$parent_total_cost = self::get_package_total_cost($parent_package);
|
||||
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
|
||||
$option_package_prices = Wiaas_Package_Pricing::get_package_prices($option_package);
|
||||
|
||||
$customer_package_prices = array();
|
||||
/**
|
||||
* Calculates customer prices for all package payment types
|
||||
*
|
||||
* @param WC_Product_Bundle $package
|
||||
* @param int $cl_commision
|
||||
* @param int $total_cost
|
||||
* @param int $customer_id
|
||||
* @param int $commercial_lead_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_prices($package, $cl_commision, $total_cost, $customer_id, $commercial_lead_id) {
|
||||
$is_same_company_as_cl = $customer_id === $commercial_lead_id;
|
||||
|
||||
foreach ($option_package_prices as $type => $option_package_price) {
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$option_package_price,
|
||||
$parent_cl_commision,
|
||||
$parent_total_cost,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||
|
||||
return $customer_package_prices;
|
||||
}
|
||||
$customer_package_prices = array();
|
||||
|
||||
// PRIVATE
|
||||
foreach ($package_prices as $type => $package_price) {
|
||||
$cl_package_extras = Wiaas_Package_CL_Pricing::get_extras_for_customer(
|
||||
$commercial_lead_id,
|
||||
$package_price['id'],
|
||||
$package->get_id(),
|
||||
$customer_id
|
||||
);
|
||||
|
||||
/**
|
||||
* Determines if customer and commercial lead are in the same company
|
||||
* For now this is hardcoded and we have only one CL
|
||||
*
|
||||
* TODO: This should be changed after customer leads are handled
|
||||
* @return bool
|
||||
*/
|
||||
private static function _is_customer_same_company_as_cl() {
|
||||
$current_user = wp_get_current_user();
|
||||
$user_organization = Wiaas_User_Organization::get_user_organization($current_user->ID);
|
||||
$is_same_company_as_cl = $user_organization->name === self::COMMERCIAL_LEAD_NAME;
|
||||
// commercial lead did not set prices for this payment type so it must not be visible for customer
|
||||
if (empty($cl_package_extras)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $is_same_company_as_cl;
|
||||
}
|
||||
$customer_package_prices[] = self::_get_package_customer_price(
|
||||
$package_price,
|
||||
$total_cost,
|
||||
$cl_package_extras,
|
||||
$cl_commision,
|
||||
$is_same_company_as_cl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates customer price for wiaas package
|
||||
* @param $package_price
|
||||
* @param $cl_commision
|
||||
* @param $total_cost
|
||||
* @param $is_same_company_as_cl
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_price($package_price, $cl_commision, $total_cost, $is_same_company_as_cl) {
|
||||
return $customer_package_prices;
|
||||
}
|
||||
|
||||
$package_total_margin = wiaas_get_price_margin(
|
||||
$package_price['minimal_fixed_price'],
|
||||
$package_price['principal_amount'],
|
||||
$total_cost);
|
||||
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
|
||||
/**
|
||||
* Calculates customer price for single package payment type
|
||||
*
|
||||
* @param array $package_price
|
||||
* @param int $total_cost
|
||||
* @param array $cl_package_extras
|
||||
* @param int $cl_commision
|
||||
* @param bool $is_same_company_as_cl
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_package_customer_price($package_price, $total_cost, $cl_package_extras, $cl_commision, $is_same_company_as_cl) {
|
||||
$package_total_margin = wiaas_get_price_margin(
|
||||
$package_price['minimal_fixed_price'],
|
||||
$package_price['principal_amount'],
|
||||
$total_cost);
|
||||
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
|
||||
|
||||
$cl_package_prices = array(
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
$customer_package_price = array(
|
||||
'id' => $package_price['id'],
|
||||
'payment_type' => $package_price['payment_type'],
|
||||
'max_contract_period' => $package_price['max_contract_period'],
|
||||
'package_pay_period' => $package_price['package_pay_period'],
|
||||
'period_unit' => $package_price['period_unit'],
|
||||
'services_contract_period' => $package_price['services_contract_period'],
|
||||
|
||||
$interest_rate = self::INTEREST_RATE;
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
|
||||
$customer_price = array(
|
||||
'id' => $package_price['id'],
|
||||
'payment_type' => $package_price['payment_type'],
|
||||
'max_contract_period' => $package_price['max_contract_period'],
|
||||
'package_pay_period' => $package_price['package_pay_period'],
|
||||
'period_unit' => $package_price['period_unit'],
|
||||
'services_contract_period' => $package_price['services_contract_period'],
|
||||
if ($is_same_company_as_cl) {
|
||||
|
||||
'fixed_extra' => 0,
|
||||
'recurrent_extra' => 0,
|
||||
'services_extra' => 0
|
||||
);
|
||||
if ($package_price['package_pay_period'] > 0) {
|
||||
$customer_package_price['fixed_extra'] = $package_price['minimal_fixed_price'];
|
||||
$customer_package_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
$cl_margin,
|
||||
self::INTEREST_RATE);
|
||||
} else {
|
||||
$customer_package_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
|
||||
$customer_package_price['recurrent_extra'] = 0;
|
||||
}
|
||||
$customer_package_price['services_extra'] = $package_price['minimal_services_price'];
|
||||
|
||||
if ($is_same_company_as_cl) {
|
||||
} else {
|
||||
|
||||
if ($package_price['package_pay_period'] > 0) {
|
||||
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'];
|
||||
$customer_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
$cl_margin,
|
||||
$interest_rate);
|
||||
} else {
|
||||
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
|
||||
$customer_price['recurrent_extra'] = 0;
|
||||
}
|
||||
$customer_price['services_extra'] = $package_price['minimal_services_price'];
|
||||
$customer_package_price['fixed_extra'] = $cl_package_extras['fixed'] + $package_price['minimal_fixed_price'];
|
||||
$customer_package_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
|
||||
$cl_package_extras['recurrent'] + wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
0,
|
||||
self::INTEREST_RATE)
|
||||
: 0;
|
||||
$customer_package_price['services_extra'] = $cl_package_extras['services'] + $package_price['minimal_services_price'];
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$customer_price['fixed_extra'] = $cl_package_prices['fixed_extra'] + $package_price['minimal_fixed_price'];
|
||||
$customer_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
|
||||
$cl_package_prices['recurrent_extra'] + wiaas_get_recurrent_price_mortage(
|
||||
$package_price['principal_amount'],
|
||||
$package_price['package_pay_period'],
|
||||
0,
|
||||
$interest_rate)
|
||||
: 0;
|
||||
$customer_price['services_extra'] = $cl_package_prices['services_extra'] + $package_price['minimal_services_price'];
|
||||
}
|
||||
|
||||
return $customer_price;
|
||||
}
|
||||
return $customer_package_price;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Pricing::init();
|
||||
@@ -4,6 +4,75 @@ class Wiaas_Product {
|
||||
|
||||
public static function init() {
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
||||
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
|
||||
|
||||
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'manage_product_settings'));
|
||||
|
||||
add_filter('woocommerce_taxonomy_args_product_tag', array(__CLASS__, 'manage_tags_as_references'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update product type settins before it is created:
|
||||
* - Define capabilities for editing products so we can easily control read/edit/create access for them
|
||||
* - Declare fields supported by product
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_product_settings($args) {
|
||||
|
||||
$args['capabilities'] = array(
|
||||
'edit_post' => 'edit_product',
|
||||
'read_post' => 'read_product',
|
||||
'delete_post' => 'delete_product',
|
||||
'edit_posts' => 'edit_products',
|
||||
'edit_others_posts' => 'edit_others_products',
|
||||
'publish_posts' => 'publish_products',
|
||||
'read_private_posts' => 'read_private_products',
|
||||
'create_posts' => 'create_products', // use `create_products` instead of default `edit_products`
|
||||
);
|
||||
|
||||
$args['supports'] = array( 'title', 'thumbnail' );
|
||||
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide default metabox for product tags
|
||||
*
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function manage_tags_as_references($args) {
|
||||
// hide metabox
|
||||
$args['meta_box_cb'] = false;
|
||||
|
||||
// update labels
|
||||
$args['labels'] = array(
|
||||
'name' => __( 'Product references', 'wiaas' ),
|
||||
'singular_name' => __( 'Reference', 'wiaas' ),
|
||||
'menu_name' => _x( 'References', 'Admin menu name', 'wiaas' ),
|
||||
'search_items' => __( 'Search references', 'wiaas' ),
|
||||
'all_items' => __( 'All references', 'wiaas' ),
|
||||
'edit_item' => __( 'Edit reference', 'wiaas' ),
|
||||
'update_item' => __( 'Update reference', 'wiaas' ),
|
||||
'add_new_item' => __( 'Add new reference', 'wiaas' ),
|
||||
'new_item_name' => __( 'New reference name', 'wiaas' ),
|
||||
'popular_items' => __( 'Popular references', 'wiaas' ),
|
||||
'separate_items_with_commas' => __( 'Separate references with commas', 'wiaas' ),
|
||||
'add_or_remove_items' => __( 'Add or remove references', 'wiaas' ),
|
||||
'choose_from_most_used' => __( 'Choose from the most used references', 'wiaas' ),
|
||||
'not_found' => __( 'No references found', 'wiaas' ),
|
||||
);
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
public static function get_supplier_id($product_id){
|
||||
return wp_get_post_terms($product_id, 'supplier', array('fields' => 'ids'))[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
215
backend/app/plugins/wiaas/includes/class-wiaas-shop.php
Normal file
215
backend/app/plugins/wiaas/includes/class-wiaas-shop.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements logic for multiple shops existing in one marketplace
|
||||
*
|
||||
* Every shop has its owner (organization that is commercial lead) and multiple customers (organizations)
|
||||
* assigned to it.
|
||||
*
|
||||
* Class Wiaas_Shop
|
||||
*/
|
||||
class Wiaas_Shop {
|
||||
|
||||
public static function init() {
|
||||
|
||||
// registers special prices taxonomy that will enable package search based on
|
||||
// set and visible price types (default and customer specific ones)
|
||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_prices_taxonomy'));
|
||||
|
||||
// update prices search terms for package after prices extras have been updated
|
||||
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register special prices taxonomy to enable search of packages by prices inside every shop
|
||||
*/
|
||||
public static function register_prices_taxonomy() {
|
||||
$args = array(
|
||||
'hierarchical' => false,
|
||||
'query_var' => true,
|
||||
'rewrite' => false,
|
||||
'public' => false,
|
||||
'capabilities' => array(
|
||||
'manage_terms' => 'manage_wiaas_package_price_terms',
|
||||
'edit_terms' => 'edit_wiaas_package_price_terms',
|
||||
'delete_terms' => 'delete_wiaas_package_price_terms',
|
||||
'assign_terms' => 'assign_wiaas_package_price_terms',
|
||||
),
|
||||
);
|
||||
|
||||
register_taxonomy( '_wiaas_shop_prices', array( 'product' ), $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Relate pricing search terms to package so customer can retrieve packages with default or
|
||||
* their own specific prices.
|
||||
* (ex: Package which will be hidden fro Customer 1 because default price
|
||||
* is hidden can be visible for Customer 2 because specific prices are set for that customer)
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param int $package_id
|
||||
* @param array $cl_extras {
|
||||
* $extra_price_payment_type => {
|
||||
* @type bool visible Indicates if payment type is visible to customer
|
||||
* }
|
||||
* }
|
||||
* @param array $old_cl_extras {
|
||||
* $extra_price_payment_type => {
|
||||
* @type bool visible Indicates if payment type is visible to customer
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public static function update_package_prices_search_terms($owner_id, $package_id, $cl_extras, $old_cl_extras) {
|
||||
// remove pricing terms for previous prices
|
||||
if (! empty($old_cl_extras)) {
|
||||
|
||||
$old_terms = self::_get_search_terms_from_cl_extras($owner_id, $old_cl_extras);
|
||||
|
||||
wp_remove_object_terms($package_id, $old_terms, '_wiaas_shop_prices');
|
||||
}
|
||||
|
||||
$new_terms = self::_get_search_terms_from_cl_extras($owner_id, $cl_extras);
|
||||
|
||||
// create term for every visible pricing type and link them to package so package can be queried
|
||||
wp_add_object_terms($package_id, $new_terms, '_wiaas_shop_prices');
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
||||
/**
|
||||
* Generate search terms from cl extras
|
||||
*
|
||||
* For default prices search term
|
||||
* `_{owner_id}_default` will be generated if all set prices are visible
|
||||
*
|
||||
* For every customer entry search term
|
||||
* `_{owner_id}_customer_{customer_id}_visible` will be generated if any of the prices is visible or
|
||||
* `_{owner_id}_customer_{customer_id}_hidden` if all prices are hidden`
|
||||
*
|
||||
* @param int $owner_id
|
||||
* @param array $cl_extras
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _get_search_terms_from_cl_extras($owner_id, $cl_extras) {
|
||||
// determine if extras are visible grouped by customer and default settings
|
||||
$cl_extras_per_customer = array();
|
||||
$cl_extra_default = false;
|
||||
|
||||
foreach ($cl_extras as $cl_extra_type => $cl_extra) {
|
||||
// is default
|
||||
if (strpos($cl_extra_type, '_default') !== false) {
|
||||
// determine if default cl extra is visible
|
||||
$cl_extra_default = $cl_extra_default || $cl_extra['visible'];
|
||||
}
|
||||
// is customer specific
|
||||
if (strpos($cl_extra_type, '_customer_') !== false) {
|
||||
$customer_id = absint(explode('_customer_', $cl_extra_type)[1]);
|
||||
// determine if customer cl extra is visible
|
||||
$cl_extras_per_customer[$customer_id] = $cl_extras_per_customer[$customer_id] || $cl_extra['visible'];
|
||||
}
|
||||
}
|
||||
|
||||
$terms = array();
|
||||
|
||||
if ($cl_extra_default) {
|
||||
$terms[] = '_' . $owner_id . '_default';
|
||||
}
|
||||
|
||||
foreach ($cl_extras_per_customer as $customer_id => $visible) {
|
||||
|
||||
$terms[] = '_' . $owner_id . '_customer_' . $customer_id . '_' .
|
||||
($visible ? 'visible' : 'hidden');
|
||||
}
|
||||
|
||||
return $terms;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Shop::init();
|
||||
@@ -8,13 +8,20 @@ defined( 'ABSPATH' ) || exit;
|
||||
class Wiaas_User {
|
||||
|
||||
public static function init() {
|
||||
include_once dirname( __FILE__ ) . '/class-wiaas-countries.php';
|
||||
include_once dirname( __FILE__ ) . '/user/class-wiaas-customer.php';
|
||||
|
||||
add_action('init', array(__CLASS__, 'load_user_organization'));
|
||||
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'), 999, 2);
|
||||
}
|
||||
|
||||
public static function load_user_organization() {
|
||||
if (class_exists('WP_User_Taxonomy')) {
|
||||
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
|
||||
require_once dirname( __FILE__ ) . '/user/wiaas-organization-functions.php';
|
||||
|
||||
new Wiaas_User_Organization();
|
||||
}
|
||||
@@ -24,6 +31,51 @@ class Wiaas_User {
|
||||
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
|
||||
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply wiaas custom transformation on retrieved JSON customer object
|
||||
*
|
||||
* @param $response
|
||||
* @param $order
|
||||
* @param $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function transform_rest_customer($response, $order, $request) {
|
||||
$data = $response->get_data();
|
||||
$user_id = $data['id'];
|
||||
$customer_info = Wiaas_Customer::get_customer_info($user_id);
|
||||
|
||||
return new WP_REST_Response($customer_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply wiaas custom transformation on JWT token response
|
||||
*
|
||||
* @param $data
|
||||
* @param $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(
|
||||
'wiaas_id_user' => $user->ID,
|
||||
'wiaas_is_company_admin' => 1, //TODO: don't hardcode this
|
||||
'wiaas_user_full_name' => $user->first_name . ' ' . $user->last_name,
|
||||
'wiaas_user_type' => $user->roles,
|
||||
'wiaas_username' => $user->data->user_login
|
||||
)
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Wiaas_User::init();
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,9 @@ class Wiaas_CLI_Update_DB_Command {
|
||||
$wpdb->hide_errors();
|
||||
|
||||
include_once WIAAS_DIR . '/includes/class-wiaas-db-update.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-functions.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-general.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-roles.php';
|
||||
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-ui-fields.php';
|
||||
|
||||
$pending_db_updates = Wiaas_DB_Update::get_pending_db_updates();
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
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": ""
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,120 @@
|
||||
[
|
||||
{
|
||||
"key": "group_5bbe558ba265c",
|
||||
"title": "Organization Info",
|
||||
"fields": [
|
||||
{
|
||||
"key": "field_5bbe5c0d1f1a7",
|
||||
"label": "Phone",
|
||||
"name": "_wiaas_organization_phone",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbe5c291f1a8",
|
||||
"label": "VAT Code",
|
||||
"name": "_wiaas_organization_vat",
|
||||
"type": "text",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"default_value": "",
|
||||
"placeholder": "",
|
||||
"prepend": "",
|
||||
"append": "",
|
||||
"maxlength": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bbe559d66d17",
|
||||
"label": "Roles",
|
||||
"name": "_wiaas_organization_roles",
|
||||
"type": "select",
|
||||
"instructions": "",
|
||||
"required": 1,
|
||||
"conditional_logic": 0,
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"choices": {
|
||||
"administrator": "Administrator",
|
||||
"supplier": "Supplier",
|
||||
"commercial_lead": "Commercial Lead",
|
||||
"customer": "Customer"
|
||||
},
|
||||
"default_value": [],
|
||||
"allow_null": 0,
|
||||
"multiple": 1,
|
||||
"ui": 1,
|
||||
"ajax": 1,
|
||||
"return_format": "value",
|
||||
"placeholder": ""
|
||||
},
|
||||
{
|
||||
"key": "field_5bc49631c35a4",
|
||||
"label": "Linked Customers",
|
||||
"name": "_wiaas_organization_customers",
|
||||
"type": "taxonomy",
|
||||
"instructions": "",
|
||||
"required": 0,
|
||||
"conditional_logic": [
|
||||
[
|
||||
{
|
||||
"field": "field_5bbe559d66d17",
|
||||
"operator": "==contains",
|
||||
"value": "commercial_lead"
|
||||
}
|
||||
]
|
||||
],
|
||||
"wrapper": {
|
||||
"width": "",
|
||||
"class": "",
|
||||
"id": ""
|
||||
},
|
||||
"taxonomy": "wiaas-user-organization",
|
||||
"field_type": "multi_select",
|
||||
"allow_null": 0,
|
||||
"add_term": 0,
|
||||
"save_terms": 0,
|
||||
"load_terms": 1,
|
||||
"return_format": "id",
|
||||
"multiple": 0
|
||||
}
|
||||
],
|
||||
"location": [
|
||||
[
|
||||
{
|
||||
"param": "taxonomy",
|
||||
"operator": "==",
|
||||
"value": "wiaas-user-organization"
|
||||
}
|
||||
]
|
||||
],
|
||||
"menu_order": 0,
|
||||
"position": "normal",
|
||||
"style": "seamless",
|
||||
"label_placement": "top",
|
||||
"instruction_placement": "field",
|
||||
"hide_on_screen": "",
|
||||
"active": 1,
|
||||
"description": ""
|
||||
}
|
||||
]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user