154 Commits

Author SHA1 Message Date
Almira Krdzic
2b688e8a5e Remove unused code 2018-11-27 11:22:01 +01:00
Almira Krdzic
95d162578f Add timestamp script to composer 2018-11-27 01:47:01 +01:00
Almira Krdzic
798ad20534 Show countries for delivery process forms. Refactor countries. 2018-11-27 00:57:35 +01:00
Almira
61ff7dbc60 Merge branch 'add-phone-number-field-in-backoffice-profile' into 'development'
Add phone number field in backoffice profile

See merge request saburly/wiaas/new-wiaas!75
2018-11-22 12:24:42 +00:00
Bilal Catic
09fc3f8018 Rename class 2018-11-22 13:22:05 +01:00
Bilal Catic
217dfb1889 add validation functions class 2018-11-22 12:08:41 +01:00
Bilal Catic
8d954469ee use woocommerce validation 2018-11-22 11:27:30 +01:00
Bilal Catic
68c760a426 validate phone number from frontend 2018-11-21 12:26:23 +01:00
Bilal Catic
35854d1367 add phone number field 2018-11-21 12:26:23 +01:00
Almira
3db4b71c3f Merge branch 'fix-location-details-field' into 'development'
Fix location details field

See merge request saburly/wiaas/new-wiaas!74
2018-11-19 15:32:55 +00:00
Bilal Catic
3df6397280 remove comment 2018-11-19 16:30:04 +01:00
Bilal Catic
e548e2a31c break project name and location details if too long 2018-11-19 16:29:22 +01:00
Almira
3d37a88247 Merge branch 'ticketing-integration' into 'development'
add helpdesk module

See merge request saburly/wiaas/new-wiaas!66
2018-11-19 12:44:16 +00:00
Bilal Catic
30e5d594ad highlight helpdesk when selected 2018-11-19 13:38:12 +01:00
Bilal Catic
dd93677def add helpdesk module 2018-11-19 13:38:12 +01:00
Nedim Uka
4de01d93d1 Merge branch 'fix-bundle-link-in-order-details' into 'development'
set commercial id to real id, not object

See merge request saburly/wiaas/new-wiaas!72
2018-11-19 12:37:09 +00:00
Bilal Catic
2fdae06a59 set commercial id to real id, not object 2018-11-19 13:30:07 +01:00
Almira
d0533b3d6e Merge branch 'support-email' into 'development'
Added support for sending customer emails

See merge request saburly/wiaas/new-wiaas!69
2018-11-19 12:24:10 +00:00
Nedim Uka
35e670fa52 removved debug log 2018-11-19 13:15:50 +01:00
Nedim Uka
f56377f606 Handled proper endpoint naming 2018-11-19 12:35:04 +01:00
Almira
95a9fd2110 Merge branch 'fix-additional-days-bug' into 'development'
add only working days

See merge request saburly/wiaas/new-wiaas!70
2018-11-19 11:11:34 +00:00
Nedim Uka
752df56d4a Fixed bug where order note text is saved as order ID 2018-11-19 11:31:46 +01:00
Bilal Catic
e1594f3a7f Merge branch 'fixes' into 'development'
Fixes

See merge request saburly/wiaas/new-wiaas!71
2018-11-19 10:15:26 +00:00
Almira Krdzic
4f97df5b45 Merge branch 'development' into fixes 2018-11-18 22:10:24 +01:00
Almira Krdzic
ef5cf00983 Fix hidden metadata 2018-11-18 22:10:01 +01:00
Bilal Catic
ca0fed674f add only working days 2018-11-16 20:30:47 +01:00
Bilal Catic
fb66d56d9c Merge branch 'installation-fix' into 'development'
Fix installation selection

See merge request saburly/wiaas/new-wiaas!68
2018-11-16 19:20:35 +00:00
Nedim Uka
a07c0e4584 Added support for sending customer emails 2018-11-16 17:16:28 +01:00
Almira Krdzic
3708c9fb30 Fix installation selection 2018-11-16 15:59:16 +01:00
Bilal Catic
c630452d0b Merge branch 'fix-tests' into 'development'
Fix and remove broken tests

See merge request saburly/wiaas/new-wiaas!67
2018-11-16 09:38:51 +00:00
Almira Krdzic
a62de78172 fix and remove broken tests 2018-11-15 23:40:58 +01:00
Almira
14550d2ea9 Merge branch 'allign-order-table' into 'development'
break long words

See merge request saburly/wiaas/new-wiaas!65
2018-11-15 15:23:51 +00:00
Bilal Catic
56c171df3e break long words 2018-11-15 14:50:02 +01:00
Bilal Catic
337f031705 Merge branch 'documents-fix' into 'development'
Handle documents upload

See merge request saburly/wiaas/new-wiaas!64
2018-11-15 13:44:55 +00:00
Almira Krdzic
b7be6fde42 Merge branch 'development' into documents-fix 2018-11-15 14:33:15 +01:00
Almira Krdzic
6c656a0b26 Handle order documents 2018-11-15 11:29:15 +01:00
Bilal Catic
c4d539f549 Merge branch 'documents-fix' into 'development'
Documents fix

See merge request saburly/wiaas/new-wiaas!63
2018-11-07 10:17:46 +00:00
Almira Krdzic
0ba27b2f1d documents fix 2018-11-07 03:05:54 +01:00
Bilal Catic
e6b372f5d0 Merge branch 'cart-validation' into 'development'
Validate that items are from the same country and catalogue

See merge request saburly/wiaas/new-wiaas!61
2018-11-06 20:13:13 +00:00
Almira Krdzic
16b51c87bb Merge branch 'development' into cart-validation 2018-11-06 21:11:38 +01:00
Almira
47b2214a99 Merge branch 'terms-and-conditions-link' into 'development'
update terms and conditions file and link

See merge request saburly/wiaas/new-wiaas!62
2018-11-06 15:17:21 +00:00
Almira Krdzic
c7bf4e8c03 Merge branch 'development' into cart-validation 2018-11-06 15:41:18 +01:00
Bilal Catic
15db815d01 update terms and conditions file and link 2018-11-06 15:38:09 +01:00
Almira Krdzic
c555571607 Text change 2018-11-06 15:33:33 +01:00
Almira Krdzic
a1997a813d Validate that items are from the same country and catalogue 2018-11-06 14:03:58 +01:00
Bilal Catic
a77a97b922 Merge branch 'hide-order-item-metadata' into 'master'
Hide metadata for order item

See merge request saburly/wiaas/new-wiaas!60
2018-11-06 12:47:43 +00:00
Almira Krdzic
99c203b920 Hide metadata for order item 2018-11-06 10:38:08 +01:00
Bilal Catic
053675b478 Merge branch 'add-customer-order-url-merge-tag' into 'master'
Add merge tag for customer order url

See merge request saburly/wiaas/new-wiaas!59
2018-11-06 06:42:26 +00:00
Almira Krdzic
f34ce98655 Merge branch 'master' into add-customer-order-url-merge-tag 2018-11-06 07:18:53 +01:00
Almira Krdzic
6ef9936403 add merge tag for customer order url 2018-11-06 02:04:34 +01:00
Bilal Catic
e0060dd69d Merge branch 'fix-order-organizations-data' into 'master'
Fix order organization info

See merge request saburly/wiaas/new-wiaas!58
2018-11-05 19:57:44 +00:00
Almira Krdzic
d6528e75cf Merge branch 'master' into fix-order-organizations-data 2018-11-05 20:54:08 +01:00
Almira Krdzic
c9b04dac1e Fix order organization info 2018-11-05 20:33:11 +01:00
Bilal Catic
09b5779056 Merge branch 'add-installation-date-action' into 'master'
Add installation date action

See merge request saburly/wiaas/new-wiaas!57
2018-11-05 19:17:18 +00:00
Almira Krdzic
fcbddcb22a fix form import 2018-11-05 19:00:07 +01:00
Almira Krdzic
dd53584d20 Enable admin to enter installation date on delivery process:
:
2018-11-05 18:18:44 +01:00
Bilal Catic
c23e570399 Merge branch 'cart-number' into 'master'
Display * instead of cart count

See merge request saburly/wiaas/new-wiaas!56
2018-11-05 13:05:54 +00:00
Nedim Uka
f5e9aa7495 Renamed Co-Market to Wiaas Market on frontend 2018-11-05 13:55:10 +01:00
Nedim Uka
aef8347df3 Display * instead of cart count 2018-11-05 13:37:47 +01:00
Bilal Catic
75141b6bd1 Merge branch 'bundle-units' into 'master'
Added wiaas_units selection to bundle products

See merge request saburly/wiaas/new-wiaas!52
2018-11-05 11:41:53 +00:00
Nedim Uka
e2952a240c Added wiaas_units selection to bundle products 2018-11-05 12:27:39 +01:00
Bilal Catic
afa370f403 Merge branch 'persist-workflow-documents' into 'master'
Persist workflow fields for order

See merge request saburly/wiaas/new-wiaas!55
2018-11-05 10:24:58 +00:00
Almira Krdzic
b02f0881d3 Fix customer acceptance flow 2018-11-05 10:53:54 +01:00
Almira Krdzic
0d62e7da4b Merge branch 'master' into persist-workflow-documents 2018-11-05 08:52:41 +01:00
Almira Krdzic
3dcef84709 Persist workflow entry fields to order 2018-11-05 08:48:25 +01:00
Almira
0600bbee9f Merge branch 'set-default-status-to-open' into 'master'
Set default status to open

See merge request saburly/wiaas/new-wiaas!54
2018-11-04 23:03:09 +00:00
Bilal Catic
75a574279b change order status to processing when process is assigned 2018-11-04 23:59:54 +01:00
Bilal Catic
9e599617c4 remove wiaas from method name 2018-11-04 23:40:52 +01:00
Bilal Catic
bc310ed738 change order status to open 2018-11-04 23:26:30 +01:00
Bilal Catic
5d872a33da register and display custom order statuses 2018-11-04 23:26:30 +01:00
Bilal Catic
cedd4bf9e9 Merge branch 'order-delivery-flow' into 'master'
Order delivery flow integration with order fields and order organization participants

See merge request saburly/wiaas/new-wiaas!53
2018-11-04 22:16:39 +00:00
Almira Krdzic
4e8b04fa8d Handle order files download separately from delivery process files 2018-11-04 22:13:52 +01:00
Almira Krdzic
1d097eda6f Get supplier organization from order item 2018-11-04 19:54:43 +01:00
Almira Krdzic
b7e4f7f49b Update db migration and remove unused files 2018-11-04 17:57:48 +01:00
Almira Krdzic
5e55d296e5 fix retrieval of process step action entries 2018-11-04 17:06:42 +01:00
Almira Krdzic
27795387df add dependencies 2018-11-04 14:50:54 +01:00
Almira Krdzic
3011c49474 remove error logs 2018-11-04 14:14:55 +01:00
Almira Krdzic
0b54ce54f8 remove procurement order 2018-11-04 13:25:19 +01:00
Almira Krdzic
a6640548ef Update delivery process fields and sample form 2018-11-04 13:20:13 +01:00
Almira Krdzic
e8a3668c25 Merge branch 'master' into order-delivery-flow 2018-11-04 11:17:42 +01:00
Almira
388f7df8a8 Merge branch 'schedule-installation-new' into 'master'
Schedule installation

See merge request saburly/wiaas/new-wiaas!49
2018-11-03 10:24:43 +00:00
Almira Krdzic
8d4f75cc41 Handle process navigation better 2018-11-03 11:15:52 +01:00
Bilal Catic
24e8515b30 show link to delivery process page 2018-11-03 07:35:39 +01:00
Bilal Catic
01b35dbac5 rename 2018-11-03 07:35:39 +01:00
Bilal Catic
93e17817dc move date selection to workflow 2018-11-03 07:35:39 +01:00
Bilal Catic
2a3f2f8245 fix formatting 2018-11-03 07:35:39 +01:00
Bilal Catic
a059f4b83d save items related to supplier in supplier list 2018-11-03 07:35:39 +01:00
Bilal Catic
c08c393b2d use taxonomy for supplier id 2018-11-03 07:35:39 +01:00
Bilal Catic
f8e3cc5875 move formatting to view 2018-11-03 07:35:39 +01:00
Bilal Catic
3af91a71d7 use acf field for additional days prior installation 2018-11-03 07:35:39 +01:00
Bilal Catic
8eeb3b9927 use order update meta 2018-11-03 07:35:39 +01:00
Bilal Catic
3e4324546b rename files and classes 2018-11-03 07:35:39 +01:00
Bilal Catic
b3ba1889b6 use existing function to get supplier name 2018-11-03 07:35:39 +01:00
Bilal Catic
9e4ee644a0 change style 2018-11-03 07:35:39 +01:00
Bilal Catic
d6c5a36e94 handle delivery schedule dates 2018-11-03 07:35:39 +01:00
Bilal Catic
e6b6f6c136 add additional fields to order 2018-11-03 07:35:39 +01:00
Bilal Catic
9956a94c7c remove debugging output 2018-11-03 07:35:39 +01:00
Bilal Catic
f8dd5f1d9f add additional days prior installation field to bundle 2018-11-03 07:35:39 +01:00
Bilal Catic
1f03563d2e replace buttons with dropdown 2018-11-03 07:35:39 +01:00
Bilal Catic
9aa3b3d044 temporarily remove additional delivery process 2018-11-03 07:35:39 +01:00
Bilal Catic
dbddcd47d3 add delivery process 2018-11-03 07:35:39 +01:00
Bilal Catic
b91341c5df add missing file 2018-11-03 07:35:39 +01:00
Bilal Catic
69c74d9340 order delivery process 2018-11-03 07:35:39 +01:00
Bilal Catic
1ae60eb6eb Merge branch 'disable-email' into 'master'
Disabled processing order email for customer

See merge request saburly/wiaas/new-wiaas!51
2018-11-02 12:33:09 +00:00
Nedim Uka
00076b89fd Disabled processing order email for customer 2018-11-02 11:26:41 +01:00
Almira Krdzic
26f997abbc Import new forms 2018-11-02 11:20:40 +01:00
Almira Krdzic
cdbefc7ef0 Handle assigment for order delivery flow 2018-11-02 10:30:25 +01:00
Nedim Uka
8ffa5ddd3a Merge branch 'quantity-limit-fix' into 'master'
increase quantity limit in cart

See merge request saburly/wiaas/new-wiaas!50
2018-11-01 10:18:59 +00:00
Almira Krdzic
4b0fc6c61d Merge branch 'master' into order-delivery-flow 2018-11-01 11:00:21 +01:00
Almira Krdzic
3d16d5027b Handle process visualization and going from one step to another 2018-11-01 10:43:15 +01:00
Almira
165eb808b8 Merge branch 'suppliers-order' into 'master'
Give order access to suppliers , when order is created

See merge request saburly/wiaas/new-wiaas!48
2018-11-01 09:36:55 +00:00
Nedim Uka
281f71d853 Removed error logs 2018-11-01 10:18:37 +01:00
Bilal Catic
1a33593cbe add more validation 2018-11-01 00:28:33 +01:00
Bilal Catic
46e2259359 increase quantity limit in cart 2018-10-31 21:31:44 +01:00
Nedim Uka
26353f0d80 Show supplier orders, and preview 2018-10-31 15:04:23 +01:00
Almira
683cc68bb7 Merge branch 'fix-total-cost' into 'master'
Fix total cost bug

See merge request saburly/wiaas/new-wiaas!47
2018-10-31 10:24:37 +00:00
Almira Krdzic
308c836460 handle order actions 2018-10-31 10:23:59 +01:00
Almira Krdzic
5aca4e8572 delivery step actions 2018-10-30 17:20:56 +01:00
Nedim Uka
51cb2af438 Give order access to suppliers , when order is created 2018-10-30 15:04:42 +01:00
Bilal Catic
d2ce84b3fb refactor 2018-10-29 16:02:01 +01:00
Bilal Catic
bc39a69b7a fix bug with software cost 2018-10-29 16:02:01 +01:00
Nedim Uka
f5766cda99 Fixed taxonomy search in simple product 2018-10-29 15:18:49 +01:00
Almira
45090fa05f Merge branch 'organisation-bug' into 'master'
Add supplier for organisation only if it has supplier role

See merge request saburly/wiaas/new-wiaas!44
2018-10-26 07:50:32 +00:00
Almira
42c9f07195 Merge branch 'template-category-in-simple-product-search' into 'master'
Connected template category to product in bundle product search

See merge request saburly/wiaas/new-wiaas!43
2018-10-26 07:41:57 +00:00
Nedim Uka
06e7461245 Use roles from hook methods 2018-10-25 14:15:05 +02:00
Nedim Uka
0926030133 Use wiaas edit and create methods for organisations when adding supplier 2018-10-25 13:25:19 +02:00
Nedim Uka
a94afea151 Better format of template category in template search box 2018-10-25 13:05:43 +02:00
Nedim Uka
ef020f57e5 Include empty template category in search 2018-10-25 11:15:32 +02:00
Bilal Catic
892571b179 Merge branch 'optimize-docker' into 'master'
Optimize docker and solve memory issues

See merge request saburly/wiaas/new-wiaas!46
2018-10-24 13:37:32 +00:00
Almira Krdzic
1b5b8e2595 Merge branch 'master' into optimize-docker 2018-10-24 14:17:47 +02:00
Almira
0b4243e368 Merge branch 'fix-env' into 'master'
fix env and docker build

See merge request saburly/wiaas/new-wiaas!45
2018-10-24 12:15:59 +00:00
Bilal Catic
d1a6d1a4d8 Update .dockerignore 2018-10-24 12:14:23 +00:00
Almira Krdzic
59e60bef4d handle order projects 2018-10-24 13:47:16 +02:00
Almira Krdzic
e524e6d0d5 handle only order project with radio buttons 2018-10-24 12:43:02 +02:00
Almira Krdzic
29ccb136d0 Remove unused db updates 2018-10-24 12:40:50 +02:00
Almira Krdzic
e41b643fc5 Handle order number and product ui fields 2018-10-24 12:13:07 +02:00
Bilal Catic
aec480d110 fix env and docker build 2018-10-24 12:09:35 +02:00
Nedim Uka
b0e6cbd9b2 Add supplyer for organisation only if it has supplier role 2018-10-24 11:15:04 +02:00
Almira Krdzic
e1589ee561 optimize docker 2018-10-24 02:15:48 +02:00
Nedim Uka
66452eee86 Connected template category to product in bundle product search 2018-10-23 15:48:56 +02:00
Nedim Uka
18f40d9403 Merge branch 'template-creation-fix' into 'master'
Template creation fix

See merge request saburly/wiaas/new-wiaas!42
2018-10-23 10:37:49 +00:00
Almira Krdzic
69773c77a7 validate country 2018-10-23 12:17:25 +02:00
Almira Krdzic
e3869e720b Fix template creation 2018-10-23 11:28:11 +02:00
Bilal Catic
00999122a2 Merge branch 'role-access' into 'master'
Enable login by role both on frontend and backend

See merge request saburly/wiaas/new-wiaas!40
2018-10-22 09:26:56 +00:00
Almira Krdzic
09aac81276 allow admin on frontend 2018-10-22 11:00:48 +02:00
Almira Krdzic
790d24a1f6 forbid admin user on frontend 2018-10-22 10:58:45 +02:00
Almira Krdzic
3d6f15dd4f return error status on login 2018-10-22 10:35:25 +02:00
Almira Krdzic
5570cf7f91 transform auth user last 2018-10-22 09:53:40 +02:00
Almira Krdzic
e420953c39 do not set cart cookies 2018-10-22 09:52:01 +02:00
Almira Krdzic
21fafc5a43 Enable login by role both on frontend and backend 2018-10-22 09:47:48 +02:00
Almira
87f408125d Merge branch 'preserve-uploads-dir' into 'master'
preserve user uploaded content

See merge request saburly/wiaas/new-wiaas!38
2018-10-22 06:46:38 +00:00
Almira Krdzic
37916e4931 fixes 2018-10-22 08:46:07 +02:00
Bilal Catic
a07b3fb7d9 preserve user uploaded content 2018-10-21 19:18:54 +02:00
Bilal Catic
f76e102bf3 Merge branch 'package-reference' into 'master'
Package reference

See merge request saburly/wiaas/new-wiaas!36
2018-10-21 13:22:49 +00:00
144 changed files with 9122 additions and 4463 deletions

6
.dockerignore Normal file
View 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

View File

@@ -18,6 +18,9 @@ ARG WP_SECURE_AUTH_SALT
ARG WP_LOGGED_IN_SALT
ARG WP_NONCE_SALT
ARG WP_JWT_AUTH_SECRET_KEY
ARG WP_SENDGRID_API_KEY
ARG WP_SENDGRID_FROM_EMAIL
ARG WP_SENDGRID_FROM_NAME
ENV WP_ENV ${WP_ENV}
ENV WP_HOME ${API_URL}
@@ -37,9 +40,13 @@ ENV WP_LOGGED_IN_SALT ${WP_LOGGED_IN_SALT}
ENV WP_NONCE_SALT ${WP_NONCE_SALT}
ENV WP_JWT_AUTH_SECRET_KEY ${WP_JWT_AUTH_SECRET_KEY}
ENV WP_SENDGRID_API_KEY ${WP_SENDGRID_API_KEY}
ENV WP_SENDGRID_FROM_EMAIL ${WP_SENDGRID_FROM_EMAIL}
ENV WP_SENDGRID_FROM_NAME ${WP_SENDGRID_FROM_NAME}
ENV WIAAS_CUSTOMER_INTERFACE ${WIAAS_CUSTOMER_INTERFACE}
RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo
RUN apt-get update && apt-get install -y git unzip gnupg mysql-client sudo libpng-dev
COPY docker/php/composer.phar /usr/local/bin/composer
RUN chmod 755 /usr/local/bin/composer
@@ -50,8 +57,9 @@ RUN chmod +x /usr/local/bin/wp
COPY docker/php/setup.sh /init-scripts/
RUN chmod +x /init-scripts/setup.sh
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN a2enmod rewrite ssl
RUN docker-php-ext-install pdo pdo_mysql mysqli opcache gd zip mbstring
RUN a2enmod rewrite
COPY docker/php/000-default.conf /etc/apache2/sites-available
COPY backend /home/wiaas/backend
@@ -59,13 +67,17 @@ WORKDIR /home/wiaas/backend/
RUN composer install --no-dev
WORKDIR /home/wiaas
RUN rm -rf backend/app/uploads
RUN cp -r backend/* /var/www/html/
WORKDIR home
RUN rm -rf wiaas
WORKDIR /var/www/html
RUN ln -s ../html api
COPY docker/php/.htaccess /var/www/html/
COPY docker/php/.htaccess /var/www/html/
COPY docker/backend/TaC.pdf /var/www/html/
RUN chown -R www-data:www-data /var/www/html

View File

@@ -19,3 +19,46 @@
.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;
}

View File

@@ -0,0 +1,3 @@
.wc-order-preview-address {
display: none;
}

View File

@@ -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);
});
});

View File

@@ -8,4 +8,50 @@ jQuery(document).ready(function($) {
$('#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();
});
});

View File

@@ -0,0 +1,7 @@
jQuery(document).ready(function($) {
$( document.body )
.on( 'wc_backbone_modal_loaded', function () {
$(".wc-order-preview-address").remove();
} );
});

View 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);
});

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -3,9 +3,6 @@
class Wiaas_Admin_Order_Projects {
public static function init() {
// Add admin page and subpage since woocommerce orders have custom menu page
// so this will not be automatic
add_filter('admin_menu', array(__CLASS__, 'add_admin_page'));
// Add is available fields to create and edit forms
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
@@ -18,18 +15,20 @@ class Wiaas_Admin_Order_Projects {
// Save is available field when creating and editing
add_action( 'created_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
add_action( 'edit_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
add_action( 'load-term.php', array( __CLASS__, 'admin_menu_highlight' ) );
add_action( 'load-edit-tags.php', array( __CLASS__, 'admin_menu_highlight' ) );
}
/**
* Add admin submenu page for order projects
* Highlighting orders menu when shop orders page selected
*/
public static function add_admin_page() {
add_submenu_page( 'woocommerce',
esc_html__( 'Order projects', 'wiaas' ),
esc_html__( 'Order projects', 'wiaas' ),
'manage_woocommerce',
'edit-tags.php?taxonomy=shop_order_project'
);
public static function admin_menu_highlight() {
global $plugin_page;
if ( isset( $_GET['taxonomy'] ) && ( $_GET['taxonomy'] === 'shop_order_project' ) ) {
$plugin_page = 'edit.php?post_type=shop_order';
}
}
/**

View File

@@ -226,7 +226,7 @@ class Wiaas_Admin_Organization {
// get current user
$current_user = wp_get_current_user();
update_user_meta($current_user->ID, '_wiaas_current_user_admin_role', $role->name);
update_user_meta($current_user->ID, '_wiaas_admin_role', $role->name);
// switch user role
$current_user->set_role($role->name);

View File

@@ -4,12 +4,13 @@ class Wiaas_Admin_Product {
public static function init() {
add_action('acf/save_post', array(__CLASS__, 'wiaas_my_save_post'), 20, 1);
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__, 'wiaas_maybe_remove_metaboxes'), 999);
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=taxonomy', array(__CLASS__, 'wiaas_render_field'), 10, 1);
add_action('acf/render_field/type=group', array(__CLASS__, 'render_choose_button_for_new_product'), 10, 1);
}
@@ -28,13 +29,12 @@ class Wiaas_Admin_Product {
));
}
public static function render_choose_button_for_new_product($field) {
public static function wiaas_render_field($field) {
if ($field['_name'] === '_wiaas_product_country') {
if ($field['_name'] === '_wiaas_product_general') {
?>
<div id="submitpost" style="padding: 20px;">
<input style="float:right;" name="save" id="save-post" class="button" type="submit" value="Choose"/>
<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
}
@@ -42,7 +42,7 @@ class Wiaas_Admin_Product {
}
public static function wiaas_maybe_remove_metaboxes() {
public static function maybe_remove_metaboxes() {
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
@@ -53,19 +53,14 @@ class Wiaas_Admin_Product {
$post_id = $post->ID;
if ($post_id === 0 ||
($post->post_status !== 'publish' && !(Wiaas_Countries::get_package_country(wc_get_product($post_id))))) {
if ($post_id === 0 || $post->post_status === '_wiaas_no_country') {
remove_meta_box('woocommerce-product-data', 'product', 'normal');
remove_meta_box('submitdiv', 'product', 'side');
remove_meta_box('slugdiv', 'product', 'normal');
remove_meta_box('wiaas_upload_and_link_document', 'product', 'normal');
remove_meta_box('postexcerpt', 'product', 'normal');
remove_meta_box('template_product_meta_box', 'product', 'normal');
remove_meta_box('postimagediv', 'product', 'normal');
remove_meta_box('woocommerce-product-images', 'product', 'normal');
remove_meta_box('wc-jetpack-product_by_user_role', 'product', 'normal');
remove_meta_box('submitdiv', 'product', 'side');
remove_meta_box('groups-permissions', 'product', 'side');
remove_meta_box('tagsdiv-product_tag', 'product', 'side');
@@ -73,15 +68,16 @@ class Wiaas_Admin_Product {
remove_meta_box('tagsdiv-supplier', 'product', 'side');
remove_meta_box('postimagediv', 'product', 'side');
remove_meta_box('woocommerce-product-images', 'product', 'side');
remove_meta_box('submitdiv', 'product', 'side');
remove_meta_box('wiaas_upload_and_link_document', 'product', 'side');
remove_meta_box('radio-tagsdiv-product_country', 'product', 'side');
remove_meta_box('tagsdiv-_wiaas_shop_prices', 'product', 'side');
remove_meta_box('tagsdiv-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('radio-product_catdiv', 'product', 'side');
remove_meta_box('product_catdiv', 'product', 'side');
// Always hide
remove_meta_box('tagsdiv-product_country', 'product', 'side');
}
@@ -99,28 +95,54 @@ class Wiaas_Admin_Product {
* @param $post_id
*/
public static function wiaas_my_save_post($post_id) {
public static function save_initial_product_country_and_type($post_id) {
global $post;
$status = get_post_status( $post->ID);
$value = get_field('_wiaas_product_country', $post_id, true);
$type = get_field('_wiaas_product_type', $post_id, true);
if ($post->post_type !== 'product') {
return;
}
error_log($status);
error_log($value);
$general = get_field('_wiaas_product_general', $post_id);
$country = $general['_wiaas_product_country'];
$type = $general['_wiaas_product_type'];
if (!empty($value) && $status === '_wiaas_no_country' ) {
/**
* 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'
));
wp_set_object_terms($post_id, $value, 'product_country', true);
wp_set_object_terms($post_id, $type, 'product_type', true);
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'
));
}
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -152,18 +152,29 @@ $insert_new_document = $post->post_type !== 'wiaas_doc';
response = response.response;
var infoContainer = jQuery('#wiaas_upload_info');
if (response.substring(0, 6) === 'ERROR:') {
jQuery('#wiaas_upload_errors').html('<span class="text-danger">' +
'<i class="fa fa-exclamation-triangle"></i>' +
infoContainer.html('<span style="color: darkred;">' +
'<i class="dashicons dashicons-warning"></i>' +
' &nbsp; ' + response.substring(6, response.length) +
'</span>');
return;
}
infoContainer.html('<span style="color: darkgreen;">' +
'<i class="dashicons dashicons-yes"></i>' +
' &nbsp; ' + 'Document uploaded and linked' +
'</span>');
<?php
if ($insert_new_document) {
?>
$('#wiaas_attached_documents').find('tbody').append(response);
$('.wiaas_documents_tab a').click();
<?php
} else {
?>
@@ -252,7 +263,8 @@ $insert_new_document = $post->post_type !== 'wiaas_doc';
</div>
</div>
<div id="wiaas_upload_errors" style="color: darkred;">
<div id="wiaas_upload_info">
</div>
</div>

View File

@@ -8,62 +8,17 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$( '.wiaas-search-documents' ).each(function() {
var element = $( this );
var searchTarget = $('#' + element.data('target'));
element.autocomplete({
source: function(request, response) {
$.get( window.ajaxurl, {
action: 'wiaas_json_search_documents',
query: request.term,
_ajax_nonce: '<?php echo wp_create_nonce('wiaas_json_search_documents') ?>'
} ).done( function( documents ) {
response( documents || []);
}
);
},
select: function(event, ui) {
if (!searchTarget || $('#wiaas_attached_document_' + ui.item.id).length) {
return;
}
$.get(window.ajaxurl, {
action: 'wiaas_link_document',
_ajax_nonce: '<?php echo wp_create_nonce('wiaas_link_document') ?>',
id: ui.item.id
}).done( function (document) {
searchTarget.find('tbody').append(document);
});
}
})
.autocomplete( 'instance' )._renderItem = function( ul, item ) {
return $( '<li role="option" id="wiaas-document-autocomplete-' + item.id + '">' )
.text( item.name )
.appendTo( ul );
};
});
$('#wiaas_attached_documents').delegate('.wiaas-remove-attached-document', 'click', function (e) {
e.preventDefault();
var id = $(this).data('id');
$('#wiaas_attached_document_' + id).remove();
});
});
</script>
<div id="wiaas_documents" class="panel woocommerce_options_panel">
<div class="options_group">
<p class="form-field">
<label style="font-weight: bold;" for="wiaas_addon_packages"><?php esc_html_e( 'Search documents:', 'wiaas' ); ?></label>
<input type="text" data-target="wiaas_attached_documents" class="wiaas-search-documents"/>
<input
type="text"
data-target="wiaas_attached_documents"
data-search-nonce="<?php echo wp_create_nonce('wiaas_json_search_documents') ?>"
data-link-nonce="<?php echo wp_create_nonce('wiaas_link_document') ?>"
class="wiaas-search-documents"
/>
</p>
</div>
<div class="options_group">

View File

@@ -148,6 +148,8 @@ class Wiaas_Admin_Package_Pricing {
$pricing_rules,
$commission,
$max_cost_margin);
Wiaas_Access_Management::maybe_handle_product_access($package_id, get_post($package_id));
}
}

View File

@@ -121,8 +121,7 @@ if ( ! defined( 'ABSPATH' ) ) {
if ($cat === 'product') {
$products_total_cost = wiaas_get_package_hardware_procurement_cost($package) +
wiaas_get_package_software_procurement_cost($package);
$products_total_cost = wiaas_get_package_product_procurement_cost($package);
esc_html_e('Total: ' . $products_total_cost, 'wiaas');
}

View File

@@ -44,6 +44,14 @@ class Wiaas_Admin_Product_Additional_Info {
}
}
/**
* 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();
@@ -59,9 +67,14 @@ class Wiaas_Admin_Product_Additional_Info {
if (!empty($search_results)) {
$search_result_objects = array_map('wc_get_product', array_keys($search_results));
foreach ($search_result_objects as $result_id => $producta) {
if (Wiaas_Countries::get_product_country_term_id($producta) !== $country_id) {
unset($search_results[$producta->get_id()]);
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].']';
}
}
}
}

View File

@@ -56,10 +56,16 @@ class Wiaas_Admin_Template_Selection {
<div id="wiaas_selected_template_items_container"><?php
$template_products_data = self::show_template_products($value);
self::render_template_products($template_products_data['hardware']);
self::render_template_products($template_products_data['services']);
self::render_template_products($template_products_data['installation']);
self::render_template_products($template_products_data['software']);
$product = wc_get_product( $post->ID );
if ($product->get_type() == 'bundle') {
$bundled_items = $product->get_bundled_items('view');
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
self::render_template_products($template_products_data['hardware'], $categories_form_bundle);
self::render_template_products($template_products_data['services'], $categories_form_bundle);
self::render_template_products($template_products_data['installation'], $categories_form_bundle);
self::render_template_products($template_products_data['software'], $categories_form_bundle);
}
?></div><?php
}
@@ -132,17 +138,22 @@ class Wiaas_Admin_Template_Selection {
* Render html of template categories
*
* @param $template_products array containing template category information
* @param $categories_form_bundle
*/
public static function render_template_products($template_products) {
public static function render_template_products($template_products, $categories_form_bundle = array()) {
if (!empty($template_products)) {
foreach ($template_products as $item) {
$connected_product = $categories_form_bundle[$item['template_category_id']] ?
$categories_form_bundle[$item['template_category_id']]->product_name : '';
$product_id = $item['template_category_id'];
$title = $item['template_category_title'];
$quantity = $item['quantity'];
$connected_product_name = $connected_product;
include('views/html-wiaas-template-selection.php');
}

View File

@@ -83,7 +83,8 @@ class Wiaas_Template_Admin_Ajax {
$terms = get_terms(array(
'taxonomy' => 'template_category',
'name__like' => $term
'name__like' => $term,
'hide_empty' => false
));
foreach ($terms as $t) {

View File

@@ -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

View File

@@ -5,7 +5,6 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* TODO: This is temporary implemetation and will probably be changed during work on pending wiaas cart task
* Class Wiaas_Document_API
*/
class Wiaas_Document_API {
@@ -30,30 +29,26 @@ class Wiaas_Document_API {
)
) );
register_rest_route( self::$namespace, 'documents/order/(?P<id>\d+)/(?P<type>[\w-]+)', array(
register_rest_route( self::$namespace, 'order/(?P<id>\d+)/item/(?P<item_id>\d+)/document/(?P<key>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Order ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
),
'type' => array(
'description' => __( 'Order document type.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
),
)
),
array(
'methods' => 'GET',
'permission_callback' => 'is_user_logged_in',
'callback' => array(__CLASS__, 'download_order_document'),
'callback' => array(__CLASS__, 'download_order_item_document'),
'args' => array(
'item_id' => array(
'description' => __( 'Package Order Item ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
'required' => true
),
'document_key' => array(
'key' => array(
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
@@ -62,6 +57,29 @@ class Wiaas_Document_API {
)
)
) );
register_rest_route(self::$namespace, 'order/(?P<id>\d+)/document/(?P<key>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Order ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
)
),
array(
'methods' => 'GET',
'permission_callback' => 'is_user_logged_in',
'callback' => array(__CLASS__, 'download_order_other_document'),
'args' => array(
'key' => array(
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'required' => true
),
)
)
));
}
/**
@@ -76,14 +94,23 @@ class Wiaas_Document_API {
}
/**
* Download order document
* Download order item document
*
* @param WP_REST_Request $request
*/
public static function download_order_document($request) {
public static function download_order_item_document($request) {
Wiaas_Document_Download::download_order_item_document(
$request['id'],
$request['item_id'],
$request['type'],
$request['document_key']);
$request['key']);
}
/**
* Download order document
*
* @param WP_REST_Request $request
*/
public static function download_order_other_document($request) {
Wiaas_Document_Download::download_order_other_document($request['id'], $request['key']);
}
}

View File

@@ -148,6 +148,10 @@ class Wiaas_REST_Customer_API {
return wiaas_api_notice('ADD_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
if (!Wiaas_Validation::is_phone($phone)){
return wiaas_api_notice('INVALID_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
};
if (!Wiaas_Customer::update_customer_profile_info($customer_id, $first_name, $last_name, $phone)){
return wiaas_api_notice('PROFILE_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
}

View File

@@ -26,28 +26,44 @@ class Wiass_REST_Delivery_Process_API {
*/
private static $namespace = 'wiaas';
private static $rest_base = 'delivery';
public static function register_routes() {
register_rest_route( self::$namespace, 'next-delivery-steps', array(
register_rest_route( self::$namespace, '/' . self::$rest_base . '/next-actions', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_next_actions_for_user'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer-acceptance/(?P<entry_id>\d+)', array(
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-acceptance', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_customer_acceptance'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer-acceptance/(?P<entry_id>\d+)', array(
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-acceptance', array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'submit_customer_acceptance'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer-acceptance/(?P<entry_id>\d+)/upload-file' , array(
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-acceptance/upload' , array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'upload_file'),
'callback' => array(__CLASS__, 'upload_customer_acceptance'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-questionnaires', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_customer_questionnaires'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, '/' . self::$rest_base . '/(?P<order_id>\d+)/customer-questionnaires/upload/(?P<action_entry_id>\d+)', array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'upload_customer_questionnaire'),
'permission_callback' => 'is_user_logged_in'
) );
}
@@ -61,14 +77,6 @@ class Wiass_REST_Delivery_Process_API {
'value' => 'pending',
);
$user_roles = gravity_flow()->get_user_roles();
foreach ( $user_roles as $user_role ) {
$field_filters[] = array(
'key' => 'workflow_role_' . $user_role,
'value' => 'pending',
);
}
$field_filters['mode'] = 'any';
$search_criteria = array();
@@ -77,10 +85,11 @@ class Wiass_REST_Delivery_Process_API {
$form_ids = gravity_flow()->get_workflow_form_ids();
$total_count = 7;
$entries = GFAPI::get_entries( $form_ids, $search_criteria, null, null, $total_count );
$entries = GFAPI::get_entries(
$form_ids,
$search_criteria,
null,
null);
$data = array();
foreach ($entries as $entry) {
@@ -96,175 +105,73 @@ class Wiass_REST_Delivery_Process_API {
return rest_ensure_response($data);
}
public static function get_customer_acceptance(WP_REST_Request $request){
$entry = GFAPI::get_entry($request['entry_id']);
if (is_wp_error($entry)){
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
}
public function get_customer_questionnaires(WP_REST_Request $request) {
$acceptance_documents = array();
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
$order_id = absint($request['order_id']);
foreach($uploaded_files as $file_url){
//example of decoded url :
//http://localhost/wp/index.php?gf-download=2018/08/rokovi-1535378841.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534
$decoded_url = urldecode($file_url);
$url_parts = explode('?', $decoded_url);
$file_name_base_parts = explode('&', $url_parts[1]);
$file_name_parts = explode('/', $file_name_base_parts[0]);
$file_name_with_extension_parts = explode('.', $file_name_parts[2]);
$data = Wiaas_Delivery_Process::get_customer_questionnaires_data($order_id);
$acceptance_documents_entry = array(
'name' => $file_name_with_extension_parts[0],
'extension' => $file_name_with_extension_parts[1],
'url' => $file_url
);
array_push($acceptance_documents, $acceptance_documents_entry);
}
$acceptance_status = 0;
if ($entry[self::ACCEPTANCE_STATUS_FIELD_ID]){
$acceptance_status = ($entry[self::ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1;
}
return rest_ensure_response(array(
'documents' => $acceptance_documents,
'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
'status' => $acceptance_status,
'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
));
return rest_ensure_response($data);
}
public static function submit_customer_acceptance(WP_REST_Request $request){
$entry = GFAPI::get_entry($request['entry_id']);
if (is_wp_error($entry)){
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
}
public function upload_customer_questionnaire(WP_REST_Request $request) {
$status = $request['actionType'];
$reason = $request['declineReason'];
$order_id = absint($request['order_id']);
$action_entry_id = absint($request['action_entry_id']);
Wiaas_Delivery_Process::upload_customer_questionnaire($order_id, $action_entry_id);
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
}
public static function get_customer_acceptance(WP_REST_Request $request){
$order_id = absint($request['order_id']);
$data = Wiaas_Delivery_Process::get_customer_acceptance_data($order_id);
return rest_ensure_response($data);
}
public static function submit_customer_acceptance(WP_REST_Request $request) {
$status = $request['action_type'];
$reason = $request['decline_reason'];
if (!in_array($status, self::ACCEPTABLE_STATUS)){
return wiaas_api_notice('ACCEPTANCE_STATUS_MISSING', 'error');
}
$installation_declined = ($status === self::DECLINE_STATUS_LABEL);
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
if ($installation_declined && $reason === ''){
return wiaas_api_notice('DECLINE_REASON_EMPTY', 'error');
}
if (!$installation_declined && (count($uploaded_files)===0)){
$order_id = $request['order_id'];
if (! $installation_declined && ! Wiaas_Delivery_Process::is_customer_acceptance_uploaded($order_id)) {
return wiaas_api_notice('ACCEPTANCE_NOT_UPLOADED', 'error');
}
$entry[self::DECLINE_REASON_FIELD_ID] = $reason;
$entry[self::ACCEPTANCE_STATUS_FIELD_ID] = $status;
if (!GFAPI::update_entry( $entry )){
return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
}
//Check if step is already completed, to not submit again
$gf_api = new Gravity_Flow_API($entry['form_id']);
$current_step = $gf_api->get_current_step($entry);
if ($current_step->get_name() !== self::USER_INPUT_STEP_NAME){
return wiaas_api_notice('ACCEPTANCE_STATUS_UPDATED', 'success');
}
if ( $current_step ) {
$current_step->purge_assignees();
$current_step->update_step_status( 'complete' );
}
$entry_id = $entry['id'];
$new_step_id = $current_step->get_id() + 1;
$new_step = $gf_api->get_step( $new_step_id, $entry );
$feedback = sprintf( esc_html__( 'Sent to step: %s', 'gravityflow' ), $new_step->get_name() );
$gf_api->add_timeline_note( $entry_id, $feedback );
$gf_api->log_activity( 'workflow', 'sent_to_step', $gf_api->form_id, $entry_id, $step_id );
gform_update_meta( $entry_id, 'workflow_final_status', 'pending' );
$new_step->start();
$gf_api->process_workflow( $entry_id );
Wiaas_Delivery_Process::update_customer_acceptance_status($order_id, $status, $reason);
if ($installation_declined){
return wiaas_api_notice('INSTALLATION_DECLINED', 'success');
}
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
}
public static function upload_file(WP_REST_Request $request){
$files = $request->get_file_params();
if (!$files[self::FILE_KEY_NAME]){
return wiaas_api_notice('NO_FILES_UPLOADED', 'error');
}
public static function upload_customer_acceptance(WP_REST_Request $request){
$entry = GFAPI::get_entry($request['entry_id']);
if (is_wp_error($entry)){
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
}
$order_id = $request['order_id'];
$form = GFAPI::get_form($entry['form_id']);
$form_upload_path = GFFormsModel::get_upload_path( $form['id'] );
$success = Wiaas_Delivery_Process::upload_customer_acceptance_document($order_id);
$target_path = $form_upload_path . '/' . date('Y') . '/' . date('m') . '/';
wp_mkdir_p( $target_path );
GFCommon::recursive_add_index_file( $target_path );
$upload_file_field = GFAPI::get_field($form['id'], self::UPLOADED_FILES_FIELD_ID);
$file_name = sanitize_file_name($files[self::FILE_KEY_NAME]['name']);
$file_path_details = pathinfo($file_name);
if ( GFCommon::file_name_has_disallowed_extension( $file_name ) ) {
return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
}
$allowed_extensions = ! empty( $upload_file_field->allowedExtensions ) ? GFCommon::clean_extensions( explode( ',', strtolower( $upload_file_field->allowedExtensions ) ) ) : array();
if ( ! empty( $allowed_extensions ) ) {
if ( ! GFCommon::match_file_extension( $file_name, $allowed_extensions ) ) {
return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
}
}
$new_file_name = $file_path_details['filename'] . '-' . time() . '.' . $file_path_details['extension'];
// Bypasses security checks when running unit tests.
if ( defined( 'WP_TEST_IN_PROGRESS' ) && WP_TEST_IN_PROGRESS ) {
return wiaas_api_notice('FILE_UPLOADED', 'success');
}
if ( move_uploaded_file($files[self::FILE_KEY_NAME]['tmp_name'], $target_path . $new_file_name ) ) {
GFFormsModel::set_permissions( $target_path . $new_file_name );
} else {
return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
}
//Extract path relative to the root
//Last 6 strings (excluding last empty) are path relative to the root
$path_parts = explode('/', $target_path);
$relative_path = '';
$i = count($path_parts) - self::PATH_PARTS_TO_EXTRACT;
while($i < count($path_parts)-1){
$relative_path = $relative_path . $path_parts[$i] . '/';
$i++;
}
$file_url = self::BASE_NAME . $relative_path . $new_file_name;
$url_for_download = $upload_file_field->get_download_url($file_url);
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
if ($uploaded_files === NULL){
$uploaded_files = [];
}
array_push($uploaded_files, $url_for_download);
$entry[self::UPLOADED_FILES_FIELD_ID] = json_encode($uploaded_files);
if (GFAPI::update_entry( $entry )) {
if ($success) {
return wiaas_api_notice('FILE_UPLOADED','success');
}

View File

@@ -43,7 +43,7 @@ class Wiass_REST_User_API {
}
public static function get_countries(){
$countries = Wiaas_Countries::get_list_of_countries();
$countries = Wiaas_Countries::get_available_countries();
return rest_ensure_response($countries);
}

View File

@@ -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');
}
}

View File

@@ -17,6 +17,7 @@ class Wiaas_Access_Management {
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 );
}
/**
@@ -76,6 +77,26 @@ class Wiaas_Access_Management {
}
}
/**
* 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();

View File

@@ -1,12 +1,9 @@
<?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';
@@ -20,11 +17,21 @@ class Wiaas_Admin {
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
// Admin organization interface
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
// Admin order delivery process
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-product.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-supplier.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-user-profile.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-countries.php';
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
}

View File

@@ -43,7 +43,8 @@ class Wiaas_API {
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc-package-api-integration.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-support-api.php';
// API functions
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
@@ -58,6 +59,7 @@ class Wiaas_API {
'Wiass_REST_User_API',
'Wiaas_REST_Customer_API',
'Wiaas_Order_Projects_API',
'Wiaas_Support_Api',
);
foreach ( $controllers as $controller ) {

View File

@@ -9,192 +9,177 @@
*/
class Wiaas_Authentication {
const SUPER_ADMIN_USER_ID = 1;
const SUPER_ADMIN_USER_ID = 1;
public static function init() {
// authenticate current user
add_action('determine_current_user', array(__CLASS__, 'authenticate_current_user'), 999);
public static function init() {
// authenticate current user
add_action('determine_current_user', array(__CLASS__, 'authenticate_current_user'), 999);
// authenticates user on login
add_filter( 'authenticate', array( __CLASS__, 'authenticate_user_on_login' ), 999, 3);
// authenticates user on login
add_filter( 'authenticate', array( __CLASS__, 'authenticate_user_on_login' ), 999, 3);
// retrieve preferred user role for user
add_filter('get_user_metadata', array(__CLASS__, 'maybe_filter_user_roles'), 10, 3);
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'authenticate_rest_user_on_login'), 999, 2);
// redirect to dashboard after login
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ) );
// redirect to dashboard after login
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ) );
}
// add role selector to login form
add_action('login_form', array(__CLASS__, 'pick_role_on_login'));
}
/**
* Redirect admin user to dashboard
*
* @return string
*/
public static function login_redirect() {
return admin_url('index.php') ;
}
/**
* Add role selector to login form
*/
public static function pick_role_on_login() {
?>
<p>
<label for="user_role"><?php esc_html_e( 'Role' , 'wiaas'); ?><br />
<select id="user_role" class="input" name="role">
<option value="administrator"><?php esc_html_e('Administrator', 'wiaas') ?></option>
<option value="supplier"><?php esc_html_e('Supplier', 'wiaas') ?></option>
<option value="commercial_lead"><?php esc_html_e('Commercial Lead', 'wiaas') ?></option>
</select>
</p>
<?php
}
/**
* Redirect admin user to dashboard
*
* @return string
*/
public static function login_redirect() {
return admin_url('index.php') ;
}
/**
* Authenticate current user based on roles assigned to organization
*
* @param int|false $user_id
* @return int|false|WP_Error
*/
public static function authenticate_current_user($user_id) {
// do nothing if user not authenticated, user is super admin or this is REST API request
if (! $user_id || $user_id === self::SUPER_ADMIN_USER_ID) {
return $user_id;
}
/**
* Authenticate current user based on roles assigned to organization
*
* If this is non admin request successfully validate user if he can have customer role.
*
* If this is admin panel request successfully validate user if has admin panel role selected
* and also he still can have that role (role was not removed from his customer organization)
*
* @param int|false $user_id
* @return int|false|WP_Error
*/
public static function authenticate_current_user($user_id) {
// do nothing if user not authenticated, user is super admin or this is REST API request
if (! $user_id || (int) $user_id === self::SUPER_ADMIN_USER_ID) {
return $user_id;
}
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
global $current_user;
$role = $is_rest_api ?
'customer' :
get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
if (empty($current_user)) {
$result = self::_can_user_have_role($user_id, $role, $is_rest_api);
$current_user = new WP_User($user_id);
}
if (is_wp_error($result)) {
return false;
}
$rest_api_slug = rest_get_url_prefix();
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
return $user_id;
}
if ($valid_api_uri) {
//for non admin request check if user has customer role
$role = 'customer';
} else {
// for admin panel request check if user has selected role
$role = get_user_meta($user_id, '_wiaas_admin_role', true);
}
/**
* Authenticate wiaas user on login based on roles assigned to organization
*
* @param WP_User $user
* @return WP_User|WP_Error
*/
public static function authenticate_user_on_login($user) {
// check if rest request
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
// do nothing if there is an error already,
// user is super admin or
// this is rest request
if (is_wp_error($user) || $user->ID === 1 || $is_rest_api) {
return $user;
}
if ( empty($role) || ! user_can($user_id, 'wiaas_' . $role)) {
// not available roles for user
$current_user->set_role('');
if (empty($_POST['role'])) {
return new WP_Error('error', 'You must selected role to login!');
}
return new WP_Error('wiaas_authentication_error', 'No set permissions!', array(
'status' => 403,
));
}
// get selected role
$requested_role = sanitize_key($_POST['role']);
// authenticate valid admin panel user
$current_user->set_role($role);
// validate can user have requested role
$result = self::_can_user_have_role($user->ID, $requested_role, false);
return $user_id;
}
// if user organization has no requested role prevent access
if (is_wp_error($result)) {
return $result;
}
// remember role for user and continue
update_user_meta($user->ID, '_wiaas_current_user_admin_role', $requested_role);
return $user;
}
/**
* Authenticate wiaas user on login based on roles assigned to organization
*
* If this is non admin panel request authenticate user if he can be customer.
*
* If this is admin panel login request user will be authenticated with previously selected or first available role
* from his organization roles.
*
* @param WP_User $user
* @return WP_User|WP_Error
*/
public static function authenticate_user_on_login($user) {
// do nothing if there is an error already,
// user is super admin
if (is_wp_error($user) || $user->ID === self::SUPER_ADMIN_USER_ID ) {
return $user;
}
/**
*
* Filters user roles retrieval so that selected user role is retrieved for admin panel
* and customer role is retrieved for JSON API request
*
* @param $null
* @param int $user_id
* @param string $meta_key
* @return array|null
*/
public static function maybe_filter_user_roles($null, $user_id, $meta_key) {
global $wpdb;
if ($user_id !== 0 && $user_id !== self::SUPER_ADMIN_USER_ID && $meta_key === $wpdb->get_blog_prefix() . 'capabilities') {
$is_rest_api = strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix());
$role = $is_rest_api ?
'customer' :
get_user_meta($user_id, '_wiaas_current_user_admin_role', true);
return array( array ( "$role" => true ));
}
return null;
}
$rest_api_slug = rest_get_url_prefix();
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
/**
* CUSTOMER API AUTHENTICATION
*/
// validate customer user login
if ($valid_api_uri) {
// PRIVATE
$role = user_can($user->ID, 'wiaas_customer') ? 'customer' : '';
$user->set_role($role);
/**
* Determines if user can have requested role based on his organization roles
*
* @param int $user_id
* @param string $user_role
* @param bool $is_rest_api
* @return bool|WP_Error
*/
private static function _can_user_have_role($user_id, $user_role, $is_rest_api) {
// check if role valid for access
if (! wp_roles()->is_role($user_role)) {
return new WP_Error('error', 'Role is not valid!');
}
return empty($role) ?
new WP_Error('wiaas_authentication_error', 'No Customer permissions!', array(
'status' => 403,
)) :
$user;
}
// only customer role can access API
if ($is_rest_api && $user_role !== 'customer') {
return new WP_Error('error', 'No access!');
}
/**
* ADMIN PANEL AUTHENTICATION
*/
// customer role cannot access admin backend
if (! $is_rest_api && $user_role === 'customer') {
return new WP_Error('error', 'No access!');
}
// retrieve selected role for user
$role = get_user_meta($user->ID, '_wiaas_admin_role', true);
// if user has selected role then use it
if (! empty($role) && user_can($user->ID, 'wiaas_' . $role)) {
return $user;
}
// import organization functions (during user authentication it is not yet loaded)
require_once dirname( __FILE__ ) . '/user/wiaas-organization-functions.php';
// user does not have selected role so try to assign one in order of access
if (user_can($user->ID, 'wiaas_administrator')) {
$role = 'administrator';
} else if (user_can($user->ID, 'wiaas_commercial_lead')) {
$role = 'commercial_lead';
} else if (user_can($user->ID, 'wiaas_supplier')) {
$role = 'supplier';
}
// get user organization
$organization_id = wiaas_get_user_organization_id($user_id);
if (empty($role)) {
return new WP_Error('wiaas_authentication_error', 'No permissions!', array(
'status' => 403,
));
}
// validate if user has organization
if (empty( $organization_id)) {
return new WP_Error('error', 'Account not completed!');
}
// get organization roles
$roles = wiaas_get_organization_roles($organization_id);
update_user_meta($user->ID, '_wiaas_admin_role', $role);
// validate if user has organization roles
if (!in_array($user_role, $roles)) {
return new WP_Error( 'error', 'Your account is not authorized for requested role. Please contact us for help.' );
}
$user->set_role($role);
return $user;
}
/**
* validate that successfully logged in rest api user can be customer
*
* @param array $data
* @param WP_User $user
* @return array | WP_Error
*
*/
public static function authenticate_rest_user_on_login($data, $user) {
// if admin do nothing
if ($user->ID === self::SUPER_ADMIN_USER_ID) {
return $data;
}
$role = user_can($user->ID, 'wiaas_customer') ? 'customer' : '';
$user->set_role($role);
return empty($role) ?
new WP_Error('wiaas_authentication_error', 'No Customer permissions!', array(
'status' => 403,
)) :
$data;
}
return true;
}
}
Wiaas_Authentication::init();

View File

@@ -28,6 +28,18 @@ class Wiaas_Cart {
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
add_action('woocommerce_checkout_create_order', array(__CLASS__, 'add_additional_order_data'), 99);
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 );
}
}
/**
@@ -152,11 +164,35 @@ class Wiaas_Cart {
return false;
}
// TODO: Add validation that only packages from the same country can be added to cart at the same time
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
// Validate that order contains only stuff from single commercial lead / reseller / shop owner
if ( ! WC()->cart->is_empty() ) {
// TODO: Add validation that only packages from the same shop can be added to cart at the same time
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
$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();
@@ -236,6 +272,10 @@ class Wiaas_Cart {
* @return bool
*/
public static function update_package_quantity($package_cart_item_key, $new_quantity) {
if ($new_quantity > 65000){
return false;
}
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
if (!$cart_item) {
@@ -282,8 +322,12 @@ class Wiaas_Cart {
}
/**
* Persist used payment type information for package in corresponding order line item.
* Also for standard package type list of addons and options will be saved.
* Persist additional metadata for every order item
* This includes:
*
* 1. payment info
* 2. relation info for addons and options
* 3. prices for simple products
*
* @param $order_item
* @param $cart_item_key
@@ -293,7 +337,11 @@ class Wiaas_Cart {
* @return WC_Order_Item
*/
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
$is_bundle_item = wc_pb_is_bundle_container_cart_item($cart_item);
$is_bundled_item = wc_pb_is_bundled_cart_item($cart_item);
if ($is_bundle_item && isset($cart_item['_wiaas_payment'])) {
$payment = $cart_item['_wiaas_payment'];
@@ -362,6 +410,36 @@ class Wiaas_Cart {
$order_item->add_meta_data( '_wiaas_documents', $item_documents, true );
}
// save simple product information that needs to be available later on
// even if this data is changed or removed from product at that time
if($is_bundled_item) {
$product = wc_get_product($cart_item['product_id']);
$order_item->add_meta_data('_wiaas_category', Wiaas_Product_Category::get_category($product), true);
$order_item->add_meta_data('_wiaas_manufacturer_product_no', $product->get_meta('_manufacturer_product_no'), true);
$order_item->add_meta_data('_wiaas_supplier_product_no', $product->get_meta('_supplier_product_no'), true);
// get supplier
if ($supplier_organization_id = Wiaas_Product_Supplier::get_supplier_organisation_id_from_product($cart_item['product_id'])) {
$order_item->add_meta_data('_wiaas_supplier_organization_id', $supplier_organization_id, true);
}
// save bundled product item total cost (price x period)
$product_price = Wiaas_Pricing::get_product_total_cost($product);
$order_item->add_meta_data('_wiaas_product_price', $product_price, true);
}
// save number of days before earliest installation for bundles
if ($is_bundle_item) {
$order_item->add_meta_data(
'_wiaas_earliest_installation_additional_days',
Wiaas_Package::get_earliest_installation_additional_days($cart_item['product_id']),
true);
}
return $order_item;
}
@@ -389,6 +467,14 @@ class Wiaas_Cart {
'_wiaas_option_group_name',
'_wiaas_standard_package',
'_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'
) );
}
@@ -406,13 +492,93 @@ class Wiaas_Cart {
$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);
// set order commercial lead
// 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);
}
/**
@@ -576,6 +742,7 @@ class Wiaas_Cart {
$documents_ids = array();
// Retrieve all document ids attached to cart content
foreach ($items as $key => $item) {
if (!isset($item['_wiaas_standard_package'])) {
continue;
@@ -593,16 +760,19 @@ class Wiaas_Cart {
}
}
// Retrieve all customer visible template documents attached to cart content
$q = new WP_Query();
$retrieved_items = $q->query(array(
'post_status' => 'publish',
'post_type' => 'wiaas_doc',
'post__in' => array_keys($documents_ids),
'meta_key' => '_wiaas_doc_visible',
'meta_value' => 'yes', // visible to customer
'tax_query' => array(
array(
'taxonomy' => 'wiaas_doc_type',
'field' => 'slug',
'terms' => array_keys(self::$cart_doc_types),
'terms' => array_keys(self::$cart_doc_types), // templates only
)
)
));

View File

@@ -65,7 +65,8 @@ class Wiaas_Checkout {
do_action( 'woocommerce_checkout_order_processed', $order_id, array(), $order );
$order->payment_complete();
//Change order status from default 'Pending payment' to open (custom wiaas status)
$order->update_status('open');
WC()->cart->empty_cart( true );

View File

@@ -12,28 +12,19 @@ if ( ! defined( 'ABSPATH' ) ) {
class Wiaas_Countries {
/**
* Available countries for wiaas
* Default available countries for wiaas
* @var array
*/
private static $available_countries = array(
'Sweden' => array(
'id' => 1,
'name' => 'Sweden',
'code' => 'se',
private static $default_countries = array(
'se' => array(
'vat' => 9 ,
'currency' => 'SEK'
),
'Denmark' => array(
'id' => 2,
'name' => 'Denmark',
'code' => 'dk',
'dk' => array(
'vat' => 9 ,
'currency' => 'DKK'
),
'Finland' => array(
'id' => 3,
'name' => 'Finland',
'code' => 'fi',
'fi' => array(
'vat' => 9 ,
'currency' => 'EUR'
),
@@ -44,22 +35,101 @@ class Wiaas_Countries {
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
}
public static function get_list_of_countries(){
$result = [];
foreach(self::$available_countries as $country){
array_push($result, array(
'country_id' => $country['id'],
'country_name' => $country['name']
));
/**
* Retrieve all possible country choices
*
* @return array
*/
public static function get_country_choices() {
$countries = new WC_Countries();
$choices = array();
foreach ($countries->get_countries() as $code => $name) {
$choices[strtolower($code)] = $name;
}
return $result;
return $choices;
}
public static function get_country_name_by_id($id){
foreach(self::$available_countries as $country){
if ($country['id'] == $id) return $country['name'];
/**
* Retrieve all possible currency choices
*
* @return array
*/
public static function get_currency_choices() {
return get_woocommerce_currencies();
}
/**
* Retrieve list of available countries setup by administrator
*
* @return array
*/
public static function get_available_countries() {
$available_countries = [];
$available_country_terms = get_terms(array(
'taxonomy' => 'product_country',
'hide_empty' => false,
));
foreach($available_country_terms as $country_term) {
$code = get_term_meta($country_term->term_id, '_wiaas_country_code', true);
$currency = get_term_meta($country_term->term_id, '_wiaas_country_currency', true);
$vat = get_term_meta($country_term->term_id, '_wiaas_country_vat', true);
$available_countries[] = array(
'id' => $country_term->term_id,
'name' => $country_term->name,
'code' => $code,
'currency' => $currency,
'vat' => $vat
);
}
return '';
return $available_countries;
}
/**
* Retrieve country name by code for available country
*
* @param string $code
*
* @return string|null
*/
public static function get_available_country_name_by_code($code) {
$available_countries = self::get_available_countries();
foreach ($available_countries as $available_country) {
if ($available_country['code'] === $code) {
return $available_country['name'];
}
}
return null;
}
/**
* Retrieve country code by currency for available country
*
* @param string $currency
*
* @return string|null
*/
public static function get_available_country_code_by_currency($currency) {
$available_countries = self::get_available_countries();
foreach ($available_countries as $available_country) {
if ($available_country['currency'] === $currency) {
return $available_country['code'];
}
}
return null;
}
/**
@@ -93,8 +163,27 @@ class Wiaas_Countries {
register_taxonomy( 'product_country', array( 'product' ), $args );
foreach (self::$available_countries as $available_country) {
wp_insert_term($available_country['name'], 'product_country');
$choices = self::get_country_choices();
foreach (self::$default_countries as $code => $info) {
$name = $choices[$code];
if (has_term($name)) {
// bail out
return;
}
$name = $choices[$code];
$result = wp_insert_term($name, 'product_country');
if (is_wp_error($result)) {
continue;
}
update_term_meta($result->term_id, '_wiaas_country_code', $code);
update_term_meta($result->term_id, '_wiaas_country_currency', $info['currency']);
update_term_meta($result->term_id, '_wiaas_country_vat', $info['vat']);
}
}
@@ -115,10 +204,25 @@ 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;
$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
);
}
/**

View File

@@ -5,26 +5,31 @@ defined( 'ABSPATH' ) || exit;
class Wiaas_DB_Update {
private static $db_updates = array(
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
'20180801222206' => 'wiaas_db_update_setup_gravity',
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
'20180826153509' => 'wiaas_create_broker_access_group',
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
'201810121644700' => 'wiaas_db_update_add_user_organization_ui_fields',
'201810171645700' => 'wiaas_db_update_create_default_roles',
'201810171745700' => 'wiaas_db_import_aam_role_settings',
'201810180145700' => 'wiaas_db_update_update_supplier_capabilities',
'201810180245700' => 'wiaas_db_update_update_admin_capabilities',
'201810180345700' => 'wiaas_create_role_access_groups',
'201810180444700' => 'wiaas_db_setup_create_customer_commercial_lead_table',
'201810180544702' => 'wiaas_db_update_update_commercial_lead_capabilities',
'201810180644703' => 'wiaas_db_update_add_organization_info_ui_fields',
'201910190145700' => 'wiaas_db_update_add_general_ui_fields',
'201910190146700' => 'wiaas_db_update_add_product_properties_ui_fields',
'201810190644704' => 'wiaas_db_update_add_reference_ui_field'
'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() {

View File

@@ -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') );

View File

@@ -18,9 +18,16 @@ class Wiaas_Order {
public static function init() {
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
require_once dirname( __FILE__ ) . '/order/wiaas-order-functions.php';
add_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);
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 999, 3);
@@ -28,6 +35,223 @@ 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;
}
/**
@@ -178,10 +402,63 @@ class Wiaas_Order {
return get_post_meta($order_id, '_wiaas_tender', true);
}
public static function get_order_country_code($order_id) {
$order = wc_get_order($order_id);
$code = $order->get_meta('_wiaas_country_code');
if (empty($code)) {
$code = Wiaas_Countries::get_available_country_code_by_currency($order->get_currency());
$order->add_meta_data('_wiaas_country_code', $code);
$order->save_meta_data();
}
return $code;
}
/**
* PRIVATE
*/
private static function _update_max_and_earliest_dates($order, $suppliers){
$max_estimated_date = 0;
$max_confirmed_date = 0;
$earliest_installation_date = 0;
$missing_estimated = false;
foreach($suppliers as $supplier) {
if (! empty($supplier['confirmed_date']) ) {
$max_confirmed_date = max($max_confirmed_date, $supplier['confirmed_date']);
} else {
$missing_confirmed = true;
}
if (! empty($supplier['estimated_date']) ) {
$max_estimated_date = max($max_estimated_date, $supplier['estimated_date']);
} else {
$missing_estimated = true;
$earliest_installation_date = 0;
}
}
if (! $missing_estimated) {
$earliest_installation_date = max($max_estimated_date, $max_confirmed_date);
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' weekdays', $earliest_installation_date);
}
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
$order->update_meta_data('_wiaas_final_estimated_delivery_date', $max_estimated_date);
$order->update_meta_data('_wiaas_earliest_installation_date', $earliest_installation_date);
}
/**
* Append specific wiaas order details, like reference
* @param $data
@@ -201,19 +478,33 @@ class Wiaas_Order {
/**
* Appends additional wiaas customer lead info to order json response
* @param $data
* @param $order
* @param WC_Order $order
* @param $request
*
* @return mixed
*/
private static function _append_commercial_lead_info($data, $order, $request) {
$data['commercial_lead'] = array(
'id' => 1,
'name' => 'Coor Service Management',
'phone' => '123456789',
'email' => 'rikard@co-ideation.com'
);
$commercial_lead_org_id = $order->get_meta('_wiaas_commercial_lead_id', true);
$commercial_lead_organization_info = $order->get_meta('_wiaas_commercial_lead_info', true);
if (! empty($commercial_lead_org_id) && empty($commercial_lead_organization_info)) {
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
$data['commercial_lead'] = array(
'id' => $commercial_lead_org_id,
'name' => $commercial_lead_organization_info['name'],
'phone' => $commercial_lead_organization_info['phone'],
'email' => $commercial_lead_organization_info['email']
);
}
if (!empty($commercial_lead_organization_info)) {
$commercial_lead_organization_info['id'] = $commercial_lead_org_id;
$data['commercial_lead'] = $commercial_lead_organization_info;
}
return $data;
}
@@ -221,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;
}
@@ -309,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;
}
}
@@ -387,11 +693,14 @@ class Wiaas_Order {
if (wiaas_is_order_item__standard_package($order_item)) {
$documents = wiaas_get_standard_package_order_item_documents($order, $product_line['id']);
$data['line_items'][$index] ['documents'] = $documents;
}
}
$data['documents'] = wiaas_get_order_other_documents($order->get_id());
return $data;
}
}

View File

@@ -48,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

View File

@@ -70,6 +70,10 @@ class Wiaas_Product {
return $args;
}
public static function get_supplier_id($product_id){
return wp_get_post_terms($product_id, 'supplier', array('fields' => 'ids'))[0];
}
}
Wiaas_Product::init();

View File

@@ -19,9 +19,9 @@ class Wiaas_Shop {
// update prices search terms for package after prices extras have been updated
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
// create new shop if organization was assigned commercial lead role
// or remove shop if commercial lead role was removed for organization
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'maybe_manage_shop_for_commercial_lead'), 10, 2);
// 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) {
@@ -86,18 +86,24 @@ class Wiaas_Shop {
}
/**
* Creates shop for new shop owner (organization with commercial lead role) or
* deletes existing shop if that role has been removed
* Remove shop for organization that is no longer commercial lead
*
* @param int $owner_id
* @param array $roles
*/
public static function maybe_manage_shop_for_commercial_lead($owner_id, $roles) {
$is_commercial_lead = in_array('commercial_lead', $roles);
public static function remove_deactivated_shop($owner_id) {
$roles = wiaas_get_organization_roles($owner_id);
$is_commercial_lead ?
self::_maybe_create_shop($owner_id) :
self::_maybe_remove_shop($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);
}
/**
@@ -132,7 +138,7 @@ class Wiaas_Shop {
* $extra_price_payment_type => {
* @type bool visible Indicates if payment type is visible to customer
* }
* }
* }
* @param array $old_cl_extras {
* $extra_price_payment_type => {
* @type bool visible Indicates if payment type is visible to customer
@@ -156,49 +162,6 @@ class Wiaas_Shop {
// PRIVATE
/**
* Each shop will be registered as product attribute.
* This will persist shops information into database.
* Also every attribute has taxonomy associated with it which will enable us to have multiple
* catalogues in one shop
*
* @param int $owner_id
*/
private static function _maybe_create_shop($owner_id) {
$shop_name = 'wiaas_shop_' . $owner_id;
$attribute_id = wc_attribute_taxonomy_id_by_name($shop_name);
if ($attribute_id === 0) {
// create shop attribute
wc_create_attribute(array( 'slug' => $shop_name, 'name' => 'Shop' ));
$taxonomy_name = wc_attribute_taxonomy_name($shop_name);
// since attribute taxonomies are registered once on load
// we will register new attribute taxonomy here so default catalogue can be added
register_taxonomy($taxonomy_name, array('product'));
// add default catalogue option to shop
wp_insert_term( 'Default Catalogue', $taxonomy_name);
}
}
/**
* Deleted associated attribute for shop. This will effectively remove shop and all of its potential catalogues
*
* @param int $owner_id
*/
private static function _maybe_remove_shop($owner_id) {
// get corresponding attribute for shop
$attribute_id = wc_attribute_taxonomy_id_by_name('wiaas_shop_' . $owner_id);
// if shop attribute exists then remove it
if ($attribute_id > 0) {
wc_delete_attribute($attribute_id);
}
}
/**
* Generate search terms from cl extras
*
@@ -242,7 +205,7 @@ class Wiaas_Shop {
foreach ($cl_extras_per_customer as $customer_id => $visible) {
$terms[] = '_' . $owner_id . '_customer_' . $customer_id . '_' .
($visible ? 'visible' : 'hidden');
($visible ? 'visible' : 'hidden');
}
return $terms;

View File

@@ -15,7 +15,7 @@ class Wiaas_User {
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
add_filter('woocommerce_rest_prepare_customer', array(__CLASS__, 'transform_rest_customer'), 10, 3);
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'transform_jwt_token_response'), 10, 2);
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'transform_jwt_token_response'), 999, 2);
}
public static function load_user_organization() {
@@ -58,6 +58,10 @@ class Wiaas_User {
* @return mixed
*/
public static function transform_jwt_token_response($data, $user) {
if (is_wp_error($data)) {
return $data;
}
return new WP_REST_Response(array(
'token' => $data['token'],
'userInfo' => array(

View File

@@ -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);
}
}

View File

@@ -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"}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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": ""
}
]

View File

@@ -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 - &#197;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&ccedil;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&atilde;o Tom&eacute; and Pr&iacute;ncipe",
"bl": "bl - Saint Barth&eacute;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&oacute;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&oacute;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&ouml;gr&ouml;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&oacute;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&#x142;oty",
"PRB": "Transnistrian ruble",
"PYG": "Paraguayan guaran&iacute;",
"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&atilde;o Tom&eacute; and Pr&iacute;ncipe dobra",
"SYP": "Syrian pound",
"SZL": "Swazi lilangeni",
"THB": "Thai baht",
"TJS": "Tajikistani somoni",
"TMT": "Turkmenistan manat",
"TND": "Tunisian dinar",
"TOP": "Tongan pa&#x2bb;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&iacute;var",
"VND": "Vietnamese &#x111;&#x1ed3;ng",
"VUV": "Vanuatu vatu",
"WST": "Samoan t&#x101;l&#x101;",
"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": ""
}
]

View File

@@ -4,10 +4,10 @@
"title": "General",
"fields": [
{
"key": "field_5bc0965a35406",
"label": "Type",
"name": "_wiaas_product_type",
"type": "select",
"key": "field_5bceef4c9771c",
"label": "General",
"name": "_wiaas_product_general",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
@@ -16,48 +16,65 @@
"class": "",
"id": ""
},
"choices": {
"simple": "Simple",
"bundle": "Bundle",
"wiaastemplate": "Template"
},
"default_value": [],
"allow_null": 0,
"multiple": 0,
"ui": 1,
"ajax": 0,
"return_format": "value",
"placeholder": ""
},
{
"key": "field_5bbf899bba1af",
"label": "Country",
"name": "_wiaas_product_country",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_5bc0965a35406",
"operator": "!=",
"value": "wiaastemplate"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "product_country",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
"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": [
@@ -76,7 +93,7 @@
],
"menu_order": 0,
"position": "acf_after_title",
"style": "default",
"style": "seamless",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",

View File

@@ -49,7 +49,7 @@
},
{
"key": "field_5bc867c3aeafd",
"label": "Product category",
"label": "Category",
"name": "category",
"type": "taxonomy",
"instructions": "",
@@ -90,10 +90,37 @@
"load_terms": 1,
"return_format": "id",
"multiple": 0
},
{
"key": "field_5bcfcceffe617",
"label": "Country",
"name": "country",
"type": "taxonomy",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "product_country",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "product"
},
{
"param": "post_taxonomy",
"operator": "==",

View File

@@ -1,52 +0,0 @@
[
{
"key": "group_5bc845c001de4",
"title": "Package Reference",
"fields": [
{
"key": "field_5bc845dc7eed5",
"label": "Reference",
"name": "_wiaas_package_reference",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "product_tag",
"field_type": "select",
"allow_null": 0,
"add_term": 1,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "product"
},
{
"param": "post_taxonomy",
"operator": "==",
"value": "product_type:bundle"
}
]
],
"menu_order": 0,
"position": "acf_after_title",
"style": "seamless",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]

View File

@@ -6,14 +6,6 @@
* General functions for updating wiaas database to latest version
*/
/**
* Enable restricting visibility by user roles for products
*/
function wiaas_db_update_enable_product_by_user_role() {
update_option('wcj_product_by_user_role_enabled', 'yes');
}
function wiaas_db_update_setup_gravity() {
// Gravity Form settings
update_option('gform_pending_installation', false);
@@ -25,59 +17,6 @@ function wiaas_db_update_setup_gravity() {
update_option('gravityflow_pending_installation', false);
}
function wiaas_db_update_add_delivery_process_forms() {
$action_type_forms_files = array(
'delivery_action_customer_acceptance_form',
'delivery_action_schedule_meeting',
'delivery_action_validate_questionnaire_form',
'delivery_action_manual_form',
);
// Since import action will generate form with new id, we need to remember this mapping
// so we can update process delivery steps to point to correct form ids
$action_type_forms_ids_mappings = array();
$process_forms_files = array(
'delivery_process_normal_delivery_form'
);
$created_forms = array();
// import forms for delivery action types
foreach ($action_type_forms_files as $action_type_form_file) {
$form_json = file_get_contents( dirname( __FILE__ ) . "/data/delivery-forms/" . $action_type_form_file . '.json' );
$form_meta = json_decode( $form_json, true );
$form_meta = $form_meta[0];
$form_id = GFAPI::add_form($form_meta);
$created_forms[] = GFAPI::get_form($form_id);
$action_type_forms_ids_mappings[$form_meta['id']] = $form_id;
}
// import forms for delivery process
foreach ($process_forms_files as $process_form_file) {
$form_json = file_get_contents( dirname( __FILE__ ) . "/data/delivery-forms/" . $process_form_file . '.json' );
$form_meta = json_decode( $form_json, true );
$form_meta = $form_meta[0];
// update delivery steps forms ids with correct values
foreach ($form_meta['feeds']['gravityflow'] as $key => $process_step_meta) {
$process_step_target_form_id = $form_meta['feeds']['gravityflow'][$key]['meta']['target_form_id'];
$form_meta['feeds']['gravityflow'][$key]['meta']['target_form_id'] = $action_type_forms_ids_mappings[$process_step_target_form_id];
}
$form_id = GFAPI::add_form($form_meta);
$created_forms[] = GFAPI::get_form($form_id);
}
do_action('gform_forms_post_import', $created_forms);
}
function wiaas_db_update_enable_orders_access_management() {
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
@@ -88,26 +27,10 @@ function wiaas_db_update_enable_orders_access_management() {
Groups_Options::update_option(Groups_Post_Access::POST_TYPES, $post_types_option);
}
function wiaas_db_update_enable_order_numbers() {
update_option('wcj_order_numbers_enabled', 'yes');
update_option('wcj_order_number_sequential_enabled', 'no');
update_option('wcj_order_number_counter', '0');
update_option('wcj_order_number_counter_reset_enabled', 'no');
update_option('wcj_order_number_prefix', '1000000');
}
function wiaas_create_broker_access_group() {
Groups_Group::create(array(
'name' => 'Broker',
));
}
function wiaas_db_setup_exclusive_taxonomies() {
update_option('radio_button_for_taxonomies_options', array(
'taxonomies' => array(
'product_cat',
'product_country',
'wiaas_document_types',
'shop_order_project',
),
'delete' => 0,
));
@@ -145,4 +68,166 @@ function wiaas_db_setup_create_customer_commercial_lead_table() {
";
dbDelta( $sql );
}
function wiaas_create_organization_roles_capabilities() {
$roles = array( 'commercial_lead', 'supplier', 'customer', 'administrator');
foreach ($roles as $role) {
Groups_Capability::create( array( 'capability' => 'wiaas_' . $role ));
}
}
function wiaas_disable_processing_order_email_delivery() {
update_option( 'woocommerce_customer_processing_order_settings', array(
'enabled' => 'no',
'subject' => '',
'heading' => '',
'mail_type' => 'html'
) );
}
function wiaas_db_update_update_delivery_forms() {
$forms = GFAPI::get_forms();
foreach ($forms as $form) {
RGFormsModel::update_form_active($form['id'], false);
}
$created_forms = array();
$actions_forms_json = file_get_contents( dirname( __FILE__ ) . '/data/delivery-forms/delivery-action-forms.json' );
$action_forms_meta = json_decode( $actions_forms_json, true );
foreach ($action_forms_meta as $action_form_meta) {
$form_id = GFAPI::add_form($action_form_meta);
$created_forms[] = GFAPI::get_form($form_id);
}
$sample_form_json = file_get_contents( dirname( __FILE__ ) . '/data/delivery-forms/delivery-process-sample-form.json' );
$sample_form = json_decode( $sample_form_json, true );
$sample_form = $sample_form[0];
$sample_form_id = GFAPI::add_form($sample_form);
RGFormsModel::update_form_active($sample_form_id, false);
$created_forms[] = GFAPI::get_form($sample_form_id);
do_action('gform_forms_post_import', $created_forms);
}
function wiaas_db_update_add_installation_date_delivery_action_form() {
$action_form_json = file_get_contents( dirname( __FILE__ ) . '/data/delivery-forms/delivery-action-enter-installation-date.json' );
$action_form_meta = json_decode( $action_form_json, true )[0];
$action_form_id = GFAPI::add_form($action_form_meta);
do_action('gform_forms_post_import', array( GFAPI::get_form($action_form_id) ));
}
// TODO: Remove after migration has been completed
function wiaas_db_migration_fix_user_profile_addresses() {
$users = get_users();
foreach ($users as $user) {
$billing_addresses = Wiaas_Customer::get_customer_billing_addresses($user->ID);
if (! empty($billing_addresses)) {
foreach ($billing_addresses as $index => $billing_address) {
switch ($billing_address['id_country_selected']) {
case 1:
$billing_address['country_code'] = 'se';
break;
case 2:
$billing_address['country_code'] = 'dk';
break;
case 3:
$billing_address['country_code'] = 'fi';
break;
}
unset($billing_address['id_country_selected']);
$billing_addresses[$index] = $billing_address;
}
update_user_meta( $user->ID, 'billing_addresses', $billing_addresses);
}
$profile_addresses = Wiaas_Customer::get_customer_profile_addresses($user->ID);
if (! empty($profile_addresses)) {
foreach ($profile_addresses as $index => $profile_address) {
switch ($profile_address['id_country_selected']) {
case 1:
$profile_address['country_code'] = 'se';
break;
case 2:
$profile_address['country_code'] = 'dk';
break;
case 3:
$profile_address['country_code'] = 'fi';
break;
}
unset($profile_address['id_country_selected']);
$profile_addresses[$index] = $profile_address;
}
update_user_meta( $user->ID, 'profile_addresses', $profile_addresses);
}
}
}
// TODO: Remove after migration has been completed
function wiaas_db_migration_fix_countries() {
$available_country_terms = get_terms(array(
'taxonomy' => 'product_country',
'hide_empty' => false,
));
foreach($available_country_terms as $country_term) {
$code = ''; $currency = ''; $vat = '';
switch ($country_term->name) {
case 'Sweden':
$code = 'se';
$currency = 'SEK';
$vat = 9;
break;
case 'Denmark':
$code = 'dk';
$currency = 'DKK';
$vat = 9;
break;
case 'Finland':
$code = 'fi';
$currency = 'EUR';
$vat = 9;
break;
}
update_term_meta($country_term->term_id, '_wiaas_country_code', $code);
update_term_meta($country_term->term_id, '_wiaas_country_currency', $currency);
update_term_meta($country_term->term_id, '_wiaas_country_vat', $vat);
}
}

View File

@@ -10,126 +10,268 @@
function wiaas_db_update_create_default_roles() {
$roles = array(
'customer', // this role will be created by woocommerce so we do not have to create it here
'supplier',
'commercial_lead'
);
$roles = array(
'customer', // this role will be created by woocommerce so we do not have to create it here
'supplier',
'commercial_lead'
);
// remove wordpress default roles
remove_role('author');
remove_role('contributor');
remove_role('editor');
remove_role('subscriber');
// remove wordpress default roles
remove_role('author');
remove_role('contributor');
remove_role('editor');
remove_role('subscriber');
// remove woocoommerce shop manager role
remove_role('shop_manager');
// remove woocoommerce shop manager role
remove_role('shop_manager');
// Dummy gettext calls to get strings in the catalog.
/* translators: user role */
_x( 'Supplier', 'User role', 'wiaas' );
/* translators: user role */
_x( 'Commercial Lead', 'User role', 'wiaas' );
// Dummy gettext calls to get strings in the catalog.
/* translators: user role */
_x( 'Supplier', 'User role', 'wiaas' );
/* translators: user role */
_x( 'Commercial Lead', 'User role', 'wiaas' );
// Add wiaas roles
add_role(
'commercial_lead',
array(
'read' => true,
)
);
// Add wiaas roles
add_role(
'commercial_lead',
'Commercial Lead',
array(
'read' => true,
)
);
add_role(
'supplier',
array(
'read' => true,
)
);
add_role(
'supplier',
'Supplier',
array(
'read' => true,
)
);
add_role(
'user',
array(
'read' => true
)
);
add_role(
'user',
'User',
array(
'read' => true
)
);
// set default wiaas role
update_option('default_role', 'user');
// set default wiaas role
update_option('default_role', 'user');
// capabilities
// capabilities
$capabilities = array();
$capabilities = array();
$capability_types = array( 'wiaas_doc' );
$capability_types = array( 'wiaas_doc' );
foreach ( $capability_types as $capability_type ) {
foreach ( $capability_types as $capability_type ) {
$capabilities[ $capability_type ] = array(
// Post type.
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
$capabilities[ $capability_type ] = array(
// Post type.
"edit_{$capability_type}",
"read_{$capability_type}",
"delete_{$capability_type}",
"edit_{$capability_type}s",
"edit_others_{$capability_type}s",
"publish_{$capability_type}s",
"read_private_{$capability_type}s",
"delete_{$capability_type}s",
"delete_private_{$capability_type}s",
"delete_published_{$capability_type}s",
"delete_others_{$capability_type}s",
"edit_private_{$capability_type}s",
"edit_published_{$capability_type}s",
// Terms.
"manage_{$capability_type}_terms",
"edit_{$capability_type}_terms",
"delete_{$capability_type}_terms",
"assign_{$capability_type}_terms",
);
}
// Terms.
"manage_{$capability_type}_terms",
"edit_{$capability_type}_terms",
"delete_{$capability_type}_terms",
"assign_{$capability_type}_terms",
);
}
foreach ( $capabilities as $cap_group ) {
foreach ( $cap_group as $cap ) {
wp_roles()->add_cap( 'administrator', $cap );
wp_roles()->add_cap( 'commercial_lead', $cap );
}
}
foreach ( $capabilities as $cap_group ) {
foreach ( $cap_group as $cap ) {
wp_roles()->add_cap( 'administrator', $cap );
wp_roles()->add_cap( 'commercial_lead', $cap );
}
}
}
function wiaas_db_import_aam_role_settings() {
// update role settings that are imported
$content = file_get_contents( dirname( __FILE__ ) . '/data/aam-settings.json' );
// update role settings that are imported
$content = file_get_contents( dirname( __FILE__ ) . '/data/aam-settings.json' );
$importer = new AAM_Core_Importer($content);
$importer = new AAM_Core_Importer($content);
$importer->run();
$importer->run();
// update toolbar settins manually since it does not get imported
update_option('aam_toolbar_default', array (
'about' => '1',
'toolbar-wp-logo' => '1',
'wporg' => '1',
'documentation' => '1',
'support-forums' => '1',
'feedback' => '1',
'toolbar-site-name' => '0',
'view-site' => '1',
'view-store' => '1',
'toolbar-updates' => '1',
'toolbar-comments' => '1',
'toolbar-new-content' => '1',
'new-post' => '1',
'new-media' => '1',
'new-page' => '1',
'new-product' => '1',
'new-shop_order' => '1',
'new-shop_coupon' => '1',
'new-wiaas_doc' => '1',
'new-user' => '1',
'gravityforms-new-form' => '1',
)
);
// update toolbar settins manually since it does not get imported
update_option('aam_toolbar_default', array (
'about' => '1',
'toolbar-wp-logo' => '1',
'wporg' => '1',
'documentation' => '1',
'support-forums' => '1',
'feedback' => '1',
'toolbar-site-name' => '0',
'view-site' => '1',
'view-store' => '1',
'toolbar-updates' => '1',
'toolbar-comments' => '1',
'toolbar-new-content' => '1',
'new-post' => '1',
'new-media' => '1',
'new-page' => '1',
'new-product' => '1',
'new-shop_order' => '1',
'new-shop_coupon' => '1',
'new-wiaas_doc' => '1',
'new-user' => '1',
'gravityforms-new-form' => '1',
)
);
update_option('aam_menu_default', array (
'menu-edit.php' => '1',
'edit.php' => '1',
'post-new.php' => '1',
'edit-tags.php?taxonomy=category' => '1',
'edit-tags.php?taxonomy=post_tag' => '1',
'menu-edit.php?post_type=page' => '1',
'edit.php?post_type=page' => '1',
'post-new.php?post_type=page' => '1',
'menu-woocommerce' => '1',
'woocommerce' => '1',
'edit.php?post_type=shop_coupon' => '1',
'edit-tags.php?taxonomy=shop_order_project' => '1',
'wc-reports' => '1',
'wc-settings' => '1',
'wc-status' => '1',
'wc-addons' => '1',
'wcj-tools' => '1',
'admin.php?page=wc-settings&tab=jetpack' => '1',
'menu-themes.php' => '1',
'themes.php' => '1',
'customize.php' => '1',
'widgets.php' => '1',
'nav-menus.php' => '1',
'custom-header' => '1',
'menu-tools.php' => '1',
'tools.php' => '1',
'import.php' => '1',
'export.php' => '1',
'export_personal_data' => '1',
'remove_personal_data' => '1',
'menu-options-general.php' => '1',
'options-general.php' => '1',
'options-writing.php' => '1',
'options-reading.php' => '1',
'options-discussion.php' => '1',
'options-media.php' => '1',
'options-permalink.php' => '1',
'privacy.php' => '1',
'radio-buttons-for-taxonomies' => '1',
'sendgrid-settings' => '1',
'menu-plugins.php' => '1',
'plugins.php' => '1',
'plugin-install.php' => '1',
'menu-groups-admin' => '1',
'groups-admin' => '1',
'groups-admin-capabilities' => '1',
'groups-admin-options' => '1',
'groups-admin-add-ons' => '1',
)
);
update_option('aam-utilities', array(
'core.settings.getStarted' => '0',
'ui.settings.renderAccessActionLink' => '0',
'core.settings.secureLogin' => '0',
'core.settings.xmlrpc' => '0',
'core.settings.cron' => '0',
'core.settings.extensionSupport' => '0',
'ui.settings.renderAccessMetabox' => '0',
'core.settings.apiAccessControl' => '0',
'core.settings.frontendAccessControl' => '0',
));
update_option('aam_menu_role_administrator', array(
'menu-edit.php' => '1',
'edit.php' => '1',
'post-new.php' => '1',
'edit-tags.php?taxonomy=category' => '1',
'edit-tags.php?taxonomy=post_tag' => '1',
'menu-edit.php?post_type=page' => '1',
'edit.php?post_type=page' => '1',
'post-new.php?post_type=page' => '1',
'menu-woocommerce' => '1',
'woocommerce' => '1',
'edit.php?post_type=shop_coupon' => '1',
'wc-reports' => '1',
'wc-settings' => '1',
'wc-status' => '1',
'wc-addons' => '1',
'wcj-tools' => '1',
'admin.php?page=wc-settings&tab=jetpack' => '1',
'menu-themes.php' => '1',
'themes.php' => '1',
'customize.php' => '1',
'widgets.php' => '1',
'nav-menus.php' => '1',
'custom-header' => '1',
'menu-tools.php' => '1',
'tools.php' => '1',
'import.php' => '1',
'export.php' => '1',
'export_personal_data' => '1',
'remove_personal_data' => '1',
'menu-options-general.php' => '1',
'options-general.php' => '1',
'options-writing.php' => '1',
'options-reading.php' => '1',
'options-discussion.php' => '1',
'options-media.php' => '1',
'options-permalink.php' => '1',
'privacy.php' => '1',
'radio-buttons-for-taxonomies' => '1',
'sendgrid-settings' => '1',
'menu-plugins.php' => '1',
'plugins.php' => '1',
'plugin-install.php' => '1',
'menu-groups-admin' => '1',
'groups-admin' => '1',
'groups-admin-capabilities' => '1',
'groups-admin-options' => '1',
'groups-admin-add-ons' => '1',
'menu-edit-comments.php' => '1',
));
update_option('aam_metabox_default', array(
'dashboard' =>
array (
'rg_forms_dashboard' => '1',
'dashboard_quick_press' => '1',
'dashboard_primary' => '1',
'woocommerce_dashboard_status' => '1',
'dashboard_activity' => '1',
),
));
update_option('aam_metabox_role_administrator', array(
'dashboard' =>
array (
'rg_forms_dashboard' => '1',
'dashboard_quick_press' => '1',
'dashboard_primary' => '1',
'woocommerce_dashboard_status' => '1',
'dashboard_activity' => '1',
'dashboard_right_now' => '1',
),
));
}
function wiaas_db_update_update_commercial_lead_capabilities() {
@@ -160,23 +302,25 @@ function wiaas_db_update_update_supplier_capabilities() {
function wiaas_db_update_update_admin_capabilities() {
wp_roles()->add_cap( 'administrator', 'create_products' );
wp_roles()->add_cap( 'administrator', 'manage_wiaas_order_projects' );
}
function wiaas_create_role_access_groups() {
function wiaas_admin_create_role_access_groups() {
Groups_Group::create(array(
'name' => 'admin',
));
}
Groups_Group::create(array(
'name' => 'commercial_lead',
));
function wiaas_db_update_update_supplier_order_capabilities() {
// add supplier role to view orders
wp_roles()->add_cap( 'supplier', 'edit_shop_orders' );
}
Groups_Group::create(array(
'name' => 'supplier',
));
function wiaas_db_update_enable_workflow_inbox_for_roles() {
// add workflow inbox for supplier
wp_roles()->add_cap( 'supplier', 'gravityflow_inbox' );
// add workflow inbox for commercial lead
wp_roles()->add_cap( 'commercial_lead', 'gravityflow_inbox' );
Groups_Group::create(array(
'name' => 'customer',
));
}

View File

@@ -18,9 +18,9 @@ function wiaas_db_update_add_user_organization_ui_fields() {
_wiaas_import_field_group($ui_json);
}
function wiaas_db_update_add_reference_ui_field() {
function wiaas_db_update_add_bundle_properties_ui_field() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-reference.json' );
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-bundle-properties.json' );
$ui_json = json_decode( $ui_json, true );
@@ -45,6 +45,15 @@ function wiaas_db_update_add_product_properties_ui_fields() {
_wiaas_import_field_group($ui_json);
}
function wiaas_db_update_add_country_settings_ui_fields() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-country-settings.json' );
$ui_json = json_decode( $ui_json, true );
_wiaas_import_field_group($ui_json);
}
// private helper function

View File

@@ -147,11 +147,27 @@ class Wiaas_Shop_DB {
$shops = array_map(function($result_row) {
return array(
'owner_id' => $result_row->shop_owner_id,
'owner_id' => absint($result_row->shop_owner_id),
'order_type' => $result_row->order_type
);
}, $results);
return $shops;
}
/**
* Remove shop
*
* @param int $owner_id
*/
public static function remove_shop($owner_id) {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->prefix}wiaas_shop_customer_relationships
WHERE shop_owner_id = %d",
$owner_id )
);
}
}

View File

@@ -0,0 +1,423 @@
<?php
/**
* Class Wiaas_Delivery_Process_Action
*/
class Wiaas_Delivery_Process_Action {
/**
* Check if form is delivery process action form
*
* @param $form
*
* @return bool
*/
public static function is_action_form($form) {
$delivery_settings = rgar($form, 'wiaas_delivery_process');
return ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action';
}
/**
* Retrieve action form for step
*
* @param Wiaas_Delivery_Process_Step $step
*
* @return mixed|null
*/
public static function get_process_step_action_form($step) {
if (empty($step->target_form_id)) {
return null;
}
return GFAPI::get_form($step->target_form_id);
}
/**
* Get action code for delivery process step form
*
* Action code is used for implementing specific logic for step form
*
* @param Wiaas_Delivery_Process_Step $step
*
* @return string
*/
public static function get_process_step_action_form_action_code($step) {
$action_form = self::get_process_step_action_form($step);
if (empty($action_form)) {
return 'manual';
}
$delivery_settings = rgar($action_form, 'wiaas_delivery_process');
return empty($delivery_settings) ? 'manual' : $delivery_settings['delivery_action_code'];
}
/**
* Check if delivery process step has customer acceptance action form
*
* @param Wiaas_Delivery_Process_Step $step
*
* @return bool
*/
public static function process_step_has_customer_acceptance_action($step) {
return self::get_process_step_action_form_action_code($step) === 'customer-acceptance';
}
/**
* Check if delivery process step has customer validate action form
*
* @param Wiaas_Delivery_Process_Step $step
*
* @return bool
*/
public static function process_step_has_customer_validate_questionnaires_action($step) {
return self::get_process_step_action_form_action_code($step) === 'validate-questionnaire';
}
/**
* @param Wiaas_Delivery_Process_Step $step
*
* @return array|WP_Error
*/
public static function get_process_step_action_entries(Wiaas_Delivery_Process_Step $step) {
$action_form = self::get_process_step_action_form($step);
if (!$action_form) {
return array();
}
$search_criteria = array(
'field_filters' => array(
array( 'key' => 'wiaas_delivery_process_id',
'value' => $step->get_entry_id()
),
),
);
$sorting = array( 'key' => 'date_created', 'direction' => 'DESC' );
return GFAPI::get_entries( $action_form, $search_criteria, $sorting );
}
/**
* Retrieve forms that will be used as possible action forms
*
* @return array
*/
public static function get_action_forms() {
$forms = GFAPI::get_forms();
$action_forms = array();
foreach ( $forms as $form ) {
$delivery_settings = rgar($form, 'wiaas_delivery_process');
if ( ! empty($delivery_settings) && $delivery_settings['delivery_form_type'] === 'action'){
$action_forms[] = $form;
}
}
return $action_forms;
}
/**
* Complete current workflow step for action form
*
* @param int $action_entry_id
*/
public static function complete_action_step($action_entry_id) {
$action_entry = GFAPI::get_entry($action_entry_id);
$action_form = GFAPI::get_form($action_entry['form_id']);
$workflow = new Gravity_Flow_API($action_form['id']);
$current_step = $workflow->get_current_step($action_entry);
if ( $current_step ) {
$new_status = $current_step->get_type() === 'approval' ? 'approved' : 'complete';
$assignees = $current_step->get_assignees();
foreach ($assignees as $assignee) {
$current_step->process_assignee_status($assignee, $new_status, $action_form);
}
}
gravity_flow()->process_workflow($action_form, $action_entry['id']);
}
/**
* Upload customer questionnaire document
*
* @param int $action_entry_id
*/
public static function upload_customer_questionnaire($action_entry_id) {
$action_entry = GFAPI::get_entry($action_entry_id);
$document_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'wiaas_order_bundle_document')[0];
$new_file = $document_field->get_single_file_value($action_entry['form_id'], 'file');
$action_entry[$document_field->id] = $new_file;
GFAPI::update_entry($action_entry);
self::complete_action_step($action_entry_id);
}
/**
* Check if customer uploaded acceptance document
*
* @param int $action_entry_id
*
* @return bool
*/
public static function is_customer_acceptance_uploaded($action_entry_id) {
$action_entry = GFAPI::get_entry($action_entry_id);
$action_form = GFAPI::get_form($action_entry['form_id']);
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_document')[0];
return ! empty( $action_entry[$acceptance_documents_field->id]);
}
/**
* Update acceptance status for order
*
* @param int $action_entry_id
* @param $new_status
* @param $reason
*/
public static function update_customer_acceptance_status($action_entry_id, $new_status, $reason) {
$action_entry = GFAPI::get_entry($action_entry_id);
$action_form = GFAPI::get_form($action_entry['form_id']);
$acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
$decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
$action_entry[$acceptance_field->id] = $new_status;
$action_entry[$decline_reason_field->id] = $reason;
GFAPI::update_entry($action_entry);
if ($new_status === 'accept') {
Wiaas_Delivery_Process_Action::complete_action_step($action_entry['id']);
}
}
/**
* Upload customer acceptance document for order
*
* @param int $action_entry_id
*
* @return bool
*/
public static function upload_customer_acceptance_document($action_entry_id) {
$action_entry = GFAPI::get_entry($action_entry_id);
$action_form = GFAPI::get_form($action_entry['form_id']);
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_document')[0];
$old_value = $action_entry[$acceptance_documents_field->id];
$value = $acceptance_documents_field->get_single_file_value($action_form['id'], 'file');
if ($acceptance_documents_field->multipleFiles ) {
$value = array( $value );
$old_value = json_decode( $old_value );
if (! empty($old_value)) {
$old_value = is_array( $old_value ) ? $old_value : array( $old_value );
$value = array_merge( $value, $old_value );
}
$value = json_encode( $value );
}
$action_entry[$acceptance_documents_field->id] = $value;
$result = GFAPI::update_entry($action_entry);
// complete step if current step is customer acceptance user input
$workflow = new Gravity_Flow_API($action_form['id']);
$current_step = $workflow->get_current_step($action_entry);
if ($current_step->get_type() === 'user_input' && ! is_wp_error($result)) {
Wiaas_Delivery_Process_Action::complete_action_step($action_entry['id']);
}
return ! is_wp_error($result);
}
/**
* Collect customer acceptance action data
*
* @param int $action_entry_id
*
* @return array
*/
public static function get_customer_acceptance_action_data($action_entry_id) {
$action_entry = GFAPI::get_entry($action_entry_id);
$action_form = GFAPI::get_form($action_entry['form_id']);
$acceptance_documents_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_document')[0];
$acceptance_field = GFCommon::get_fields_by_type($action_form, 'radio')[0];
$decline_reason_field = GFCommon::get_fields_by_type($action_form, 'textarea')[0];
$expiration_date_field = GFCommon::get_fields_by_type($action_form, 'date')[0];
$file_paths = json_decode($action_entry[$acceptance_documents_field->id]);
$documents = array();
foreach ($file_paths as $file_path) {
$info = pathinfo( $file_path );
$documents[] = array(
'name' => $info['basename'],
'extension' => $info['extension'],
'url' => $acceptance_documents_field->get_download_url( $file_path, true )
);
}
$status = 0;
if ($action_entry[$acceptance_field->id] === 'accept') {
$status = 1;
}
if ($action_entry[$acceptance_field->id] === 'decline') {
$status = -1;
}
return array(
'action_id' => $action_entry['id'],
'documents' => $documents,
'expiration' => $action_entry[$expiration_date_field->id],
'decline_reason' => $action_entry[$decline_reason_field->id],
'status' => $status
);
}
/**
* Get customer validate questionnaires action data
*
* @param int $action_entry_id
*
* @return array|null
*/
public static function get_customer_validate_questionnaires_action_data($action_entry_id) {
$action_entry = GFAPI::get_entry($action_entry_id);
$action_form = GFAPI::get_form($action_entry['form_id']);
$order_id = $action_entry['wiaas_delivery_order_id'];
$order = wc_get_order($order_id);
// we need to collect document, bundle id and current status
$bundle_item_id = null; $status = null;
$bundle_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle')[0];
$bundle_item_id = absint(explode('|', $action_entry[$bundle_field->id])[1]);
if (empty($bundle_item_id)) {
return null;
}
$document_field = GFCommon::get_fields_by_type($action_form, 'wiaas_order_bundle_document')[0];
$file_path = $action_entry[$document_field->id];
$info = pathinfo( $action_entry[$document_field->id] );
$document = array(
'name' => $info['basename'],
'extension' => $info['extension'],
'url' => $document_field->get_download_url( $file_path, true )
);
$discussion_field = GFCommon::get_fields_by_type(GFAPI::get_form($action_entry['form_id']), 'workflow_discussion')[0];
$discussion_items = json_decode($action_entry[$discussion_field->id], ARRAY_A);
$formatted_comments = array();
if (is_array($discussion_items)) {
foreach ($discussion_items as $item) {
$formatted = $discussion_field->format_discussion_item( $item, 'text', $action_entry_id );
$formatted = explode("\n", $formatted);
$formatted_comments[] = array(
'header' => $formatted[0],
'value' => $formatted[1]
);
}
}
$action_workflow_api = new Gravity_Flow_API($action_form['id']);
$action_step = $action_workflow_api->get_current_step($action_entry);
// if completed it means that document got validated
$status = 'validated';
if (! empty($action_step)) {
$is_assignee = $action_step->is_assignee($action_step->get_current_assignee_key());
if ($is_assignee) {
// if customer is assignee it means it is his turn to upload changed version of document
// which means it was rejected
$status = 'invalid';
} else {
// if customer is not assignee it means administrator is still reviewing document
$status = 'not-validated';
}
}
return array(
'item_id' => $bundle_item_id,
'order_id' =>$order->get_id(),
'action_id' => $action_entry['id'],
'document' => $document,
'status' => $status,
'comments' => $formatted_comments
);
}
}

View File

@@ -0,0 +1,234 @@
<?php
if (! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
private static $_instance = null;
protected $_slug = 'wiaas_delivery_process';
protected $_title = 'Delivery Settings';
protected $_short_title = 'Delivery Settings';
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new Wiaas_Delivery_Process_Addon();
}
return self::$_instance;
}
public function init() {
parent::init();
add_filter( 'gform_enqueue_scripts', array( $this, 'filter_gform_enqueue_scripts' ) );
}
public function filter_gform_enqueue_scripts( ) {
wp_enqueue_script( 'gform_datepicker_init' );
}
/**
* Extends Gravity Form entry metadata with 'wiaas_delivery_process_id'
*
* @param array $entry_meta
* @param int $form_id
*
* @return array
*/
public function get_entry_meta( $entry_meta, $form_id ) {
$entry_meta[ 'wiaas_delivery_process_id' ] = array(
'label' => 'Wiaas Delivery Process Id',
'is_numeric' => true,
'update_entry_meta_callback' => array( __CLASS__, 'update_entry_delivery_process_id' ),
'is_default_column' => false, // this column will be displayed by default on the entry list
'filter' => array(
'operators' => array( 'is' ),
),
);
$entry_meta[ 'wiaas_delivery_order_id' ] = array(
'label' => 'Wiaas Delivery Process Order Id',
'is_numeric' => true,
'update_entry_meta_callback' => null,
'is_default_column' => false, // this column will be displayed by default on the entry list
'filter' => array(
'operators' => array( 'is' ),
),
);
$entry_meta[ 'wiaas_delivery_step_name' ] = array(
'label' => 'Wiaas Delivery Step name',
'is_numeric' => false,
'update_entry_meta_callback' => null,
'is_default_column' => false, // this column will be displayed by default on the entry list
'filter' => array(
'operators' => array( 'is' ),
),
);
return $entry_meta;
}
public static function update_entry_delivery_process_id($key, $entry, $form) {
if ( isset( $_REQUEST['wiaas_delivery_process_id'] ) ) {
return absint( $_REQUEST['wiaas_delivery_process_id'] );
}
if ( isset( $entry[ $key ] ) ) {
return $entry[ $key ];
}
return '';
}
public function scripts() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
$scripts = array(
array(
'handle' => 'wiaas_form_editor_js',
'src' => $plugin_url . '/assets/js/wiaas-form-editor.js',
'enqueue' => array(
array(
'admin_page' => array('form_editor'),
),
),
)
);
return array_merge( parent::scripts(), $scripts );
}
/**
* Add settings menu for form delivery process
*
* @param $tabs
* @param $form_id
*
* @return array
*/
public function add_form_settings_menu( $tabs, $form_id ) {
$tabs[] = array(
'name' => $this->_slug,
'label' => esc_html__( 'Delivery Settings', 'wiaas' ),
'query' => array( 'fid' => null )
);
return $tabs;
}
/**
* Add settings field for delivery process settings menu
*
* @param $form
*
* @return array
*/
public function form_settings_fields($form) {
return array(
array(
'title' => esc_html__( 'Delivery Process', 'wiaas' ),
'fields' => array(
array(
'name' => 'delivery_process',
'label' => esc_html__( 'Delivery Form Type', 'wiaas' ),
'type' => 'delivery_process',
)
)
)
);
}
public function settings_delivery_process() {
$this->settings_select(array(
'name' => 'delivery_form_type',
'choices' => array(
array( 'value' => 'process', 'label' => 'Process Form' ),
array( 'value' => 'action', 'label' => 'Action Form' ),
),
'after_select' => '<p class="description"> Choose if this form will be used as process form or action form.</p>' .
'<p class="description"> <strong>Process form</strong> defines order delivery process workflow.</p>' .
'<p class="description"> <strong>Action form</strong> defines custom order data that is collected from delivery process participants.</p>'
));
?>
<br /> <br /> <br />
<?php
$settings = $this->get_current_settings();
if ($settings['delivery_form_type'] !== 'process') {
$this->settings_select(array(
'name' => 'delivery_action_code',
'choices' => array(
array( 'value' => '', 'label' => 'Select action code ...' ),
array( 'value' => 'customer-acceptance', 'label' => 'Customer acceptance' ),
array( 'value' => 'validate-questionnaire', 'label' => 'Validate Questionnaire' ),
array( 'value' => 'schedule-meeting', 'label' => 'Schedule meeting' ),
),
'after_select' => '<p class="description"> Choose action code for action form.</p>'
));
$this->settings_checkbox_and_select(array(
'checkbox' => array(
'label' => esc_html__( 'Automatic', 'wiaas' ),
'name' => 'automatic_action_entries_enabled',
'default_value' => '0',
),
'select' => array(
'name' => 'automatic_action_entries_type',
'choices' => array(
array(
'value' => 'single',
'label' => esc_html__( 'Single entry', 'wiaas' ),
),
array(
'value' => 'bundle',
'label' => esc_html__( 'Entry per bundle', 'wiaas' ),
)
),
'after_select' => '<p class="description">Automatic entries can be created once per order or per every bundle in order.</p>' .
'<p class="description">Automatic entry will not be created if any required field cannot be populated.</p>',
)
));
return;
}
$countries = Wiaas_Countries::get_available_countries();
$countries_choices = array();
foreach ($countries as $country) {
$countries_choices[] = array( 'value' => $country['code'] , 'label' => $country['name'] );
}
$this->settings_select(array(
'name' => 'delivery_country',
'choices' => $countries_choices,
'after_select' => '<p class="description"> Choose country for which this process is defined.</p>'
));
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* Handle organization and order level assignment to delivery process step.
*
* Currently Gravity Flow enables assignment of roles to step, but these roles are not bounded to organization level
* so cannot be used in that form for our delivery processes.
*
* This will enable delivery process step to be assigned to order admin, order seller, order customer or
* single order supplier organization.
*
*
* Class Wiaas_Delivery_Process_Step_Assignee
*/
class Wiaas_Delivery_Process_Step_Assignee {
public static function init() {
add_filter('gravityflow_assignee_choices', array (__CLASS__, 'filter_delivery_process_step_assignee_choices'));
add_filter('gravityflow_step_assignees', array (__CLASS__, 'maybe_handle_order_organization_assignees'), 10, 2);
}
/**
* Allow only order specific organization roles and fields as choices for delivery process step assignee
*
* @param array $old_choices
*
* @return array
*/
public static function filter_delivery_process_step_assignee_choices($old_choices) {
$choices = array(
$choices[] = array(
'label' => __( 'Order', 'wiaas' ),
'choices' => array(
array(
'value' => 'role|administrator', // allow global administrator role here since it is only one
'label' => __('Administrator', 'wiaas')
)
),
)
);
// add administrator users
$args = array(
'number' => 1000,
'orderby' => 'display_name',
'role' => 'administrator'
);
$accounts = get_users( $args );
$account_choices = array();
foreach ( $accounts as $account ) {
$account_choices[] = array( 'value' => 'user_id|' . $account->ID, 'label' => $account->display_name );
}
$choices[] = array(
'label' => __( 'Users', 'gravityflow' ),
'choices' => $account_choices,
);
// append field choices
foreach ($old_choices as $old_choice) {
if ($old_choice['label'] === 'Fields') {
$choices[] = $old_choice;
break;
}
}
return $choices;
}
/**
* Handle order level assignees for delivery process step
*
* @param $assignees
*
* @param Gravity_Flow_Step $step
*
* @return array
*/
public static function maybe_handle_order_organization_assignees($assignees, Gravity_Flow_Step $step) {
$mapped_assignees = array();
$order_id = self::_get_order_id_for_step($step);
$order = wc_get_order($order_id);
foreach ($assignees as $assignee) {
/**
* Handle step assignee for installation company field
*/
if (strpos($assignee->get_type(), 'wiaas_installation_') !== false) {
$item_id = $assignee->get_id();
$item = $order->get_item($item_id);
$organization_id = $item['wiaas_supplier_organization_id'];
$user_ids = wiaas_get_organization_user_ids($organization_id);
if (empty($user_ids)) {
continue;
}
$user_id = $user_ids[0];
$mapped_assignees[] = $step->get_assignee( array(
'id' => $user_id,
'type' => 'user_id',
'editable_fields' => $assignee->get_editable_fields()
) );
continue;
}
/**
* Handle step assignee for order role
*/
if ($assignee->get_type() === 'wiaas_order_role') {
$order_role = $assignee->get_id();
// Assign step to order customer
if ($order_role === 'customer') {
$customer_user_id = $order->get_customer_id();
// for now assign only customer that create order
// check if all customer organization users should be able to see order step
$mapped_assignees[] = $step->get_assignee( array(
'id' => $customer_user_id,
'type' => 'user_id',
'editable_fields' => $assignee->get_editable_fields()
) );
continue;
}
}
$mapped_assignees[] = $assignee;
}
return $mapped_assignees;
}
/**
* Retrieve order id for delivery process step
*
* @param Gravity_Flow_Step $step
*
* @return bool|int Order id on success, false if step does not have associated order id
*
*/
private static function _get_order_id_for_step(Gravity_Flow_Step $step) {
$entry = $step->get_entry();
// if order is present in entry metadata use that value
if (! empty($entry['wiaas_delivery_order_id'])) {
return absint($entry['wiaas_delivery_order_id']);
}
// try getting order id from order field
$form = GFAPI::get_form($entry['form_id']);
$order_fields = GFCommon::get_fields_by_type($form, array( 'wiaas_order'));
if (! empty($order_fields)) {
$order_field = $order_fields[0]; // there should only be one order field per entry
return absint($entry[$order_field->id]);
}
return false;
}
}
Wiaas_Delivery_Process_Step_Assignee::init();

View File

@@ -7,30 +7,12 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
* @var string
*/
public $_step_type = 'wiaas_delivery_step';
private static $delivery_action_form_title_prefix = 'DELIVERY ACTION TYPE:';
private static $delivery_action_types = array(
'DELIVERY ACTION TYPE: Customer acceptance' => 'customer-acceptance',
'DELIVERY ACTION TYPE: Validate Questionnaire' => 'validate-questionnaire',
'DELIVERY ACTION TYPE: Manual' => 'manual',
'DELIVERY ACTION TYPE: Schedule meeting' => 'schedule-meeting'
);
public static function get_delivery_action_types() {
return array_keys(self::$delivery_action_types);
}
public static function get_delivery_action_type_prefix() {
return self::$delivery_action_form_title_prefix;
}
/**
* Returns label for Wiass Delivery Process Step
* @return string
*/
public function get_label() {
return esc_html__( 'Wiaas Delivery Step', 'wiaas' );
return esc_html__( 'Delivery Step', 'wiaas' );
}
/**
@@ -41,12 +23,12 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
$settings_api = $this->get_common_settings_api();
$forms = $this->get_target_forms_choices();
$forms = Wiaas_Delivery_Process_Action::get_action_forms();
$form_choices[] = array( 'label' => esc_html__( 'Select a Form', 'wiaas' ), 'value' => '' );
foreach ( $forms as $form ) {
$form_choices[] = array( 'label' => $form->title, 'value' => $form->id );
}
$form_choices[] = array( 'label' => $form['title'], 'value' => $form['id'] );
}
$settings = array(
'title' => esc_html__( 'Wiaas Delivery Step', 'wiaas' ),
@@ -71,18 +53,71 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
'type' => 'select',
'onchange' => "jQuery(this).closest('form').submit();",
'choices' => $form_choices,
),
)
),
);
return $settings;
}
public function start() {
parent::start();
$this->update_step_status('pending');
return false;
}
public function evaluate_status() {
return $this->get_status();
}
public function get_status_label($status) {
$label = parent::get_status_label($status);
if (empty($label)) {
$label = __('Not started', 'wiaas');
}
return $label;
}
/**
* Process Wiass Delivery Process Step
* Update status
*
* @param bool $status
*/
public function update_step_status($status = false) {
/**
* If status is being updated after manual step completion ('Next Step' or 'Previous Step') change default
* behavior of settings status to cancelled if manual action is sending flow to next step.
* Instead of default cancelled status set complete status for this step.
*/
if ($status === 'cancelled' && $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' )) {
list( $base_admin_action, $step_id ) = rgexplode( '|', $admin_action, 2 );
$next_step = gravity_flow()->get_next_step($this, $this->get_entry(), $this->get_form());
// going to next step
if ($base_admin_action === 'send_to_step' && $next_step && $next_step->get_id() == $step_id) {
$status = 'complete';
}
}
parent::update_step_status($status);
}
/**
*
* Process Wiaas Delivery Process Step
*
*
* @return bool
* @return bool We will always return false because step will be completed only by manual user action
*/
function process() {
@@ -90,81 +125,77 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
$entry = $this->get_entry();
$target_form = GFAPI::get_form( $this->target_form_id );
# if target form is not valid just finish the step
# if target form is not set we are done
if (!$target_form) {
return true;
// return false since we wait for admin to process the step
return false;
}
# create new entry for target form with populated value for customer-id from parent entry
$new_entry = array(
'form_id' => $this->target_form_id,
'wiaas_delivery_process_id' => $this->get_entry_id(),
'wiaas_delivery_order_id' => $entry['wiaas_delivery_order_id'],
'wiaas_delivery_step_name' => $this->get_name(),
);
$delivery_settings = rgar($target_form, 'wiaas_delivery_process');
$customer_id_value = null;
if (! $delivery_settings['automatic_action_entries_enabled']) {
if ( is_array( $form['fields'] ) ) {
foreach ( $form['fields'] as $field ) {
if (GFCommon::get_label( $field ) === 'customer-id') {
$customer_id_value = $entry[$field->id];
break;
}
}
return false;
}
$action_entries_ids = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids');
// if action entries present this step is reprocessing and we should not be creating new action entries
if (! empty($action_entries_ids)) {
// return false since we wait for admin to process the step
return false;
}
if ( is_array( $target_form['fields'] ) ) {
foreach ( $target_form['fields'] as $field ) {
if (GFCommon::get_label( $field ) === 'customer-id') {
$new_entry[$field->id] = $customer_id_value;
break;
}
}
// create new entries for step action forms
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
$order_id = empty($order_field) ? null : absint($entry[$order_field->id]);
// if process has not order we cannot create actions
if (empty($order_id)) {
// return false since we wait for admin to process the step
return false;
}
$entry_id = GFAPI::add_entry( $new_entry );
if ( is_wp_error( $entry_id ) ) {
$this->log_debug( __METHOD__ .'(): failed to add entry' );
} else {
// store entry id
gform_update_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id', $entry_id);
$delivery_settings = rgar($target_form, 'wiaas_delivery_process');
switch ($delivery_settings['automatic_action_entries_type']) {
case 'single':
$action_entries_ids = $this->_create_single_action_entry($target_form, $order_id);
break;
case 'bundle':
$action_entries_ids = $this->_create_per_bundle_action_entries($target_form, $order_id);
}
gform_update_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids', $action_entries_ids);
$note = $this->get_name() . ': ' . esc_html__( 'started.', 'wiaas' );
$this->add_note( $note );
# return false since we wait for workflow of target entry to be complete first
// return false since we wait for admin to process the step
return false;
}
/**
* Evaluates current step status based on target form entry status
*
* If target form entry has associated workflow current step will complete its status
* only when target form entry workflow is completed
* @return string
*/
public function status_evaluation() {
public function workflow_detail_box($form, $args) {
parent::workflow_detail_box($form, $args);
# retrieve target form entry to check its workflow status
$target_form_entry = $this->get_target_form_entry();
$target_form = GFAPI::get_form( $this->target_form_id );
# if there is no target form entry just complete the step
if(!$target_form_entry) {
return 'complete';
if (empty( $target_form)) {
return;
}
# retrieve target form entry workflow status
$api = new Gravity_Flow_API( $this->target_form_id );
$status = $api->get_status($target_form_entry);
?>
<h4>Step: <?php echo $this->get_name() ?></h4>
<h4>Action: <?php echo $target_form['title'] ?></h4>
<?php
# status is complete only if target entry flow is complete
return $status === 'complete' || $status === 'approved' ? 'complete' : 'pending';
}
/**
* Expands step entry with additional metadata to track created target entry id
* Expands step entry with additional metadata to track created target actions entries id
*
* @param array $entry_meta
* @param int $form_id
*
@@ -172,79 +203,94 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
*/
public function get_entry_meta($entry_meta, $form_id) {
if ($form_id === $this->get_form_id()) {
$entry_meta['wiaas_delivery_step_' . $this->get_id() .'_entry_id'] = null;
$entry_meta['wiaas_delivery_step_' . $this->get_id() . '_action_entry_ids'] = array();
}
return $entry_meta;
}
/**
* Retrieves forms that are valid options for delivery step action
*
* PRIVATE
*
*/
/**
* Create action entry to trigger subworkflow
* @param $target_form
* @param $order_id
*
* @return array
*/
public function get_target_forms_choices() {
return GFFormsModel::search_forms(self::$delivery_action_form_title_prefix, true);
private function _create_single_action_entry($target_form, $order_id) {
$action_entries_ids = array();
$new_entry = Wiaas_Order_Fields::map_order_to_entry($order_id, $target_form);
if (empty($new_entry)) {
// entry cannot be created
return $action_entries_ids;
}
$new_entry['form_id'] = $target_form['id'];
$new_entry['wiaas_delivery_process_id'] = $this->get_entry_id();
$new_entry['wiaas_delivery_order_id'] = $order_id;
$entry_id = GFAPI::add_entry( $new_entry );
if ( is_wp_error( $entry_id ) ) {
$this->log_debug( __METHOD__ .'(): failed to add entry' );
} else {
// store entry id
$action_entries_ids[] = $entry_id;
}
return $action_entries_ids;
}
/**
* Retrieves delivery action type that is executed with this step
* @return string
* Create action form entries for every bundle in order to trigger subworkflows
*
* @param $target_form
* @param $order_id
*
* @return array
*/
public function get_delivery_action_type() {
$target_form = GFAPI::get_form( $this->target_form_id );
return self::$delivery_action_types[$target_form['title']];
}
private function _create_per_bundle_action_entries($target_form, $order_id) {
public function get_target_actual_date() {
$target_entry = $this->get_target_form_entry();
$target_form = GFAPI::get_form( $this->target_form_id );
$action_entries_ids = array();
if (!is_wp_error($target_entry) && is_array($target_form['fields'])) {
foreach ( $target_form['fields'] as $field ) {
if (GFCommon::get_label( $field ) === 'Actual Date') {
return $target_entry[$field->id];
}
$bundle_items = wiaas_get_order_standard_bundle_items($order_id);
foreach ($bundle_items as $item) {
$new_entry = Wiaas_Order_Fields::map_order_to_entry($order_id, $target_form, $item->get_id());
if (empty($new_entry)) {
// entry cannot be created
continue;
}
$new_entry['form_id'] = $target_form['id'];
$new_entry['wiaas_delivery_process_id'] = $this->get_entry_id();
$new_entry['wiaas_delivery_order_id'] = $order_id;
$entry_id = GFAPI::add_entry( $new_entry );
if ( is_wp_error( $entry_id ) ) {
$this->log_debug( __METHOD__ .'(): failed to add entry' );
} else {
// store entry id
$action_entries_ids[] = $entry_id;
}
}
return null;
}
public function get_target_step_comments() {
$notes = RGFormsModel::get_lead_notes( $this->get_target_form_entry_id() );
$comments = array();
foreach ( $notes as $key => $note ) {
if ( $note->note_type !== 'gravityflow' ) {
$comments[] = array(
'date' => $note->date_created,
'text' => $note->value,
'user' => $note->user_name
);
}
}
return $comments;
}
/**
* Retrieves target form entry created when step was started
* @return array|null
*/
public function get_target_form_entry() {
$entry = GFAPI::get_entry($this->get_target_form_entry_id());
if(is_wp_error($entry)) {
return null;
}
return $entry;
}
/**
* Retrieves target form entry id created when step was started
* @return int
*/
public function get_target_form_entry_id() {
$value = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id');
return absint($value);
return $action_entries_ids;
}
}

View File

@@ -0,0 +1,73 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Bundle_Document extends GF_Field_FileUpload {
public $type ='wiaas_order_bundle_document';
public $wiaasDocTypeFilter = 'config';
public function get_form_editor_field_settings() {
return array(
'wiaas_doc_type_filter',
'multiple_files_setting',
'conditional_logic_field_setting',
'error_message_setting',
'label_setting',
'label_placement_setting',
'admin_label_setting',
'rules_setting',
'file_extensions_setting',
'file_size_setting',
'visibility_setting',
'description_setting',
'css_class_setting',
);
}
public function get_input_type() {
return 'fileupload';
}
public function add_button( $field_groups ) {
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
return parent::add_button( $field_groups );
}
public function get_form_editor_button() {
return array(
'group' => 'wiaas_order_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_form_editor_field_title() {
return esc_attr__( 'Bundle Document', 'wiaas' );
}
public function get_download_url( $file, $force_download = false ) {
$upload_root = GFFormsModel::get_upload_url( $this->formId );
$upload_root = trailingslashit( $upload_root );
// handle download for order documents not uploaded by gravity forms
if ( strpos( $file, $upload_root ) === false ) {
return admin_url() . '?gf-wiaas-order-doc=' . urlencode($file);
}
return parent::get_download_url( $file, $force_download );
}
public function sanitize_settings() {
parent::sanitize_settings();
$this->wiaasDocTypeFilter = sanitize_key($this->wiaasDocTypeFilter);
}
}
GF_Fields::register( new Wiaas_Field_Order_Bundle_Document() );

View File

@@ -0,0 +1,38 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Bundle_Installation_Date extends GF_Field_Date {
public $type ='wiaas_order_bundle_installation_date';
public $inputType = 'date';
public $dateType = 'datepicker';
public function get_input_type() {
return 'date';
}
public function get_form_editor_field_title() {
return esc_attr__( 'Bundle Install Date', 'wiaas' );
}
public function add_button( $field_groups ) {
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
return parent::add_button( $field_groups );
}
public function get_form_editor_button() {
return array(
'group' => 'wiaas_order_fields',
'text' => $this->get_form_editor_field_title(),
);
}
}
GF_Fields::register( new Wiaas_Field_Order_Bundle_Installation_Date() );

View File

@@ -0,0 +1,63 @@
<?php
class Wiaas_Field_Order_Bundle extends GF_Field_Text {
public $type = 'wiaas_order_bundle';
public function get_form_editor_field_title() {
return esc_attr__( 'Bundle', 'wiaas' );
}
public function add_button( $field_groups ) {
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
return parent::add_button( $field_groups );
}
public function get_form_editor_button() {
return array(
'group' => 'wiaas_order_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
return $this->get_bundle_display_name($value);
}
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
return $this->get_bundle_display_name($value);
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
return $this->get_bundle_display_name($value);
}
public function get_bundle_item($value) {
list($order_id, $item_id) = rgexplode('|', $value, 2);
if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) {
return $order->get_item($item_id);
}
return null;
}
public function get_bundle_display_name($value) {
$item = $this->get_bundle_item($value);
if (! empty($item)) {
return $item->get_name();
}
return '';
}
}
GF_Fields::register( new Wiaas_Field_Order_Bundle() );

View File

@@ -0,0 +1,74 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Document extends GF_Field_FileUpload {
public $type ='wiaas_order_document';
public $wiaasDocTypeFilter = 'install_guide';
public function get_form_editor_field_settings() {
return array(
'wiaas_doc_type_filter',
'multiple_files_setting',
'conditional_logic_field_setting',
'error_message_setting',
'label_setting',
'label_placement_setting',
'admin_label_setting',
'rules_setting',
'file_extensions_setting',
'file_size_setting',
'visibility_setting',
'description_setting',
'css_class_setting',
);
}
public function get_input_type() {
return 'fileupload';
}
public function get_form_editor_field_title() {
return esc_attr__( 'Order Document', 'wiaas' );
}
public function add_button( $field_groups ) {
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
return parent::add_button( $field_groups );
}
public function get_form_editor_button() {
return array(
'group' => 'wiaas_order_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_download_url( $file, $force_download = false ) {
$upload_root = GFFormsModel::get_upload_url( $this->formId );
$upload_root = trailingslashit( $upload_root );
// handle download for order documents not uploaded by gravity forms
if ( strpos( $file, $upload_root ) === false ) {
return admin_url() . '?gf-wiaas-order-doc=' . urlencode($file);
}
return parent::get_download_url( $file, true );
}
public function sanitize_settings() {
parent::sanitize_settings();
$this->wiaasDocTypeFilter = sanitize_key($this->wiaasDocTypeFilter);
}
}
GF_Fields::register( new Wiaas_Field_Order_Document() );

View File

@@ -0,0 +1,127 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Order_Installation_Select extends GF_Field_Select {
public $type = 'wiaas_order_installation_select';
public function get_input_type() {
return 'workflow_assignee_select';
}
public function add_button( $field_groups ) {
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
return parent::add_button( $field_groups );
}
public function get_form_editor_button() {
return array(
'group' => 'wiaas_order_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_field_input( $form, $value = '', $entry = null ) {
if ( empty($entry) ) {
return parent::get_field_input($form, $value, $entry);
}
// get bundle item field
$bundle_item_field = GFCommon::get_fields_by_type($form, array( 'wiaas_order_bundle') )[0];
if (! empty($bundle_item_field) &&
$bundle_item = $bundle_item_field->get_bundle_item($entry[$bundle_item_field->id])) {
$bundled_items = wc_pb_get_bundled_order_items($bundle_item);
$installation_items = array();
foreach ($bundled_items as $id => $bundled_item) {
$product = $bundled_item->get_product();
if ($product && Wiaas_Product_Category::is_installation($product)) {
$installation_items[] = $bundled_item;
}
}
$choices = array(
array( 'value' => '0', 'text' => 'Select installation ...')
);
$order_id = $bundle_item->get_order_id();
foreach ($installation_items as $installation_item) {
$choices[] = array(
'value' => 'wiaas_installation_' . $order_id . '|' . $installation_item->get_id(),
'text' => $installation_item->get_name()
);
}
$this->choices = $choices;
}
return parent::get_field_input($form, $value, $entry);
}
public function get_form_editor_field_title() {
return esc_attr__( 'Installation Select', 'wiaas' );
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
return $this->get_selected_installation_display_name($value);
}
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
return $this->get_selected_installation_display_name($value);
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
return $this->get_selected_installation_display_name($value);
}
public function get_selected_installation($value) {
$value = $value ? str_replace('wiaas_installation_', '', $value) : '';
list ($order_id, $item_id) = explode('|', $value);
if (! empty($order_id) && ! empty($item_id) && $order = wc_get_order($order_id)) {
return $order->get_item($item_id);
}
return null;
}
public function get_selected_installation_display_name($value) {
$item = $this->get_selected_installation($value);
return ! empty($item) ? $item->get_name() : '';
}
public function post_convert_field() {
if ($this->is_form_editor()) {
$this->choices = array(
array( 'value' => '0', 'text' => 'Select installation ...')
);
}
}
}
GF_Fields::register( new Wiaas_Order_Installation_Select() );

View File

@@ -0,0 +1,66 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Field_Order_Number extends GF_Field_Number {
public $type = 'wiaas_order';
function get_form_editor_field_settings() {
return array(
'conditional_logic_field_setting',
'prepopulate_field_setting',
'error_message_setting',
'label_setting',
'label_placement_setting',
'admin_label_setting',
'size_setting',
'rules_setting',
'visibility_setting',
'duplicate_setting',
'default_value_setting',
'placeholder_setting',
'description_setting',
'css_class_setting',
);
}
public function sanitize_settings() {
parent::sanitize_settings();
}
public function get_form_editor_field_title() {
return esc_attr__( 'Order Number', 'wiaas' );
}
public function add_button( $field_groups ) {
$field_groups = Wiaas_Order_Fields::maybe_add_order_field_group($field_groups);
return parent::add_button( $field_groups );
}
public function get_form_editor_button() {
return array(
'group' => 'wiaas_order_fields',
'text' => $this->get_form_editor_field_title(),
);
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
return "#100000$value";
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
return "#100000$value";
}
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
return "#100000$value";
}
}
GF_Fields::register( new Wiaas_Field_Order_Number() );

View File

@@ -0,0 +1,59 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Merge_Tag_Customer_Order_Url extends Gravity_Flow_Merge_Tag {
/**
* Name of the merge tag
*
* @var string
*/
public $name = 'customer_order_url';
/**
* The regular expression to use for the matching.
*
* @var string
*/
protected $regex = '/{customer_order_url(:(.*?))?}/';
public function replace( $text ) {
$matches = $this->get_matches( $text );
if ( ! empty( $matches ) ) {
$entry = $this->entry;
$form = GFAPI::get_form($entry['form_id']);
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
if (empty($order_field)) {
return $text;
}
$order_id = $entry[$order_field->id];
$url = WIAAS_CUSTOMER_INTERFACE . '/orders/' . $order_id;
$link = sprintf( '<a href="%s">%s</a>', $url, 'Order' );
foreach ( $matches as $match ) {
$full_tag = $match[0];
$text = str_replace( $full_tag, $link, $text );
}
}
return $text;
}
}
Gravity_Flow_Merge_Tags::register( new Wiaas_Merge_Tag_Customer_Order_Url );

View File

@@ -0,0 +1,465 @@
<?php
if ( ! class_exists( 'GFForms' ) ) {
die();
}
class Wiaas_Order_Fields {
public static function init() {
add_action( 'gform_field_standard_settings', array( __CLASS__, 'field_settings' ) );
add_filter('gform_fileupload_entry_value_file_path', array( __CLASS__, 'display_order_document_fields' ), 999, 2);
add_action('gform_post_update_entry', array(__CLASS__, 'maybe_map_entry_to_order'), 10, 2);
add_action('gform_after_update_entry', array(__CLASS__, 'maybe_apply_user_input_changes'), 10, 3);
}
/**
* Workflow user input are handled separately in gravity flow. We get them here
* and then try to apply changes to order
*
* @param $form
* @param $entry_id
* @param $original_entry
*/
public static function maybe_apply_user_input_changes($form, $entry_id, $original_entry) {
$entry = GFAPI::get_entry($entry_id);
self::maybe_map_entry_to_order($entry, $original_entry);
}
/**
* Persist workflow entry change to order
*
* @param $entry
* @param $old_entry
*/
public static function maybe_map_entry_to_order($entry, $old_entry) {
$form = GFAPI::get_form($old_entry['form_id']);
$order_field = GFCommon::get_fields_by_type($form, 'wiaas_order')[0];
if (empty($order_field)) {
return;
}
$order_id = $entry[$order_field->id];
// get order process entry
$order = wc_get_order($order_id);
$process_entry = Wiaas_Delivery_Process::get_order_delivery_process_entry($order_id);
if ( !$order || empty($process_entry) ) {
return;
}
// apply entry changes to order properties
foreach ($form['fields'] as $field) {
$old_value = $old_entry[$field->id];
$new_value = $entry[$field->id];
// check if field changed
if ($old_value === $new_value || empty($new_value)) {
continue;
}
// save changes to order
switch ($field->type) {
case 'wiaas_order_bundle_installation_date':
/**
* Persist bundle installation date
*/
// get corresponding bundle field
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
if (empty($bundle_field)) {
continue;
}
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
if (empty($bundle_item)) {
continue;
}
$bundle_item->update_meta_data('_wiaas_installation_date', $new_value);
$bundle_item->save_meta_data();
break;
case 'wiaas_order_bundle_document':
/**
* Persist delivery flow documents for bundle
*/
// get corresponding bundle field
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
if (empty($bundle_field)) {
continue;
}
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
if (empty($bundle_item)) {
continue;
}
$bundle_documents = $bundle_item->get_meta('_wiaas_documents', true);
if (empty($bundle_documents)) {
$bundle_documents = array();
}
$new_documents = $field->multipleFiles ? json_decode( $new_value ) : array( $new_value );
if (! empty($old_value) ) {
$old_documents = $field->multipleFiles ? json_decode( $old_value ) : array( $old_value );
$added_documents = array_diff($new_documents, $old_documents);
} else {
$added_documents = $new_documents;
}
foreach ($added_documents as $added_document) {
$info = pathinfo( $added_document );
$dir = wp_upload_dir();
$relative_file_path = str_replace($dir['baseurl'] . '/', '', $added_document);
$bundle_documents[] = array(
'key' => wp_generate_uuid4(),
'name' => $info['filename'],
'extension' => $info['extension'],
'version' => $relative_file_path,
'url' => $field->get_download_url( $added_document, true ),
'type' => $field->wiaasDocTypeFilter
);
}
$bundle_item->update_meta_data('_wiaas_documents', $bundle_documents);
$bundle_item->save_meta_data();
break;
case 'wiaas_order_document':
/**
* Persist delivery flow documents for order
*/
$new_documents = $field->multipleFiles ? json_decode( $new_value ) : array( $new_value );
if (! empty($old_value) ) {
$old_documents = $field->multipleFiles ? json_decode( $old_value ) : array( $old_value );
$added_documents = array_diff($new_documents, $old_documents);
} else {
$added_documents = $new_documents;
}
$order_documents = $order->get_meta('_wiaas_other_documents', true);
if (empty($order_documents)) {
$order_documents = array();
}
foreach ($added_documents as $added_document) {
$info = pathinfo( $added_document );
$dir = wp_upload_dir();
$relative_file_path = str_replace($dir['baseurl'] . '/', '', $added_document);
$order_documents[] = array(
'key' => wp_generate_uuid4(),
'name' => $info['filename'],
'extension' => $info['extension'],
'version' => $relative_file_path,
'url' => $field->get_download_url( $added_document, true ),
'type' => $field->wiaasDocTypeFilter
);
}
$order->update_meta_data('_wiaas_other_documents', $order_documents);
$order->save_meta_data();
break;
case 'wiaas_order_installation_select':
/**
* Persist installation for bundle
*/
$selected_installation = $field->get_selected_installation($new_value);
if ( empty($selected_installation) ) {
// no installation selected
continue;
}
// get corresponding bundle field
$bundle_field = GFCommon::get_fields_by_type( $form, 'wiaas_order_bundle' )[0];
if (empty($bundle_field)) {
continue;
}
$bundle_item = $bundle_field->get_bundle_item( $entry[$bundle_field->id] );
if (empty($bundle_item)) {
continue;
}
$bundle_item->update_meta_data('_wiaas_installation', $selected_installation->get_id());
$bundle_item->save_meta_data();
}
}
}
/**
* Adds the Order Fields group to the form editor.
*
* @param array $field_groups The properties for the field groups.
*
* @return array
*/
public static function maybe_add_order_field_group( $field_groups ) {
foreach ( $field_groups as $field_group ) {
if ( $field_group['name'] == 'wiaas_order_fields' ) {
return $field_groups;
}
}
$field_groups[] = array(
'name' => 'wiaas_order_fields',
'label' => __( 'Order Fields', 'wiaas' ),
'fields' => array()
);
return $field_groups;
}
public static function display_order_document_fields($file_path, $field) {
if (strpos($file_path, 'gf-download') === false &&
strpos($file_path, 'gf-wiaas-order-doc') === false) {
$field = new Wiaas_Field_Order_Bundle_Document();
return $field->get_download_url($file_path);
}
return $file_path;
}
/**
* Add custom settings for form order fields
*
* @param int $position
*/
public static function field_settings( $position ) {
if ( $position === 20 ) {
// After Field description setting.
?>
<li class="wiaas_doc_type_filter field_setting">
<label for="wiaas-doc-type-filter" class="section_label">
<?php esc_html_e( 'Document Type', 'wiaas' ); ?>
</label>
<select id="wiaas-doc-type-filter" onchange="SetFieldProperty('wiaasDocTypeFilter',this.value);">
<option value="configuration"><?php esc_html_e( 'Configuration', 'wiaas' ); ?></option>
<option value="order_questionaire"><?php esc_html_e( 'Order Questionaire', 'wiaas' ); ?></option>
<option value="installation_protocol"><?php esc_html_e( 'Installation protocol', 'wiaas' ); ?></option>
<option value="install_guide"><?php esc_html_e( 'Installation Guide', 'wiaas' ); ?></option>
<option value="customer_acceptance"><?php esc_html_e( 'Customer acceptance', 'wiaas' ); ?></option>
</select>
</li>
<li class="wiaas_installation_organization_filter field_setting">
<input type="checkbox" id="wiaas-installation-organization-filter"
onclick="var value = jQuery(this).is(':checked'); SetFieldProperty('wiaasOnlyInstallationOrg', value);""/>
<label for="wiaas-installation-organization-filter" class="inline">
<?php esc_html_e( 'Only installation', 'wiaas' ); ?>
</label>
</li>
<?php
}
}
/**
* Create new entry for order delivery process action form
*
* @param int $order_id
* @param array $form
* @param int|null $bundle_item_id
*
* @return array|bool
*/
public static function map_order_to_entry($order_id, $form, $bundle_item_id = null) {
if (empty($form['fields']) ||
empty(GFCommon::get_fields_by_type( $form, array('wiaas_order')) ) ) {
// form does not have order field so cannot be mapped
return false;
}
$order = wc_get_order($order_id);
$entry = array();
foreach ($form['fields'] as $field) {
switch ($field->type) {
case 'wiaas_order':
$entry[(string) $field->id] = $order->get_id();
break;
case 'workflow_user':
$entry[(string) $field->id] = $order->get_customer_id(); // save customer if needed
break;
case 'wiaas_order_bundle':
$bundle_item = $order->get_item($bundle_item_id);
if ( empty($bundle_item) && $field->isRequired) {
// there is no data for required field so entry cannot be created
return false;
}
if (! empty($bundle_item)) {
$entry[(string) $field->id] = $order->get_id() . '|' . $bundle_item->get_id();
}
break;
case 'wiaas_order_bundle_document':
$bundle_item = $order->get_item($bundle_item_id);
if ( empty($bundle_item) && $field->isRequired) {
// there is no data for required field so entry cannot be created
return false;
}
if (! empty($bundle_item)) {
$documents = wiaas_get_standard_package_order_item_documents($order, $bundle_item_id);
$filtered_documents = array();
foreach ($documents as $document) {
if ($document['type'] === $field->wiaasDocTypeFilter) {
$filtered_documents[] = $document;
}
}
if ( empty($filtered_documents) && $field->isRequired ) {
// there is no data for required field so entry cannot be created
return false;
}
if (! empty ($filtered_documents) && ! $field->multipleFiles) {
$document = $filtered_documents[0];
$entry[$field->id] = $document['version'];
} else if (! empty ($filtered_documents) ) {
$versions = array();
foreach ($filtered_documents as $filtered_document) {
$versions[] = $filtered_document['version'];
}
$entry[$field->id] = json_encode($versions);
}
}
break;
case 'wiaas_order_installation_select':
$bundle_item = $order->get_item($bundle_item_id);
if ( empty($bundle_item) && $field->isRequired) {
// there is no data for required field so entry cannot be created
return false;
}
// installation is already selected
if (!empty($bundle_item->get_meta('_wiaas_installation', true))) {
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $bundle_item->get_meta('_wiaas_installation', true);
continue;
}
$bundled_items = wc_pb_get_bundled_order_items($bundle_item, $order);
$installation_items = array();
foreach ($bundled_items as $id => $bundled_item) {
$product = $bundled_item->get_product();
if ($product && Wiaas_Product_Category::is_installation($product)) {
$installation_items[] = $bundled_item;
}
}
if (empty($installation_items)) {
// there is no data for required field so entry cannot be created
return false;
}
if (count($installation_items) === 1) {
$installation_item = $installation_items[0];
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $installation_item->get_id();
} else if (count($installation_items) > 1) {
// force admin to select installation
$entry[(string) $field->id] = '0';
}
}
}
return $entry;
}
}
Wiaas_Order_Fields::init();

View File

@@ -12,9 +12,41 @@ class Wiaas_Document_Download {
if ( isset($_GET['wiaasdoc']) ) {
add_action( 'init', array( __CLASS__, 'admin_download' ) );
}
if (isset($_GET['gf-wiaas-order-doc'])) {
add_action( 'init', array( __CLASS__, 'admin_gf_order_document_download' ) );
}
}
/**
* Handle download of order documents by gravity flow steps for wordpress administration interface
*
*/
public static function admin_gf_order_document_download() {
if (!is_user_logged_in()) {
wp_die( __( 'No Access.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 403 ) );
}
// relative file path from upload dir for document
$version = urldecode($_GET['gf-wiaas-order-doc']);
$file_path = wiaas_get_document_version_path($version);
if (!file_exists($file_path)) {
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
}
WC_Download_Handler::download_file_force(
$file_path,
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
);
}
/**
* Handle document download for wordpress administration interface
*
* Since only REST api uses JWT Authentication this endpoint will work only for users
* that are logged in directly to wordpress
*/
@@ -54,6 +86,48 @@ class Wiaas_Document_Download {
);
}
/**
* Download order other document (not related to any order item)
*
* @param int $order_id
* @param string $document_key
*/
public static function download_order_other_document($order_id, $document_key) {
$order = wc_get_order($order_id);
if (!$order) {
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
}
$order_other_documents = wiaas_get_order_other_documents($order_id);
$order_document = null;
foreach ($order_other_documents as $order_other_document) {
if ($order_other_document['key'] === $document_key) {
$order_document = $order_other_document;
break;
}
}
if (!isset($order_document)) {
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
}
$file_path = wiaas_get_document_version_path($order_document['version']);
if (!file_exists($file_path)) {
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
}
WC_Download_Handler::download_file_force(
$file_path,
pathinfo( $file_path, PATHINFO_FILENAME ) . '.' . pathinfo( $file_path, PATHINFO_EXTENSION )
);
}
/**
* Download document related to order item
*
@@ -62,7 +136,7 @@ class Wiaas_Document_Download {
* @param $type
* @param $document_key
*/
public static function download_order_item_document($order_id, $item_id, $type, $document_key) {
public static function download_order_item_document($order_id, $item_id, $document_key) {
$order = wc_get_order($order_id);
if (!$order) {
wp_die( __( 'Invalid Document Request.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 400 ) );
@@ -77,7 +151,7 @@ class Wiaas_Document_Download {
$order_document = null;
foreach ($item_documents as $item_document) {
if ($item_document['key'] === $document_key && $item_document['type'] === $type) {
if ($item_document['key'] === $document_key) {
$order_document = $item_document;
break;
}

View File

@@ -26,6 +26,17 @@ function wiaas_documents_upload_dir() {
* @return string
*/
function wiaas_get_document_version_path($version) {
// documents uploaded with gravity forms have relevant path to form entry upload folder
if (strpos($version, 'gravity_forms') !== false) {
$wp_uploads = wp_upload_dir();
$wp_uploads_dir = $wp_uploads['basedir'];
return $wp_uploads_dir . '/' . $version;
}
return wiaas_documents_upload_dir() . '/' . $version;
}
@@ -182,9 +193,60 @@ function wiaas_get_standard_package_order_item_documents($order, $package_item_i
return array_map(function($doc) {
// append document extension and name information
$doc['extension'] = wiaas_get_doc_version_extension($doc['version']);
$doc['extension'] = isset($doc['extension']) ? $doc['extension'] : wiaas_get_doc_version_extension($doc['version']);
$doc['name'] = isset($doc['name']) ? $doc['name'] : wiaas_get_doc_version_filename($doc['version']);
return $doc;
}, $order_documents);
}
/**
* Retrieve documents for order item
*
* @param $order_item
* @param string|null $doc_type
*
* @return array {
* $param string key Unique key used for frontend downloand
* $param string name Document name visible in download link
* $param string version Relative path from upload directory to physical document file
* $param string type Document type
*
* @reference Wiaas_Document
* }
*/
function wiaas_get_order_item_documents($order_item, $doc_type = null) {
$documents = empty($order_item['wiaas_documents']) ? array() : $order_item['wiaas_documents'];
if (empty($doc_type)) {
return $documents;
}
$filtered_documents = array();
foreach ($documents as $document) {
if ($document['type'] === $doc_type) {
$filtered_documents[] = $document;
}
}
return $filtered_documents;
}
/**
* Retrieve order other documents (not binded to any order item)
*
* @param int $order_id
*
* @return array|mixed
*/
function wiaas_get_order_other_documents($order_id) {
$order = wc_get_order($order_id);
$documents = $order->get_meta('_wiaas_other_documents', true);
return empty($documents) ? array() : $documents;
}

View File

@@ -31,6 +31,12 @@ class Wiaas_Order_Project {
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'shop_order_project' ),
'capabilities' => array(
'manage_terms' => 'manage_wiaas_order_projects',
'edit_terms' => 'manage_wiaas_order_projects',
'delete_terms' => 'manage_wiaas_order_projects',
'assign_terms' => 'manage_wiaas_order_projects',
),
'update_count_callback' => array(__CLASS__, 'update_count_callback')
);

View File

@@ -0,0 +1,92 @@
<?php
/**
* Retrieve standard bundles from order
*
* @param int|WC_Order $order
*
* @return array
*/
function wiaas_get_order_standard_bundle_items($order) {
if (is_numeric($order)) {
$order = wc_get_order($order);
}
$items = $order->get_items();
$standard_bundle_items = array();
foreach ($items as $item) {
if (isset($item['wiaas_standard_package'])) {
$standard_bundle_items[] = $item;
}
}
return $standard_bundle_items;
}
/**
* Retrieve order summary data for procurement order for suppliers
*
* @param int $order_id
*
* @return array
*/
function wiaas_get_order_procurement_info($order_id) {
$order = wc_get_order($order_id);
$order_items = $order->get_items();
$order_suppliers_info = array();
$order_delivery_suppliers_info = $order->get_meta('_wiaas_delivery_suppliers');
$order_installation_suppliers_info = $order->get_meta('_wiaas_installation_suppliers');
foreach ($order_delivery_suppliers_info as $id => $order_delivery_supplier_info) {
$order_suppliers_info[$id] = $order_delivery_supplier_info;
}
foreach ($order_installation_suppliers_info as $id => $order_installation_supplier_info) {
$order_suppliers_info[$id] = $order_installation_supplier_info;
}
$data = array();
foreach ($order_items as $order_item_id => $order_item) {
$category = $order_item['wiaas_category'];
$supplier_organization_id = $order_item['wiaas_supplier_organization_id'];
$supplier_info = $order_suppliers_info[$supplier_organization_id];
if (empty($category)) {
continue;
}
$data[$category] ?: array();
// get price and quantity
$single_product_item_cost = floatval($order_item['wiaas_product_price']);
$quantity = absint($order_item['quantity']);
$total_price = $quantity * $single_product_item_cost;
$data[$category][] = array(
'Name' => $order_item->get_name(),
'Category' => ucfirst(strtolower($category)),
'Manufacturer Product No' => $order_item['wiaas_manufacturer_product_no'],
'Supplier Product No' => $order_item['wiaas_supplier_product_no'],
'Units' => $quantity,
'Price' => $total_price,
'Supplier Company' => $supplier_info['name'],
'Supplier VAT' => $supplier_info['vat_code'],
'Supplier Phone' => $supplier_info['phone'],
'Supplier Email' => $supplier_info['email'],
);
}
return $data;
}

View File

@@ -50,14 +50,14 @@ function wiaas_get_price_margin($fixed_price, $principal_amount, $total_cost) {
return $total_gain - $total_cost;
}
function wiaas_get_package_hardware_procurement_cost($package) {
function wiaas_get_package_product_procurement_cost($package){
$bundled_items = $package->get_bundled_items();
$total_cost = 0;
foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product;
if (Wiaas_Product_Category::get_category($product) === 'hardware') {
if (Wiaas_Product_Category::is_product($product)) {
$total_cost += Wiaas_Pricing::get_product_total_cost($product) * $bundled_item->get_quantity();
}
}
@@ -65,19 +65,6 @@ function wiaas_get_package_hardware_procurement_cost($package) {
return $total_cost;
}
function wiaas_get_package_software_procurement_cost($package) {
$bundled_items = $package->get_bundled_items();
$total_cost = 0;
foreach ($bundled_items as $bundled_item) {
if (Wiaas_Product_Category::is_hardware($bundled_item->product)) {
$total_cost += Wiaas_Pricing::get_product_total_cost($bundled_item->product) * $bundled_item->get_quantity();
}
}
return $total_cost;
}
function wiaas_get_package_installation_procurement_cost($package) {
$bundled_items = $package->get_bundled_items();
$total_cost = 0;

View File

@@ -86,26 +86,15 @@ class Wiaas_Product_Category {
}
/**
* Determines if provided product is hardware
* Determines if provided product type is product (hardware or software)
* @param $product
*
* @return bool
*/
public static function is_hardware($product) {
return self::_get_product_category_type($product) === 'hardware';
public static function is_product($product) {
return self::_get_product_category_type($product) === 'product';
}
/**
* Determines if provided product is software
* @param $product
*
* @return bool
*/
public static function is_software($product) {
return self::_get_product_category_type($product) === 'software';
}
// PRIVATE

View File

@@ -6,7 +6,8 @@ class Wiaas_Product_Supplier {
public static function init() {
add_action('init', array(__CLASS__, 'register_supplier_taxonomy'));
add_action('created_' . 'wiaas-user-organization', array(__CLASS__, 'on_organization_added'));
add_action('wiaas_organization_created', array(__CLASS__, 'on_organization_added'), 20, 2);
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'on_organization_added'), 20, 2);
}
/**
@@ -33,7 +34,7 @@ class Wiaas_Product_Supplier {
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'meta_box_cb' => false,
'meta_box_cb' => false,
'query_var' => true,
'rewrite' => array('slug' => 'template_category'),
);
@@ -46,19 +47,45 @@ class Wiaas_Product_Supplier {
* Create corresponding supplier term for organization
*
* @param $organization_id
* @param $roles
*/
public static function on_organization_added($organization_id) {
public static function on_organization_added($organization_id, $roles) {
$organization = get_term_by('id', $organization_id, 'wiaas-user-organization');
$supplier = term_exists($organization->slug, 'supplier');
$supplier = term_exists($organization->slug, 'supplier');
if (! $supplier) {
$supplier = wp_insert_term($organization->name, 'supplier', array(
'slug' => $organization->slug
));
if (!$supplier && in_array('supplier', $roles)) {
$supplier = wp_insert_term($organization->name, 'supplier', array(
'slug' => $organization->slug
));
}
add_term_meta($supplier['term_id'], 'organisation_id', $organization->term_id);
add_term_meta($supplier['term_id'], 'organisation_id', $organization->term_id);
}
/**
* Retrieve organisation id of the supplier of the product
*
* @param $product_id
* @return int|false organization_id
*/
public static function get_supplier_organisation_id_from_product($product_id) {
$supplier_terms = wp_get_object_terms($product_id, 'supplier');
if (empty( $supplier_terms )) {
return false;
}
$supplier_organisation_slug = $supplier_terms[0]->slug;
$supplier_organisation = get_term_by('slug', $supplier_organisation_slug, 'wiaas-user-organization');
if ($supplier_organisation) {
return $supplier_organisation->term_id;
}
return $supplier_organisation ? $supplier_organisation->term_id : false;
}
}

View File

@@ -9,11 +9,17 @@ class Wiaas_Template_Category_Object {
public $quantity = '';
public $product_id = '';
public function __construct($id, $title, $quant) {
public $product_name = '';
public function __construct($id, $title, $quant, $product_id = '', $product_name = '') {
$this->template_category_id = $id;
$this->name = $title;
$this->quantity = $quant;
$this->product_id = $product_id;
$this->product_name = $product_name;
}
public function get_quantity(){

View File

@@ -92,7 +92,9 @@ function construct_template_products_class() {
$template_category_object = new Wiaas_Template_Category_Object(
$category_template_id,
$cat,
$item_data['quantity_max']);
$item_data['quantity_max'],
$item->get_id(),
$item->get_title());
$template_category_objects[$category_template_id] = $template_category_object;
}

View File

@@ -133,9 +133,9 @@ class Wiaas_Customer {
if ($new_address->id){
$updated = array(
'id' => $new_address->id,
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
'id_country_selected' => $new_address->id_country_selected,
'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
@@ -152,9 +152,9 @@ class Wiaas_Customer {
}else{
$new_billing_address = array(
'id' => time(),
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
'id_country_selected' => $new_address->id_country_selected,
'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
@@ -178,9 +178,9 @@ class Wiaas_Customer {
if ($new_address->id){
$updated = array(
'id' => $new_address->id,
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
'id_country_selected' => $new_address->id_country_selected,
'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
@@ -197,9 +197,9 @@ class Wiaas_Customer {
}else{
$new_delivery_address = array(
'id' => time(),
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
'id_country_selected' => $new_address->id_country_selected,
'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,

View File

@@ -38,22 +38,22 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
add_action( 'pre_delete_term', array( __CLASS__, 'on_taxonomy_term_will_be_deleted' ), 10, 2);
add_action( 'delete_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_deleted' ));
add_action('acf/save_post', array(__CLASS__, 'on_organization_roles_maybe_updated'));
add_action('acf/save_post', array(__CLASS__, 'on_organization_roles_maybe_updated'), 20);
add_action('set_object_terms', array( __CLASS__, 'on_taxonomy_term_assigned' ), 10, 4);
add_action('deleted_term_relationships', array( __CLASS__, 'on_taxonomy_term_unassigned' ), 10, 3);
// Remove bulk editor for organizations on users list
remove_filter( 'admin_notices', array( $this, 'bulk_notice'));
remove_filter( 'bulk_actions-users', array( $this, 'bulk_actions'));
remove_filter( 'bulk_actions-users', array( $this, 'bulk_actions_sort'));
remove_action( 'handle_bulk_actions-users', array( $this, 'handle_bulk_actions'));
remove_filter( 'admin_notices', array( $this, 'bulk_notice'));
remove_filter( 'bulk_actions-users', array( $this, 'bulk_actions'));
remove_filter( 'bulk_actions-users', array( $this, 'bulk_actions_sort'));
remove_action( 'handle_bulk_actions-users', array( $this, 'handle_bulk_actions'));
// remove default organization info from profiles
// it will be handled by custom fields
remove_action( 'show_user_profile', array( $this, 'edit_user_relationships' ), 99);
remove_action( 'edit_user_profile', array( $this, 'edit_user_relationships' ), 99 );
// remove default organization info from profiles
// it will be handled by custom fields
remove_action( 'show_user_profile', array( $this, 'edit_user_relationships' ), 99);
remove_action( 'edit_user_profile', array( $this, 'edit_user_relationships' ), 99 );
}
// hooks functions
@@ -61,12 +61,15 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
/**
* Creates corresponding access group for newly created organizational term
*
* @param $organization_id id of the organization term
* @param int $organization_id id of the organization term
*/
public static function on_organization_added($organization_id) {
self::_create_organization_access_group($organization_id);
$roles = wiaas_get_organization_roles($organization_id);
do_action('wiaas_organization_created', $organization_id, $roles);
do_action('wiaas_organization_created', $organization_id);
self::_assign_organization_roles_capabilities($organization_id, $roles);
}
/**
@@ -104,6 +107,11 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
//get organization id
$id = absint(str_replace('term_', '', $id));
if ($id) {
self::_assign_organization_roles_capabilities($id, $roles);
}
do_action('wiaas_organization_roles_updated', $id, $roles);
}
}
@@ -153,7 +161,7 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
*/
public static function get_user_organization_id($user_id = null) {
if (!isset($user_id)) {
$user_id = get_current_user_id();
$user_id = get_current_user_id();
}
$organization_id = get_user_meta($user_id, '_wiaas_organization_id', true);
@@ -284,4 +292,33 @@ class Wiaas_User_Organization extends WP_User_Taxonomy {
}
}
}
/**
*Reflect organization roles in access group
*
* This will be used when assigning roles to user
*
* @param int $organization_id
* @param array $roles
*/
private static function _assign_organization_roles_capabilities($organization_id, $roles) {
$access_group_id = self::_get_organization_access_group_id($organization_id);
$all_roles = array( 'commercial_lead', 'supplier', 'customer', 'administrator');
foreach ($all_roles as $role) {
$cap = Groups_Capability::read_by_capability('wiaas_' . $role);
Groups_Group_Capability::delete($access_group_id, $cap->capability_id);
}
foreach ($roles as $role) {
$cap = Groups_Capability::read_by_capability('wiaas_' . $role);
Groups_Group_Capability::create(array(
'group_id' => $access_group_id,
'capability_id' => $cap->capability_id
));
}
}
}

View File

@@ -103,4 +103,38 @@ function wiaas_get_user_organization_id($user_id) {
*/
function wiaas_get_current_user_organization_id() {
return wiaas_get_user_organization_id(get_current_user_id());
}
function wiaas_get_organization_user_ids($organization_id) {
$user_ids = get_objects_in_term($organization_id, Wiaas_User_Organization::TAXONOMY_NAME);
return is_wp_error($user_ids) ? array() : $user_ids;
}
function wiaas_get_organization_info($organization_id) {
$organization = get_term($organization_id);
if ($organization) {
$user_ids = wiaas_get_organization_user_ids($organization_id);
$email = null;
if (! empty($user_ids)) {
$user = get_userdata($user_ids[0]);
$email = $user ? $user->user_email : null;
}
return array(
'name' => $organization->name,
'description' => $organization->description,
'vat_code' => get_term_meta($organization_id, '_wiaas_organization_vat', true),
'phone' => get_term_meta($organization_id, '_wiaas_organization_phone', true),
'email' => $email
);
}
}

View File

@@ -1,521 +0,0 @@
<?php
/**
* Wiaas_Delivery_Process_Step_Test
*
* @package Wiaas
*/
class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case {
var $order_id, $api;
/**
* Test REST Server
*
* @var WP_REST_Server
*/
protected $server;
protected $namespaced_route = '/wiaas';
function setUp() {
parent::setUp();
$order = wc_create_order();
$this->order_id = $order->get_id();
wp_set_current_user(1);
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$this->server = $wp_rest_server = new \WP_REST_Server;
do_action( 'rest_api_init' );
$original_valid_customer_acceptance = __DIR__ . '/../dummy-files/valid-customer-acceptance.odt';
$this->test_file_valid_customer_acceptance = '/tmp/valid-customer-acceptance.odt';
copy( $original_valid_customer_acceptance, $this->test_file_valid_customer_acceptance );
$original_invalid_customer_acceptance = __DIR__ . '/../dummy-files/invalid-customer-acceptance.txt';
$this->test_file_invalid_customer_acceptance = '/tmp/invalid-customer-acceptance.txt';
copy( $original_invalid_customer_acceptance, $this->test_file_invalid_customer_acceptance );
}
function test_register_route() {
$routes = $this->server->get_routes();
$this->assertArrayHasKey( $this->namespaced_route, $routes );
}
function test_endpoints() {
$the_route = $this->namespaced_route;
$routes = $this->server->get_routes();
foreach( $routes as $route => $route_config ) {
if( 0 === strpos( $the_route, $route ) ) {
$this->assertTrue( is_array( $route_config ) );
foreach( $route_config as $i => $endpoint ) {
$this->assertArrayHasKey( 'callback', $endpoint );
$this->assertArrayHasKey( 0, $endpoint[ 'callback' ], get_class( $this ) );
$this->assertArrayHasKey( 1, $endpoint[ 'callback' ], get_class( $this ) );
$this->assertTrue( is_callable( array( $endpoint[ 'callback' ][0], $endpoint[ 'callback' ][1] ) ) );
}
}
}
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_next_actions_for_user
*/
function test_get_next_actions_for_user() {
wp_set_current_user(1);
$response = Wiass_REST_Delivery_Process_API::get_next_actions_for_user();
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response', $response);
$next_steps = $response->get_data();
$this->assertNotNull($next_steps);
$this->assertTrue(is_array($next_steps));
$pending_step = $next_steps[0];
$this->assertTrue(is_array($pending_step));
$this->assertArrayHasKey('order_id', $pending_step);
$this->assertArrayHasKey('order_number', $pending_step);
$this->assertArrayHasKey('status', $pending_step);
$this->assertArrayHasKey('step_action', $pending_step);
$this->assertEquals($pending_step['order_id'], $this->order_id);
$this->assertEquals($pending_step['order_number'], $this->order_id);
$this->assertEquals($pending_step['status'], 'pending');
$this->assertNotEmpty($pending_step['step_action']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
*/
function test_get_customer_acceptance_as_guest() {
wp_set_current_user(0);
$request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/99191991919191');
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 401);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
*/
function test_get_nonexisting_customer_acceptance() {
wp_set_current_user(1);
$request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/911919191919' ); //non existing entry ID
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 404);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
*/
function test_get_valid_customer_acceptance() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertTrue(is_array($response_data));
$this->assertArrayHasKey('documents', $response_data);
$this->assertArrayHasKey('expiration', $response_data);
$this->assertArrayHasKey('status', $response_data);
$this->assertArrayHasKey('decline_reason', $response_data);
$this->assertTrue(is_array($response_data['documents']));
$uploaded_file = $response_data['documents'][0];
$this->assertTrue(is_array($uploaded_file));
$this->assertArrayHasKey('name', $uploaded_file);
$this->assertArrayHasKey('extension', $uploaded_file);
$this->assertArrayHasKey('url', $uploaded_file);
$this->assertEquals($uploaded_file['name'], 'file1');
$this->assertEquals($uploaded_file['extension'], 'docx');
$this->assertEquals($uploaded_file['url'], 'http://localhost/wp/index.php?gf-download=2018%2F08%2Ffile1.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534');
$this->assertEquals($response_data['status'], 1); //1 means accept
$this->assertEquals($response_data['expiration'], "2020-01-01");
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_as_guest() {
wp_set_current_user(0);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/9191919191' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 401);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_nonexisting_customer_acceptance() {
wp_set_current_user(1);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919191919191' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 404);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_invalid_status() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'invalid status',
'declineReason' => ''
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('ACCEPTANCE_STATUS_MISSING', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_accepted_status() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'accept',
'declineReason' => ''
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('success', $message['code']);
$this->assertEquals('INSTALLATION_ACCEPTED', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_declined_status_and_empty_reason() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'decline',
'declineReason' => ''
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('DECLINE_REASON_EMPTY', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_decline_status() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'decline',
'declineReason' => 'This is very reasonable reason'
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('success', $message['code']);
$this->assertEquals('INSTALLATION_DECLINED', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_customer_acceptance_file_as_guest() {
wp_set_current_user(0);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 401);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_customer_acceptance_file_to_non_existing_entry() {
wp_set_current_user(1);
$original_valid_customer_acceptance = __DIR__ . '/../dummy-files/valid-customer-acceptance.odt';
$this->test_file_valid_customer_acceptance = '/tmp/valid-customer-acceptance.odt';
copy( $original_valid_customer_acceptance, $this->test_file_valid_customer_acceptance );
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
$request->set_file_params( array(
'file' => array(
'file' => file_get_contents( $this->test_file_valid_customer_acceptance ),
'name' => 'valid-customer-acceptance.odt',
'size' => filesize( $this->test_file_valid_customer_acceptance ),
'tmp_name' => $this->test_file_valid_customer_acceptance,
),
) );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 404);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_customer_acceptance_file_without_file() {
wp_set_current_user(1);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('NO_FILES_UPLOADED', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_invalid_customer_acceptance_file() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id . '/upload-file' );
$request->set_file_params( array(
'file' => array(
'file' => file_get_contents( $this->test_file_invalid_customer_acceptance ),
'name' => 'invalid-customer-acceptance.txt',
'size' => filesize( $this->test_file_invalid_customer_acceptance ),
'tmp_name' => $this->test_file_invalid_customer_acceptance,
),
) );
$request->set_header( 'Content-MD5', md5_file( $this->test_file_invalid_customer_acceptance ) );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('INVALID_FILE_ACCEPTANCE', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_valid_customer_acceptance_file() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id . '/upload-file' );
$request->set_file_params( array(
'file' => array(
'file' => file_get_contents( $this->test_file_valid_customer_acceptance ),
'name' => 'valid-customer-acceptance.odt',
'size' => filesize( $this->test_file_valid_customer_acceptance ),
'tmp_name' => $this->test_file_valid_customer_acceptance,
),
) );
$request->set_header( 'Content-MD5', md5_file( $this->test_file_valid_customer_acceptance ) );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('success', $message['code']);
$this->assertEquals('FILE_UPLOADED', $message['message']);
}
public function tearDown() {
parent::tearDown();
if ( file_exists( $this->test_file_valid_customer_acceptance ) ) {
unlink( $this->test_file_valid_customer_acceptance );
}
if ( file_exists( $this->test_file_invalid_customer_acceptance ) ) {
unlink( $this->test_file_invalid_customer_acceptance );
}
$this->remove_added_uploads();
}
//===================================================================================
/**
* Helper function : creates customer acceptance entry
*/
private function create_pending_customer_acceptance_entry(){
$customer_acceptance_form_id = 1;
$customer_id_field_id = 2;
$actual_date_field_id = 6;
$acceptance_status_field_id = 8;
$expiration_date_field_id = 9;
$decline_reason_field_id = 10;
$files_uploaded_field_id = 12;
$input_values['input_' . $acceptance_status_field_id] = 'accept';
$input_values['input_' . $expiration_date_field_id] = "2020-01-01";
//$input_values['input_' . $files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']);
GFAPI::submit_form($customer_acceptance_form_id, $input_values);
//this part is needed since form submit does not store files for some reason, probably files should be sent some other way
$entry = GFAPI::get_entries($customer_acceptance_form_id)[0];
$entry[$files_uploaded_field_id] = json_encode(['http://localhost/wp/index.php?gf-download=2018%2F08%2Ffile1.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534']);
$entry['workflow_step'] = 1;
$entry['workflow_step_status_1'] = 'pending';
$entry['workflow_step_status_2'] = false;
$entry['workflow_timestamp'] = false;
$update = GFAPI::update_entry($entry);
return $entry['id'];
}
}

View File

@@ -102,7 +102,7 @@ class Wiass_REST_User_Api_Test extends Wiaas_Unit_Test_Case {
$country = $data[0];
$this->assertNotNull($country);
$this->assertTrue(is_array($country));
$this->assertArrayHasKey('country_id', $country);
$this->assertArrayHasKey('country_name', $country);
$this->assertArrayHasKey('code', $country);
$this->assertArrayHasKey('name', $country);
}
}

View File

@@ -1,388 +0,0 @@
<?php
class Wiaas_Authentication_Test extends Wiaas_Unit_Test_Case {
var $user_id, $organization_id, $request_uri;
public function setUp() {
parent::setUp();
// set admin as current user
wp_set_current_user(1);
// create testing user
$this->user_id = wp_create_user('test', 'test', 'test@mail.com');
// create organization
$this->organization_id = wp_insert_term(
'test_organization',
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
update_user_meta($this->user_id, '_wiaas_organization_id', $this->organization_id);
# assign user to organization
wp_set_terms_for_user(
$this->user_id,
Wiaas_User_Organization::TAXONOMY_NAME,
[$this->organization_id]);
wp_set_current_user($this->user_id);
$this->request_uri = $_SERVER['REQUEST_URI'];
}
function tearDown() {
parent::tearDown();
wp_set_current_user(1);
wp_delete_user($this->user_id);
wp_delete_term(
$this->organization_id,
Wiaas_User_Organization::TAXONOMY_NAME);
delete_user_meta($this->user_id, '_wiaas_organization_id');
delete_user_meta($this->user_id, '_wiaas_current_user_admin_role');
$_SERVER['REQUEST_URI'] = $this->request_uri;
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_user_authentication_fail_when_no_selected_role() {
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
$this->assertTrue(
is_wp_error(
Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user())
)
);
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_user_authentication_forwards_error() {
// add roles to organization
$organization_roles = array( 'supplier', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user(false)
);
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_fail_when_organization_has_no_roles() {
$roles = array('administrator', 'supplier', 'customer', 'commercial_lead');
foreach ($roles as $role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $role);
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_fail_when_organization_has_different_roles() {
// add roles to organization
$organization_roles = array( 'supplier', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = array('administrator', 'commercial_lead');
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_valid_when_organization_has_requested_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertEquals(
$this->user_id,
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_invalid_when_organization_has_no_customer_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_valid_when_organization_has_customer_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertEquals(
$this->user_id,
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_if_no_role_posted() {
$user = wp_get_current_user();
$error = Wiaas_Authentication::authenticate_user_on_login($user);
$this->assertTrue(is_wp_error($error));
$this->assertEquals('You must selected role to login!', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_does_nothing_if_rest_request() {
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
$user = wp_get_current_user();
$response_user = Wiaas_Authentication::authenticate_user_on_login($user);
$this->assertEquals(
$user->ID,
$response_user->ID
);
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_if_customer_role_requested() {
$user = wp_get_current_user();
$_POST['role'] = 'customer';
$error = Wiaas_Authentication::authenticate_user_on_login($user);
$this->assertTrue(is_wp_error($error));
$this->assertEquals('No access!', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_when_user_has_no_organization() {
$_POST['role'] = 'supplier';
delete_user_meta($this->user_id, '_wiaas_organization_id');
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertTrue(is_wp_error($error));
$this->assertEquals('Account not completed!', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_when_organization_has_no_roles() {
$_POST['role'] = 'supplier';
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertTrue(is_wp_error($error));
$this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_when_organization_has_different_roles() {
// add roles to organization
$organization_roles = array( 'supplier', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$_POST['role'] = 'commercial_lead';
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertTrue(is_wp_error($error));
$this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_valid_when_organization_has_requested_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
foreach ($user_roles as $user_role) {
$_POST['role'] = $user_role;
$response_user = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertEquals(
$this->user_id,
$response_user->ID
);
}
}
/**
* @covers Wiaas_Authentication::maybe_filter_user_roles()
* @group authentication
*/
function test_user_has_customer_role_on_rest_request() {
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
global $wpdb;
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
null, $this->user_id,
$wpdb->get_blog_prefix() . 'capabilities'
);
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$user_roles = $user_roles[0];
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$this->assertArrayHasKey('customer', $user_roles);
$this->assertTrue($user_roles['customer']);
}
/**
* @covers Wiaas_Authentication::maybe_filter_user_roles()
* @group authentication
*/
function test_user_has_no_role_if_not_selected() {
global $wpdb;
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
null, $this->user_id,
$wpdb->get_blog_prefix() . 'capabilities'
);
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$user_roles = $user_roles[0];
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$this->assertEmpty(array_keys($user_roles)[0]);
}
/**
* @covers Wiaas_Authentication::maybe_filter_user_roles()
* @group authentication
*/
function test_user_has_selected_role() {
global $wpdb;
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
null, $this->user_id,
$wpdb->get_blog_prefix() . 'capabilities'
);
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$user_roles = $user_roles[0];
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$this->assertArrayHasKey('supplier', $user_roles);
$this->assertTrue($user_roles['supplier']);
}
}

View File

@@ -19,9 +19,7 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
'form_id' => $this->form_id,
));
$this->target_form_id = GFFormsModel::search_forms(
'DELIVERY ACTION TYPE: Manual',
true)[0]->id;
$this->target_form_id = Wiaas_Delivery_Process_Action::get_action_forms()[0]['id'];
$this->step = Gravity_Flow_Steps::create( array(
@@ -36,8 +34,8 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
), GFAPI::get_entry($form_entry_id));
}
private function _get_target_entry_meta_key() {
return 'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id';
private function _get_target_action_entries_meta_key() {
return 'wiaas_delivery_step_' . $this->step->get_id() .'_action_entry_ids';
}
/**
@@ -55,25 +53,9 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
$this->assertEquals($this->step->target_form_id, $this->target_form_id);
$this->assertEquals($this->step->get_label(), 'Wiaas Delivery Step');
$this->assertEquals($this->step->get_label(), 'Delivery Step');
#$this->assertEquals($step->is_visible_to_customer, true);
}
/**
* @covers Wiaas_Delivery_Process_Step::get_target_forms_choices
*/
function test_target_forms_choices_are_valid() {
$target_forms_choices = $this->step->get_target_forms_choices();
$available_action_types = Wiaas_Delivery_Process_Step::get_delivery_action_types();
$this->assertEquals(sizeof($target_forms_choices), sizeof($available_action_types));
foreach ($target_forms_choices as $target_forms_choice) {
$this->assertTrue(in_array($target_forms_choice->title, $available_action_types));
}
//$this->assertEquals($this->step->is_visible_to_customer, true);
}
/**
@@ -97,7 +79,7 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
);
$expected_meta = array(
'test' => 'test',
'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id' => null
'wiaas_delivery_step_' . $this->step->get_id() .'_action_entry_ids' => array()
);
$this->assertEquals($expected_meta, $this->step->get_entry_meta($meta, $this->step->get_form_id()));
@@ -109,12 +91,12 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
function test_process_with_no_target_form() {
$this->step->target_form_id = '';
$this->assertTrue($this->step->process());
$this->assertFalse($this->step->process());
# check that entry metadata is not updated
$target_entry_meta_key = $this->_get_target_entry_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
$this->assertFalse($value);
$target_action_entries_meta_key = $this->_get_target_action_entries_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_action_entries_meta_key);
$this->assertEmpty($value);
}
/**
@@ -125,46 +107,13 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
$this->assertFalse($this->step->process());
# check that entry metadata is updated with correct target entry value
$target_entry_meta_key = $this->_get_target_entry_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
$target_entry_id = absint($value);
$this->assertGreaterThan(0, $target_entry_id);
$target_action_entries_meta_key = $this->_get_target_action_entries_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_action_entries_meta_key);
//$this->assertNotEmpty($value);
# check that entry metadata key for target entry id points to valid entry
$entry = GFAPI::get_entry($target_entry_id);
$this->assertFalse(is_wp_error($entry));
}
/**
* @covers Wiaas_Delivery_Process_Step::status_evaluation
*/
function test_status_evaluation_with_no_target_form() {
$this->step->target_form_id = '';
$this->step->process();
$this->assertEquals($this->step->status_evaluation(), 'complete');
}
/**
* @covers Wiaas_Delivery_Process_Step::status_evaluation
*/
function test_status_evaluation_with_target_form() {
$this->step->process();
# check that step status is now pending
$this->assertEquals($this->step->status_evaluation(), 'pending');
# complete target entry workflow
$api = new Gravity_Flow_API( $this->step->target_form_id );
$target_form_entry = $this->step->get_target_form_entry();
$this->assertEquals($api->get_status($target_form_entry), 'pending');
gform_update_meta($target_form_entry['id'], 'workflow_role_administrator', 'approved');
$target_entry_current_step = $api->get_current_step($target_form_entry);
$target_entry_current_step->refresh_entry();
# check that step status is now complete
$this->assertEquals($this->step->status_evaluation(), 'complete');
// $entry = GFAPI::get_entry($target_entry_id);
//
// $this->assertFalse(is_wp_error($entry));
}
}

View File

@@ -1,156 +0,0 @@
<?php
/**
* Wiaas_Delivery_Process_Test
*
* @package Wiaas
*/
class Wiaas_Delivery_Process_Test extends Wiaas_Unit_Test_Case {
var $process_form, $step_form, $process_form_instance, $process_step, $process_form_workflow_api;
function setUp() {
parent::setUp();
$this->process_form = GFFormsModel::search_forms(
'DELIVERY PROCESS: Normal Delivery',
true)[0];
$this->step_form = GFFormsModel::search_forms(
'DELIVERY ACTION TYPE: Manual',
true)[0];
$process_form_instance_id = GFAPI::add_entry(array(
'form_id' => $this->process_form->id,
));
$this->process_form_instance = GFAPI::get_entry($process_form_instance_id);
$this->process_form_workflow_api = new Gravity_Flow_API( $this->process_form->id );
}
/**
* @covers Wiaas_Delivery_Process::create_delivery_process_for_order
*/
function test_delivery_process_for_order_created() {
$order = wc_create_order();
$order_id = $order->get_id();
Wiaas_Delivery_Process::create_delivery_process_for_order($order_id);
$order_process_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_id'));
$order_process_instance_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_entry_id'));
# check field populated
$this->assertGreaterThan(0, $order_process_id);
$this->assertGreaterThan(0, $order_process_instance_id);
}
/**
* @covers Wiaas_Delivery_Process::extend_gravity_form_entry_meta
*/
function test_gravity_form_entry_meta_extended() {
# create test entry with additional metadata
$entry = array(
'form_id' => $this->step_form->id,
'wiaas_delivery_process_id' => false,
);
$result = GFAPI::add_entry($entry);
# test that entry was successfully created
$this->assertFalse(is_wp_error($result));
}
/**
* @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
*/
function test_do_nothing_if_completed_workflow_has_no_parent() {
# Test there is no exception if entry has no parent process
$entry_id = GFAPI::add_entry(array(
'form_id' => $this->step_form->id
));
$this->assertFalse(
Wiaas_Delivery_Process::maybe_complete_parent_process_step(
$entry_id,
$this->step_form)
);
}
/**
* @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
*/
function test_process_parent_process_step_on_workflow_completion() {
# get process current step
$process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
# retrieve process steps
$process_steps = $this->process_form_workflow_api->get_steps($this->process_form);
$first_process_step = $process_steps[0];
$second_process_step = $process_steps[1];
# Check that current step is first step of corresponding process
$process_instance_current_step = $this->process_form_workflow_api->get_current_step($process_form_instance);
$this->assertEquals(
$process_instance_current_step->get_id(),
$first_process_step->get_id());
# Update step form entry to complete its workflow
$step_form_entry = $process_instance_current_step->get_target_form_entry();
gform_update_meta($step_form_entry['id'], 'workflow_role_administrator', 'approved');
# execute callback
Wiaas_Delivery_Process::maybe_complete_parent_process_step($step_form_entry['id'], null);
# refresh process instance and check we moved to next step
$process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
$this->assertEquals(
$this->process_form_workflow_api->get_current_step($process_form_instance)->get_id(),
$second_process_step->get_id());
}
/**
* @covers Wiaas_Delivery_Process::get_order_delivery_process()
*/
function test_get_order_delivery_process() {
$order = wc_create_order();
$order_id = $order->get_id();
$delivery_process = Wiaas_Delivery_Process::get_order_delivery_process($order_id);
$this->assertNotNull($delivery_process);
$steps = $delivery_process['steps'];
$this->assertNotNull($steps);
$this->assertTrue(is_array($steps));
foreach ($steps as $step) {
# test returned step is array
$this->assertTrue(is_array($step));
# test returned step properties
$this->assertArrayHasKey('step_id', $step);
$this->assertArrayHasKey('step_form_entry_id', $step);
$this->assertArrayHasKey('short_desc', $step);
$this->assertArrayHasKey('full_desc', $step);
$this->assertArrayHasKey('action_code', $step);
$this->assertArrayHasKey('step_type', $step);
$this->assertArrayHasKey('status', $step);
$this->assertArrayHasKey('order_id', $step);
$this->assertEquals($step['order_id'], $order_id);
# test that started steps have valid form entry
if ($step['status'] !== 'inactive') {
$process_instance = GFAPI::get_entry($step['step_form_entry_id']);
$this->assertFalse(is_wp_error($process_instance));
}
}
}
}

View File

@@ -129,30 +129,6 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$args['post_status']);
}
/**
* @covers Wiaas_Order::transform_rest_order()
*/
function test_order_rest_response_has_process() {
$order_response = array(
'customer_id' => $this->customer_id,
'status' => 'processing',
'line_items' => array()
);
$request = array( 'id' => $this->order_id);
$order_rest_response = new WP_REST_Response($order_response);
$order_rest_response = Wiaas_Order::transform_rest_order(
$order_rest_response,
wc_get_order($this->order_id),
$request);
$transformed_order_response = $order_rest_response->get_data();
$this->assertNotNull($transformed_order_response['delivery-process']);
$this->assertTrue(is_array($transformed_order_response['delivery-process']));
}
/**
* @covers Wiaas_Order::transform_rest_order()
*/
@@ -176,28 +152,4 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$this->assertArrayHasKey('email', $transformed_order_response['customer']);
$this->assertArrayHasKey('phone', $transformed_order_response['customer']);
}
/**
* @covers Wiaas_Order::transform_rest_order()
*/
function test_order_rest_response_has_commercial_lead_info() {
$order_response = array(
'customer_id' => $this->customer_id,
'status' => 'processing',
'line_items' => array()
);
$order_rest_response = Wiaas_Order::transform_rest_order(
new WP_REST_Response($order_response),
wc_get_order($this->order_id),
array( 'id' => $this->order_id));
$transformed_order_response = $order_rest_response->get_data();
$this->assertNotNull($transformed_order_response['commercial_lead']);
$this->assertTrue(is_array($transformed_order_response['commercial_lead']));
$this->assertArrayHasKey('name', $transformed_order_response['commercial_lead']);
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
}
}

View File

@@ -59,6 +59,8 @@ include_once WIAAS_DIR . '/includes/class-wiass-templates.php';
include_once WIAAS_DIR . '/includes/wiaas-class-measurement-units.php';
include_once WIAAS_DIR . '/includes/class-wiaas-validation.php';
function wiaas_redirect_to_login() {
wp_safe_redirect(get_site_url('', 'wp-login.php'));
}

View File

@@ -49,25 +49,24 @@
"johnpbloch/wordpress": "4.9.7",
"oscarotero/env": "1.1.0",
"roots/wp-password-bcrypt": "1.0.0",
"phpoffice/phpspreadsheet": "1.5",
"woocommerce/woocommerce": "3.5.0",
"3rdparty/woocommerce-product-bundles": "*",
"wpackagist-plugin/akismet": "4.0.3",
"wpackagist-plugin/hello-dolly": "1.6",
"woocommerce/woocommerce": "3.4.4",
"wpackagist-plugin/woocommerce-jetpack": "3.7.0",
"wpackagist-plugin/groups": "2.3.1",
"wpackagist-plugin/klarna-checkout-for-woocommerce": "1.5.2",
"wpackagist-plugin/mailchimp-for-woocommerce": "2.1.7",
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6",
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
"wpackagist-plugin/wp-user-groups": "2.2.0",
"wpackagist-plugin/radio-buttons-for-taxonomies": "1.8.3",
"wpackagist-plugin/advanced-access-manager": "5.4.3.2",
"wpackagist-plugin/advanced-custom-fields" : "5.7.7",
"wpackagist-plugin/radio-buttons-for-taxonomies": "1.8.3",
"wpackagist-plugin/sendgrid-email-delivery-simplified" : "1.11.8",
"3rdparty/gravityforms": "*",
"3rdparty/gravityflow": "*",
"3rdparty/woocommerce-product-bundles": "*"
"3rdparty/gravityflow": "*"
},
"require-dev": {
"vlucas/phpdotenv": "2.5.0"
@@ -90,16 +89,15 @@
"activate-plugins": [
"wp plugin activate woocommerce",
"wp plugin activate woocommerce-product-bundles",
"wp plugin activate woocommerce-jetpack",
"wp plugin activate jwt-authentication-for-wp-rest-api",
"wp plugin activate gravityforms",
"wp plugin activate gravityflow",
"wp plugin activate capability-manager-enhanced",
"wp plugin activate groups",
"wp plugin activate wp-user-groups",
"wp plugin activate radio-buttons-for-taxonomies",
"wp plugin activate advanced-access-manager",
"wp plugin activate advanced-custom-fields",
"wp plugin activate sendgrid-email-delivery-simplified",
"wp plugin activate wiaas"
],
"update-db": [
@@ -108,6 +106,9 @@
"wp wc update",
"wp wc pb update",
"wp wiaas update-db"
],
"timestamp": [
"php -r \"print date('YmdHis') . PHP_EOL;\" "
]
}
}

Some files were not shown because too many files have changed in this diff Show More