267 Commits

Author SHA1 Message Date
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
Almira Krdzic
5a6f876c69 Merge branch 'master' into package-reference 2018-10-19 21:01:05 +02:00
Nedim Uka
9b5cc3a978 Merge branch 'bundle-cost-summary' into 'master'
Bundle cost summary

See merge request saburly/wiaas/new-wiaas!35
2018-10-19 10:28:24 +00:00
Almira Krdzic
038b622eca Update product properties field 2018-10-19 12:27:25 +02:00
Almira Krdzic
e4ed26de7d add missing comma 2018-10-19 10:27:33 +02:00
Almira Krdzic
094a7bd56c Merge branch 'master' into package-reference 2018-10-19 10:19:45 +02:00
Almira Krdzic
67dc8d7d69 Hide unused tabs and render only edit link for package prices 2018-10-18 20:02:12 +02:00
Almira Krdzic
3ccea1804e Merge branch 'master' into bundle-cost-summary 2018-10-18 19:01:18 +02:00
Almira
315ac70484 Merge branch 'simple-product-details' into 'master'
Added manufacturer and supplyer product numbers

See merge request saburly/wiaas/new-wiaas!30
2018-10-18 17:00:28 +00:00
Nedim Uka
c4cddf8ace Added comment to save post method 2018-10-18 17:30:42 +02:00
Nedim Uka
00e853ae6b Fixed product status issue 2018-10-18 17:28:31 +02:00
Nedim Uka
071c549726 Impleneted search by country, and added mesurment unit 2018-10-18 16:45:26 +02:00
Almira Krdzic
d22ea58568 Import reference ui field 2018-10-18 13:36:45 +02:00
Almira Krdzic
d3c280548b customize column name for reference 2018-10-18 13:28:41 +02:00
Almira Krdzic
1ed7310994 handle package reference 2018-10-18 13:10:55 +02:00
Almira Krdzic
76e9b10235 Merge branch 'master' into bundle-cost-summary 2018-10-18 09:58:15 +02:00
Almira Krdzic
6b0dd0b5a9 handle bundle product prices editor and prices summary 2018-10-18 09:57:44 +02:00
Almira Krdzic
6d65a5f30c handle bundle product prices editor and prices summary 2018-10-18 09:57:38 +02:00
Bilal Catic
c8ed5f7ff8 Merge branch 'resseler-to-customer' into 'master'
Link customers to their respective (commercial leads/ resellers /shops)

See merge request saburly/wiaas/new-wiaas!34
2018-10-17 20:27:03 +00:00
Almira Krdzic
49281f02be remove error logs 2018-10-17 19:40:25 +02:00
Almira Krdzic
b7ab761a25 Handle bundle pricing on separate page 2018-10-17 19:38:41 +02:00
Almira Krdzic
0238f9140e Fixes 2018-10-17 17:45:33 +02:00
Almira Krdzic
4d13ee40bc Add descriptive comments 2018-10-17 14:02:35 +02:00
Almira Krdzic
6c27afabfc Merge branch 'master' into resseler-to-customer 2018-10-17 13:44:15 +02:00
Almira Krdzic
755fc75ae9 Filter linked organizations as customer 2018-10-17 11:31:09 +02:00
Nedim Uka
ecde654ae9 Merge branch 'commercial-lead-prices' into 'master'
Commercial lead prices

See merge request saburly/wiaas/new-wiaas!33
2018-10-17 09:29:54 +00:00
Almira Krdzic
8769606a4b Implement shop search and refactor 2018-10-17 00:36:19 +02:00
Almira Krdzic
ddf7d4452c Refactor admin cl interface and handle product access with groups 2018-10-16 16:57:48 +02:00
Almira Krdzic
554dc37a2d updated timestamp of role related db updates so they get triggered again 2018-10-16 06:49:57 +02:00
Almira Krdzic
afab22a30b reseller to customer 2018-10-16 06:45:28 +02:00
Almira Krdzic
dc1a1c64d2 Add default roles 2018-10-15 18:08:09 +02:00
Almira Krdzic
2d7b6c55e6 add view admin dashboard to cl 2018-10-15 17:22:58 +02:00
Almira Krdzic
d7103df6dc add view admin dashboard to cl 2018-10-15 17:21:30 +02:00
Almira Krdzic
b7ac53d195 use only customer specific prices if set 2018-10-15 14:59:57 +02:00
Almira Krdzic
f14d35b1aa Fix tests 2018-10-15 05:06:46 +02:00
Almira Krdzic
e810dd086a Merge branch 'master' into commercial-lead-prices 2018-10-15 00:31:24 +02:00
Bilal Catic
8789eb1426 Merge branch 'organization-access' into 'master'
Organization access

See merge request saburly/wiaas/new-wiaas!32
2018-10-14 22:27:52 +00:00
Almira Krdzic
bd724d12c2 Merge branch 'master' into organization-access 2018-10-15 00:25:11 +02:00
Almira
803e62ea69 Merge branch 'backoffice-max-cost-margin' into 'master'
Backoffice - max cost margin

See merge request saburly/wiaas/new-wiaas!31
2018-10-14 22:24:33 +00:00
Bilal Catic
a5168d3487 remove unnecessary code 2018-10-14 23:42:18 +02:00
Bilal Catic
d7c34c3b0b remove double code, change hook for validation 2018-10-14 23:38:38 +02:00
Bilal Catic
55dc87e174 check if taxonomy query exists and append if exists 2018-10-14 16:03:05 +02:00
Bilal Catic
9f3fe44bb1 add proper message when adding invalid package to cart 2018-10-14 15:31:27 +02:00
Bilal Catic
ba2629ca22 refactor 2018-10-14 14:46:35 +02:00
Bilal Catic
14eda981b7 add notice instead of throwing error 2018-10-14 14:24:06 +02:00
Bilal Catic
8df4ec3dc7 move package validation to seperate function 2018-10-14 14:19:22 +02:00
Almira Krdzic
17acc9d96a Error proof creating suppliers link to organization 2018-10-13 14:28:45 +02:00
Bilal Catic
4bdad78ed8 add tests 2018-10-12 11:15:41 +02:00
Bilal Catic
f3d911e5b1 remove debug logging 2018-10-12 11:15:41 +02:00
Bilal Catic
e4a7b28301 fix tests 2018-10-12 11:15:41 +02:00
Bilal Catic
84ba574bcb add detailed error message 2018-10-12 11:15:41 +02:00
Bilal Catic
4f31cc94e8 update package status on package update 2018-10-12 11:15:41 +02:00
Bilal Catic
bc74b504db fix const declaration 2018-10-12 11:15:41 +02:00
Bilal Catic
8d2b1e52b4 prevent checkout with invalid package 2018-10-12 11:15:41 +02:00
Bilal Catic
63c1ee945f prevent adding invalid package to cart 2018-10-12 11:15:41 +02:00
Bilal Catic
1e9f959b16 fetch only available packages 2018-10-12 11:15:41 +02:00
Bilal Catic
afe4ac1676 update package status on product update 2018-10-12 11:15:41 +02:00
Bilal Catic
c7e8a526e0 add custom package status 2018-10-12 11:15:16 +02:00
Bilal Catic
ac9c89e8eb update name to reflect logic behind margin 2018-10-12 11:15:16 +02:00
Bilal Catic
ea63870704 use minimum cost margin in pricing panel 2018-10-12 11:15:16 +02:00
Bilal Catic
accc359cbe handle bundle minimum cost margin read and update 2018-10-12 11:15:16 +02:00
Bilal Catic
57d61918b9 add minimum cost margin input box 2018-10-12 11:15:16 +02:00
Almira Krdzic
a830a47d31 retrieve all commercial leads on request 2018-10-11 07:52:10 +02:00
Almira Krdzic
61109e9bf0 Merge branch 'organization-access' into commercial-lead-prices 2018-10-11 07:27:32 +02:00
Almira Krdzic
c6a1f9837d Merge branch 'master' into organization-access 2018-10-11 07:14:33 +02:00
Almira
089bea5ce4 Merge branch 'suppliers-simple-product' into 'master'
Supplier

See merge request saburly/wiaas/new-wiaas!28
2018-10-11 05:13:43 +00:00
Almira Krdzic
b53fbe5402 Handle commercial lead prices 2018-10-11 07:12:53 +02:00
Almira Krdzic
84cd11f9c9 handle user roles by organization 2018-10-11 04:16:43 +02:00
Nedim Uka
a2656173c2 Connected supplier and organisation terms 2018-10-05 16:57:08 +02:00
Bilal Catic
9a8e05e341 Merge branch 'checkout-documents' into 'master'
Wiaas documents handling

See merge request saburly/wiaas/new-wiaas!29
2018-10-05 10:11:32 +00:00
Almira Krdzic
246788207b remove unused import 2018-10-04 18:36:53 +02:00
Nedim Uka
360b24c6ec Added Supplier taxonomy 2018-10-04 13:33:13 +02:00
Almira Krdzic
d11860223f Merge branch 'master' into checkout-documents 2018-10-04 13:22:26 +02:00
Almira
c537557daf Merge branch 'package-template-refactoring' into 'master'
Templates refactoring

See merge request saburly/wiaas/new-wiaas!26
2018-10-04 11:21:17 +00:00
Nedim Uka
c102b6a5ad Fixed template selection bug 2018-10-04 13:14:49 +02:00
Nedim Uka
f41252ea23 Services not listed bug fix 2018-10-04 12:54:34 +02:00
Nedim Uka
c5c07cbfae Fixed bug where template categoryes are not save properly in template 2018-10-04 12:41:17 +02:00
Nedim Uka
7ceac97fed Fixed template validation bug 2018-10-04 10:51:18 +02:00
Almira Krdzic
ab9ee2cb0d Checkout logic 2018-10-04 03:15:51 +02:00
Almira
451f9fb2eb Merge branch 'frontend-show-order-docuemnts' into 'master'
Display order documents in order details page

See merge request saburly/wiaas/new-wiaas!27
2018-10-03 18:46:28 +00:00
Nedim Uka
b028fb3f04 Removed error log 2018-10-03 16:58:52 +02:00
Almira Krdzic
3ad210f883 Handle wiaas documents 2018-10-03 16:46:41 +02:00
Nedim Uka
4c760b12c3 Added unit tests for templates 2018-10-01 17:03:24 +02:00
Bilal Catic
ea9a47fd39 create unit test 2018-09-30 21:37:34 +02:00
Bilal Catic
925896c469 don't show documents on other tabs 2018-09-30 21:37:34 +02:00
Bilal Catic
2cd4a77a34 rename props 2018-09-30 21:37:34 +02:00
Bilal Catic
174517a161 stop fetching data on view change 2018-09-30 21:37:34 +02:00
Bilal Catic
dc1311340f add documents property to order 2018-09-30 21:37:34 +02:00
Nedim Uka
f1c99c28ae Added documentation to methods 2018-09-28 14:24:47 +02:00
Nedim Uka
6f6fb1115a renamed variables to 2018-09-27 16:02:49 +02:00
Nedim Uka
93d03a96ee Refactored template product feature 2018-09-27 15:09:52 +02:00
Nedim Uka
21d96a0e55 Removed uneccesary code from wiaas admin panels.js 2018-09-27 15:09:52 +02:00
Nedim Uka
6afffc7eca Merge branch 'order-projects' into 'master'
CART: Order projects

See merge request saburly/wiaas/new-wiaas!25
2018-09-26 14:13:05 +00:00
Almira Krdzic
5f744f016e remove call to empty function 2018-09-26 16:06:21 +02:00
Almira Krdzic
0e59272689 Merge branch 'master' into order-projects 2018-09-26 16:03:15 +02:00
Almira
aa8aa42164 Merge branch 'login-bug' into 'master'
Replaced login screen with loader, wile validating access token

See merge request saburly/wiaas/new-wiaas!24
2018-09-26 14:02:32 +00:00
Almira Krdzic
415c5d8747 Remove empty function 2018-09-26 16:01:43 +02:00
Almira Krdzic
12805678b1 Change order project name sanitize function 2018-09-26 11:11:44 +02:00
Almira Krdzic
e1a1b4dc49 Fix filtering unavailable order projects 2018-09-25 13:47:25 +02:00
Almira Krdzic
4ecadc8bcc Fix error for html client response handling 2018-09-25 13:18:03 +02:00
Nedim Uka
eab040b13d Reduced loader size 2018-09-25 11:38:38 +02:00
Almira Krdzic
fdc01b974e Fix broken counting of orders inside order project 2018-09-24 22:19:21 +02:00
Almira Krdzic
11c26aeee1 Handle order project and refactor api 2018-09-24 21:51:55 +02:00
Nedim Uka
9c4539acfe Replaced login screen with loader, wile validating access token 2018-09-24 16:10:55 +02:00
Almira Krdzic
8cc2a7c8bc Merge branch 'master' into order-projects 2018-09-21 20:48:45 +02:00
Bilal Catic
c13983d6df Merge branch 'frontend-handle-page-refresh' into 'master'
add rewrite rule to apache for frontend

See merge request saburly/wiaas/new-wiaas!23
2018-09-20 12:33:53 +00:00
Bilal Catic
0065b25fef add rewrite rule to apache for frontend 2018-09-20 14:29:34 +02:00
Almira
d8c38ec089 Merge branch 'frontend-profileSettings' into 'master'
Frontend profile settings

See merge request saburly/wiaas/new-wiaas!20
2018-09-20 12:27:02 +00:00
Bilal Catic
cbf1de3403 modify test to use DELTE instead of POST 2018-09-20 14:08:32 +02:00
Bilal Catic
41e92e2390 use DELETE instead of POST for delete action 2018-09-20 13:57:01 +02:00
Bilal Catic
5da2353d04 add tests for profile endpoints 2018-09-20 13:39:25 +02:00
Bilal Catic
4159f12854 fix company info update 2018-09-20 13:39:25 +02:00
Bilal Catic
3fa75daafd fix typo 2018-09-20 13:39:25 +02:00
Bilal Catic
c637880245 fix personal info validation 2018-09-20 13:39:25 +02:00
Bilal Catic
fa2b691996 apply snake case change 2018-09-20 13:39:25 +02:00
Bilal Catic
393158808a snake case - camel case transformations 2018-09-20 13:39:25 +02:00
Bilal Catic
0787cf834f use snake case 2018-09-20 13:39:25 +02:00
Bilal Catic
522417ca28 use snake case 2018-09-20 13:39:25 +02:00
Bilal Catic
498f5526a9 use customer endpoint for profile actions 2018-09-20 13:39:25 +02:00
Bilal Catic
31115b7c6a add helper to transform snake case to camel case 2018-09-20 13:39:25 +02:00
Bilal Catic
af2da3eed0 add customer class and endpoint 2018-09-20 13:39:25 +02:00
GotPPay
d36398f2ab remove comment 2018-09-20 13:39:25 +02:00
GotPPay
32379f7f47 simple frontend address validation 2018-09-20 13:39:25 +02:00
GotPPay
82e4579e88 simple backend address validation 2018-09-20 13:39:25 +02:00
GotPPay
b93aed107b use new list of countries and adapt backend and frontend to it 2018-09-20 13:39:25 +02:00
GotPPay
5d91576fb7 turn off autocomplete also for billing address input/edit 2018-09-20 13:39:25 +02:00
GotPPay
c322c8ac78 display name, last name and email above address for profile addresses 2018-09-20 13:39:25 +02:00
GotPPay
90402d3e1d change property name to comply with frontend 2018-09-20 13:39:25 +02:00
GotPPay
84916a01ed add first name, last name and email fields to profile address on backend 2018-09-20 13:39:25 +02:00
GotPPay
b98f3c979c add aditional fields to profile address on frontend 2018-09-20 13:39:25 +02:00
GotPPay
a901da55fc Enable address changes in cart module 2018-09-20 13:39:25 +02:00
GotPPay
8a9af7ed8c keep old variable name 2018-09-20 13:39:25 +02:00
GotPPay
39cb851a55 change property name to comply with frontend 2018-09-20 13:39:25 +02:00
GotPPay
e6e487f312 add unit tests 2018-09-20 13:39:25 +02:00
GotPPay
d26569a8be create user class and make use of it 2018-09-20 13:39:25 +02:00
GotPPay
aae23e4ea3 improve frontend code 2018-09-20 13:39:25 +02:00
GotPPay
a79ef1044c user profile edit actions 2018-09-20 13:39:25 +02:00
GotPPay
b974eab225 add tests for rest-user-api 2018-09-20 13:39:25 +02:00
GotPPay
b3cff5d095 add list of available countries 2018-09-20 13:39:25 +02:00
GotPPay
4ce7b86ea9 update and read customer phone number, company name and VAT number 2018-09-20 13:39:25 +02:00
GotPPay
bc61e2e706 use custom user endpoint for validation and JWT auth for login 2018-09-20 13:39:25 +02:00
GotPPay
9da31990fd add user info to JWT token response 2018-09-20 13:39:25 +02:00
GotPPay
f63e118579 add user controller 2018-09-20 13:39:25 +02:00
Almira
cf92f62703 Merge branch 'templates' into 'master'
Package templates

See merge request saburly/wiaas/new-wiaas!16
2018-09-20 11:12:20 +00:00
Almira Krdzic
6e5f2af5a3 Started work on order projects 2018-09-20 10:32:05 +02:00
Bilal Catic
7c2a77b75d Merge branch 'wiaas-test' into 'master'
Wiaas test

See merge request saburly/wiaas/new-wiaas!22
2018-09-19 13:03:50 +00:00
Almira Krdzic
85deb1d9f8 Tests 2018-09-19 10:52:59 +02:00
Almira Krdzic
cae148ebce Packages and products countries test 2018-09-18 13:13:48 +02:00
241 changed files with 19915 additions and 4620 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

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

View File

@@ -0,0 +1,64 @@
#wpadminbar #wp-admin-bar-wiaas-view-as .ab-icon {
float: none;
margin-left: 10px;
color: rgba(240,245,250,0.7) !important;
}
#wpadminbar #wp-admin-bar-wiaas-view-as .ab-label {
font-weight: bold;
}
#wpadminbar #wp-admin-bar-wiaas-view-as a:not(:hover) .ab-icon:before {
color: rgba(240,245,250,0.7) !important;
}
#createuser .acf-taxonomy-field, #your-profile .acf-taxonomy-field {
width: 25em;
}
.wc-order-preview footer {
display: none;
}
.gravityflow-discussion-item{
margin-bottom:10px;
padding: 6px;
}
.gravityflow-dicussion-item-name {
color:black;
font-weight:bold;
}
.gravityflow-dicussion-item-date {
color: #9b9b9b;
margin-left:8px;
font-size:90%;
}
.rtl .gravityflow-dicussion-item-date {
margin-right:8px;
margin-left: 0;
}
.gravityflow-dicussion-item-toggle-display {
float: right;
}
.rtl .gravityflow-dicussion-item-toggle-display {
float: left;
}
@media print {
.gravityflow-dicussion-item-hidden {
display:block !important;
}
.gravityflow-dicussion-item-toggle-display {
display: none;
}
}
.gravityflow-dicussion-item-value {
padding: 10px;
}

View File

@@ -0,0 +1,11 @@
#posts-filter .tablenav .actions {
display: none;
}
#menu-posts-product .wp-submenu li:last-child {
display: none;
}
.woocommerce-BlankState .button {
display: none !important
}

View File

@@ -30,19 +30,9 @@
}
#wiaas_package_pricing_rules > .wiaas-pricing-rule {
border-color:#dfdfdf;
border-width:1px;
border-style:solid;
-moz-border-radius:3px;
-khtml-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
padding: 0;
border-style:solid;
border-spacing:0;
background-color:#F9F9F9;
margin-bottom: 12px;
margin-left: 12px;
border:1px #dfdfdf solid;
background-color:#fff;
width: 95%;
}
#wiaas_package_pricing_rules > .wiaas-pricing-rule .section {
@@ -120,4 +110,25 @@
#wiaas_package_option_groups_list .wiaas_option_group h3 {
background-color:#F9F9F9;
}
#createuser label[for="role"], #createuser label[for="url"], #createuser #role, #createuser #url{
display: none;
}
#your-profile label[for="role"], #your-profile label[for="url"],#your-profile #role, #your-profile #url{
display: none;
}
#adminmenu #toplevel_page_wiaas-cl-packages div.wp-menu-image::before {
font-family: WooCommerce!important;
content: '\e006';
}
.wiaas-package-error {
color: #a00 !important;
}
table.wp-list-table .column-price {
width: auto !important;
}

View File

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

View File

@@ -0,0 +1,71 @@
jQuery(document).ready(function ($) {
$('#tabs').each(function() {
var disabled = $( this ).data('disabled') || '';
$( this ).tabs({
disabled: [ disabled ]
});
});
$('#wiaas_add_cl_customer_extras').click(function(e) {
e.preventDefault();
var customer_id = $('#wiaas_cl_customers').val();
if (!customer_id || customer_id === '0') {
return;
}
$.post(window.ajaxurl, {
action: 'wiaas_create_cl_customer_extras',
_ajax_nonce: $('#wiaas_create_cl_customer_extras_nonce').val(),
customer_id: customer_id,
package_id: $('#wiaas_cl_package_id').val()
}).done( function (result) {
$('#tabs-2').append(result);
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', true );
});
$('#wiaas_cl_customers').val('0');
});
$('#wiaas_package_extras').delegate('.wiaas_remove_cl_extras', 'click', function(e) {
e.preventDefault();
var customer_id = $( this ).data('customer_id');
$('#extras_customer_' + customer_id).remove();
$('#wiaas_cl_customer_' + customer_id).prop( 'disabled', false );
$('#wiaas_cl_customers').val('0');
});
$('#wiaas_package_extras').delegate('.wiaas-cl-extra-input', 'change', function(e) {
e.preventDefault();
var val = parseFloat($( this ).val());
var target = '#' + $( this).data('target');
if (isNaN(val)) {
$(target).val('Invalid!');
return;
}
var type = $( this).data('type');
if (type === 'fixed') {
$(target).text( $(target).data('base') + val);
}
if (type === 'recurrent' || type === 'services') {
$(target).data(type, val);
$(target).text( $(target).data('base') + $(target).data('recurrent') + $(target).data('services'));
}
});
});

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

@@ -0,0 +1,150 @@
jQuery(document).ready(function ($) {
$("#wiaas-add-pricing").click(function (event) {
event.preventDefault();
var pay_type = $('#wiaas_pay_types').val();
if (! pay_type) {
return;
}
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
$("#wiaas_package_pricing_rules").data('setindex', set_index);
var data = {
'pay_type': pay_type,
action: 'create_empty_pricing_rule'
};
$.post(ajaxurl, data, function (response) {
$('#wiaas_package_pricing_rules').append(response);
$(`#wiaas_pay_type_${pay_type}`).prop( 'disabled', true );
$('#wiaas_pay_types').val('0');
});
});
//Remove Pricing Type
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
event.preventDefault();
if (confirm('Are you sure you would like to remove this pay type?')) {
var name = $(this).data('name');
$('#wiaas-pricing-rule-' + name).slideUp().remove();
// append new option to controls
$(`#wiaas_pay_type_${name}`).prop( 'disabled', false );
}
});
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
event.preventDefault();
var minimal_services_price = parseFloat($(this).val()) || 0;
var principal_amount = 0;
var name = $(this).data('name');
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
if (principal_amount_input) {
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
}
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
var services_contract_period = $(this).data('period');
if (services_contract_period > 0) {
var final_services_price = minimal_services_price * services_contract_period;
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
}
});
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
event.preventDefault();
var value = parseFloat($(this).val());
var period = parseFloat($(this).data('period'));
var interestRate = 0.58;
var principal_amount = wiaasCalculateFinancing(interestRate, period, value);
var minimal_services_price = 0;
var name = $(this).data('name');
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
if (minimal_services_price_input) {
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
}
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(0));
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(0));
});
$('#wiaas_package_pricing_editor').delegate('#wiaas_pricing_rules_commision', 'change', function(event) {
event.preventDefault();
var value = parseInt($(this).val());
$('#wiaas_pricing_rules_commission_details').text('Commercial lead: ' + (100 - value) + ' %');
});
$('#wiaas_package_pricing_editor').delegate('#wiaas_pricing_rules_max_cost_margin', 'change', function(event) {
event.preventDefault();
var value = parseFloat($(this).val());
var total = parseFloat($(this).data('total'));
if (value > 0 && value < total) {
$('#wiaas_pricing_rules_max_cost_margin_error').show();
} else {
$('#wiaas_pricing_rules_max_cost_margin_error').hide();
}
});
/**
* Copy of Excel's PMT function.
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
*
* @param ratePerPeriod The interest rate for the loan.
* @param numberOfPayments The total number of payments for the loan in months.
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
* Also known as the principal.
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
* 0 = At the end of period
* 1 = At the beginning of the period
* @returns {number}
*/
function wiaasCalculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
/*var q = 0;
var c = 0;
const monthlyRatePerPeriod = ratePerPeriod / 12;
if (monthlyRatePerPeriod !== 0.0) {
// Interest rate exists
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
return c.toFixed(2);
} else if (numberOfPayments !== 0.0) {
// No interest rate, but number of payments exists
return -(futureValue + presentValue) / numberOfPayments;
}
return 0;*/
const rates = {
24 : 4.282,
30 : 3.451,
36 : 2.896,
42 : 2.500,
48 : 2.223,
54 : 2.025,
60 : 1.834
};
const interest = rates[numberOfPayments] || 10;
return presentValue * (interest / 100);
}
});

View File

@@ -0,0 +1,57 @@
jQuery(document).ready(function($) {
if ($('#product-type').val() === 'simple') {
$('#general_product_data').find('.pricing').show();
} else {
$('#general_product_data').find('.pricing').hide();
}
$('#general_product_data').find('.pricing').addClass('hide_if_wiaastemplate hide_if_bundle');
$('#general_product_data').find('.pricing').removeClass('show_if_bundle show_if_wiaastemplate');
$( '.wiaas-search-documents' ).each(function() {
var element = $( this );
var searchTarget = $('#' + element.data('target'));
element.autocomplete({
source: function(request, response) {
$.get( window.ajaxurl, {
action: 'wiaas_json_search_documents',
query: request.term,
_ajax_nonce: element.data('search-nonce')
} ).done( function( documents ) {
response( documents || []);
}
);
},
select: function(event, ui) {
if (!searchTarget || $('#wiaas_attached_document_' + ui.item.id).length) {
return;
}
$.get(window.ajaxurl, {
action: 'wiaas_link_document',
_ajax_nonce: element.data('link-nonce'),
id: ui.item.id
}).done( function (document) {
searchTarget.find('tbody').append(document);
});
}
})
.autocomplete( 'instance' )._renderItem = function( ul, item ) {
return $( '<li role="option" id="wiaas-document-autocomplete-' + item.id + '">' )
.text( item.name )
.appendTo( ul );
};
});
$('#wiaas_attached_documents').delegate('.wiaas-remove-attached-document', 'click', function (e) {
e.preventDefault();
var id = $(this).data('id');
$('#wiaas_attached_document_' + id).remove();
});
});

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

@@ -1,76 +1,23 @@
jQuery(function ($) {
var $edit_in_cart = $('.bundle_edit_in_cart'),
$group_mode_select = $('select#_wc_pb_group_mode'),
$bundled_products_panel = $('#bundled_product_data'),
$bundled_products_toolbar = $bundled_products_panel.find('.toolbar'),
$template_products_container_hardware = $('.wiaas-template-items_hardware'),
$template_products_container_software = $('.wiaas-template-items_software'),
$template_products_container_services = $('.wiaas-template-items_services'),
$template_products_container_isntallation = $('.wiaas-template-items_installation'),
var $template_categories_container_hardware = $('.wiaas-template-items_hardware'),
$template_categories_container_software = $('.wiaas-template-items_software'),
$template_categories_container_services = $('.wiaas-template-items_services'),
$template_categories_container_isntallation = $('.wiaas-template-items_installation'),
$template_products = $('.wc-bundled-item',
$template_products_container_services,
$template_products_container_software,
$template_products_container_hardware,
$template_products_container_isntallation),
$template_categories = $('.wc-bundled-item',
$template_categories_container_services,
$template_categories_container_software,
$template_categories_container_hardware,
$template_categories_container_isntallation),
$template_search_hardware = $('#wiaastemplate_products_hardware'),
$template_search_software = $('#wiaastemplate_products_software'),
$template_search_services = $('#wiaastemplate_products_services'),
$template_search_installation = $('#wiaastemplate_products_installation'),
bundled_product_objects = {},
bundled_products_add_count = $template_products.length,
block_params = {
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
};
template_category_objects = {},
template_category_add_count = $template_categories.length;
$.fn.wc_bundles_select2 = function () {
$(document.body).trigger('wc-enhanced-select-init');
};
// Bundle type move stock msg up.
$('.bundle_stock_msg').appendTo('._manage_stock_field .description');
// Simple type options are valid for bundles.
$('.show_if_simple:not(.hide_if_bundle)').addClass('show_if_bundle');
$('body').on('woocommerce-product-type-change', function (event, select_val) {
if ('bundle' === select_val) {
$('.show_if_external').hide();
$('.show_if_bundle').show();
$('input#_manage_stock').change();
$('#_nyp').change();
}
});
$group_mode_select.change(function () {
if ($.inArray($group_mode_select.val(), wc_bundles_admin_params.group_modes_with_parent) === -1) {
$edit_in_cart.hide();
} else {
$edit_in_cart.show();
}
});
// Downloadable support.
$('input#_downloadable').change(function () {
$('select#product-type').change();
});
// Trigger product type change.
$('select#product-type').change();
// Trigger group mode change.
$group_mode_select.change();
init_event_handlers();
@@ -81,52 +28,50 @@ jQuery(function ($) {
$template_search_hardware
.on('change', function () {
addSearchedProduct('hardware', $template_search_hardware, $template_products_container_hardware)
addSearchedTemplateCategory('hardware', $template_search_hardware, $template_categories_container_hardware)
});
$template_search_software
.on('change', function () {
addSearchedProduct('software', $template_search_software, $template_products_container_software)
addSearchedTemplateCategory('software', $template_search_software, $template_categories_container_software)
});
$template_search_installation
.on('change', function () {
addSearchedProduct('services', $template_search_installation, $template_products_container_isntallation)
addSearchedTemplateCategory('installation', $template_search_installation, $template_categories_container_isntallation)
});
$template_search_services
.on('change', function () {
addSearchedProduct('installation', $template_search_services, $template_products_container_services)
addSearchedTemplateCategory('services', $template_search_services, $template_categories_container_services)
});
function addSearchedProduct(options, search, container) {
var bundled_product_ids = search.val(),
bundled_product_id = bundled_product_ids && bundled_product_ids.length > 0 ? bundled_product_ids.shift() : false;
function addSearchedTemplateCategory(options, search, container) {
var template_category_ids = search.val(),
template_category_id = template_category_ids && template_category_ids.length > 0 ? template_category_ids.shift() : false;
var template_category_title =search.text();
if (!bundled_product_id) {
if (!template_category_id) {
return false;
}
search.val([]).change();
$bundled_products_panel.block(block_params);
bundled_products_add_count++;
template_category_add_count++;
var data = {
action: 'wiaas_add_template_product',
post_id: woocommerce_admin_meta_boxes.post_id,
id: bundled_products_add_count,
id: template_category_add_count,
title: template_category_title,
product_id: bundled_product_id,
template_category_id: template_category_id,
security: wc_bundles_admin_params.add_bundled_product_nonce,
options: options,
};
@@ -140,13 +85,11 @@ jQuery(function ($) {
container.append(response.markup);
var $added = $('.wiaas-template-item', container).last(),
added_id = 'bundled_item_' + bundled_products_add_count;
added_id = 'bundled_item_' + template_category_add_count;
$added.data('bundled_item_id', added_id);
$added.wc_bundles_select2();
$bundled_products_panel.trigger('wc-bundles-added-bundled-product');
} else if (response.message !== '') {
window.alert(response.message);
}
@@ -161,8 +104,6 @@ jQuery(function ($) {
}
search.text('');
$bundled_products_panel.unblock();
});
}, 250);
@@ -170,7 +111,7 @@ jQuery(function ($) {
return false;
}
$template_products_container_isntallation
$template_categories_container_isntallation
// Remove Item.
.on('click', 'a.remove_row', function (e) {
@@ -181,15 +122,13 @@ jQuery(function ($) {
$el.find('*').off();
$el.remove();
delete bundled_product_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
delete template_category_objects[el_id];
e.preventDefault();
});
$template_products_container_hardware
$template_categories_container_hardware
// Remove Item.
.on('click', 'a.remove_row', function (e) {
@@ -200,15 +139,13 @@ jQuery(function ($) {
$el.find('*').off();
$el.remove();
delete bundled_product_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
delete template_category_objects[el_id];
e.preventDefault();
});
$template_products_container_software
$template_categories_container_software
// Remove Item.
.on('click', 'a.remove_row', function (e) {
@@ -219,15 +156,13 @@ jQuery(function ($) {
$el.find('*').off();
$el.remove();
delete bundled_product_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
delete template_category_objects[el_id];
e.preventDefault();
});
$template_products_container_services
$template_categories_container_services
// Remove Item.
.on('click', 'a.remove_row', function (e) {
@@ -238,9 +173,7 @@ jQuery(function ($) {
$el.find('*').off();
$el.remove();
delete bundled_product_objects[el_id];
$bundled_products_panel.triggerHandler('wc-bundled-products-changed');
delete template_category_objects[el_id];
e.preventDefault();

View File

@@ -0,0 +1,79 @@
<?php
/**
* Class Wiaas_Admin_CL_Customers
*/
class Wiaas_Admin_CL_Customers {
/**
* Displays table list of customers that are linked to commercial lead
*
* Enables commercial lead to update default order type for his shop
*
* Enables commercial lead to update order type for specific shop customer
*
*/
public static function init() {
add_action( 'admin_menu', array( __CLASS__, 'add_customers_page' ), 9 );
}
/**
* Add customer menu page for commercial lead
*/
public static function add_customers_page() {
add_menu_page(
__( 'Customers', 'wiaas' ),
__( 'Customers', 'wiaas' ),
'manage_wiaas_cl_customers',
'wiaas-cl-customers',
array(__CLASS__, 'output_customers'),
'dashicons-groups',
'66.0' );
}
/**
* Render content for customer menu page
*/
public static function output_customers() {
$organization_id = wiaas_get_current_user_organization_id();
// handle default order type update if needed
if (! empty($_POST['wiaas_update_cl_default_order_type_nonce']) &&
! empty($_POST['default_order_type']) &&
wp_verify_nonce(
$_POST['wiaas_update_cl_default_order_type_nonce'],
'wiaas_update_cl_default_order_type')
) {
$default_order_type = sanitize_key($_POST['default_order_type']);
Wiaas_Shop::update_default_order_type($organization_id, $default_order_type);
}
// handle customer order type update if needed
if (! empty($_POST['wiaas_update_cl_customer_order_type_nonce']) &&
! empty($_POST['customer_order_type']) &&
wp_verify_nonce(
$_POST['wiaas_update_cl_customer_order_type_nonce'],
'wiaas_update_cl_customer_order_type')
) {
$customer_id = absint($_POST['customer_order_type']['customer_id']);
$order_type = sanitize_key($_POST['customer_order_type']['order_type']);
Wiaas_Shop::update_shop_customer_order_type(
$organization_id,
$customer_id,
$order_type);
}
$customers = Wiaas_Shop::get_shop_customers($organization_id);
require 'views/html-admin-cl-customers-page.php';
}
}
Wiaas_Admin_CL_Customers::init();

View File

@@ -0,0 +1,126 @@
<?php
/**
* Class Wiaas_Admin_CL_Orders
*/
class Wiaas_Admin_CL_Orders {
/**
* Displays list of orders from commercial lead owned shop
*
* Enables quick preview of each order
*
* This list of orders is achieved with customization of default order list for `shop_order` post
* by using hooks and filters to allow only data that commercial lead should be able to see
*
*/
public static function init() {
add_filter( 'bulk_actions-edit-shop_order', array( __CLASS__, 'remove_bulk_actions_for_list_table_orders' ), 999 );
add_filter('woocommerce_admin_order_preview_actions', array(__CLASS__, 'remove_actions_from_order_preview'));
add_filter('woocommerce_admin_order_preview_line_items', array(__CLASS__, 'filter_order_items_for_order_preview'), 10, 2);
add_filter('manage_shop_order_posts_columns', array(__CLASS__, 'columns_for_list_table_orders'), 999);
add_filter( 'manage_edit-shop_order_sortable_columns', array( __CLASS__, 'define_sortable_columns_for_list_table_orders' ) );
add_action('manage_shop_order_posts_custom_column', array(__CLASS__, 'render_columns_for_list_table_orders'), 999, 2);
}
/**
* Remove all bulk actions for commercial lead
*
* @return array
*/
public static function remove_bulk_actions_for_list_table_orders() {
return array();
}
/**
* Remove actions from shop order preview modal so only data info is visible
*
* @return array
*/
public static function remove_actions_from_order_preview() {
return array();
}
/**
* Show only packages on order preview
*
* @param $order_items
* @param $order
*
* @return array
*/
public static function filter_order_items_for_order_preview($order_items, $order) {
$items = array();
foreach ($order_items as $order_item) {
if (isset($order_item['wiaas_standard_package'])) {
$items[] = $order_item;
}
}
return $items;
}
/**
* Override default table columns so only commercial lead specific columns are visible
*
* @param $columns
*
* @return array
*/
public static function columns_for_list_table_orders($columns) {
$show_columns = array();
$show_columns['cb'] = $columns['cb'];
$show_columns['_wiaas_order_number'] = __( 'Order', 'woocommerce' );
$show_columns['order_date'] = __( 'Date', 'woocommerce' );
$show_columns['order_status'] = __( 'Status', 'woocommerce' );
$show_columns['order_total'] = __( 'Total', 'woocommerce' );
return $show_columns;
}
/** Append commercial lead columns to table sortable columns
*
* @param $sortable_columns
*
* @return mixed
*/
public static function define_sortable_columns_for_list_table_orders($sortable_columns) {
$sortable_columns['_wiaas_order_number'] = 'ID';
return $sortable_columns;
}
/**
* Render commercial lead specific columns
*
* @param $column
* @param $order_id
*/
public static function render_columns_for_list_table_orders($column, $order_id) {
if ($column === '_wiaas_order_number') {
$order = wc_get_order($order_id);
echo '<strong>#' . esc_attr( $order->get_order_number() ) . '</strong>';
if ( $order->get_status() !== 'trash' ) {
echo '<a href="#" class="order-preview" data-order-id="' . absint( $order->get_id() ) . '" title="' . esc_attr( __( 'Preview', 'wiaas' ) ) . '">' . esc_html( __( 'Preview', 'wiaas' ) ) . '</a>';
}
}
}
}
Wiaas_Admin_CL_Orders::init();

View File

@@ -0,0 +1,259 @@
<?php
/**
* Class Wiaas_Admin_CM_Packages
*
*/
class Wiaas_Admin_CL_Packages {
/**
* Handles output of Commercial Lead packages page in admin panel.
*
* Shows list of packages available for sale and packages sold by current commercial lead.
* Enables adding package to commercial lead catalogue and setting package specific prices
* for current commercial lead.
*
*/
public static function init() {
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
add_action( 'admin_menu', array(__CLASS__, 'add_cl_packages_menu') );
add_action( 'admin_head', array( __CLASS__, 'menu_highlight' ) );
add_filter( 'manage_product_posts_columns', array( __CLASS__, 'define_list_table_products_columns' ), 999 );
add_filter( 'bulk_actions-edit-product', array( __CLASS__, 'define_list_table_products_bulk_actions' ), 999 );
add_filter( 'views_edit-product', array( __CLASS__, 'define_list_table_products_views' ), 999 );
add_filter( 'post_row_actions', array( __CLASS__, 'define_list_table_products_row_actions' ), 999, 2 );
add_filter( 'list_table_primary_column', array( __CLASS__, 'define_list_table_products_primary_column' ), 999, 2 );
add_action( 'manage_product_posts_custom_column', array( __CLASS__, 'render_list_table_products_columns' ), 10, 2 );
}
public static function enqueue_scripts() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
}
public static function add_cl_packages_menu() {
add_submenu_page(
'edit.php?post_type=product',
__( 'Products', 'wiaas' ),
null,
'manage_wiaas_cl_products',
'wiaas-cl-package',
array(__CLASS__, 'output_package')
);
}
public static function menu_highlight() {
global $parent_file;
$screen = get_current_screen();
if ($screen->id === 'admin_page_wiaas-cl-product') {
$parent_file = 'edit.php?post_type=product';
}
}
public static function output_package() {
wp_enqueue_script( 'jquery-ui-tabs' );
$package_id = absint( $_GET['cl_package_id'] );
$package = wc_get_product($package_id);
if (!$package) {
return;
}
if (! empty($_POST['wiaas_save_cl_extras_nonce']) && ! empty($_POST['cl_extras'])) {
if (wp_verify_nonce($_POST['wiaas_save_cl_extras_nonce'], 'wiaas_save_cl_extras')) {
self::_handle_cl_extras_update($package_id);
}
}
$bundled_items = $package->get_bundled_items();
$bundled_items_per_category = array();
foreach ($bundled_items as $bundled_item) {
$category = Wiaas_Product_Category::get_category($bundled_item->product);
if (isset($category)) {
if ($category ==='hardware' || $category === 'software') {
$category = 'products';
}
$bundled_items_per_category[$category] ?: array();
$bundled_items_per_category[$category][] = $bundled_item;
}
}
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
$cl_id = wiaas_get_current_user_organization_id();
$cl_extras = Wiaas_Package_CL_Pricing::get_extras($cl_id, $package_id);
$has_default_cl_extras = ! empty($cl_extras);
// default values for catalogue package
if (! $has_default_cl_extras) {
$cl_extras = array();
foreach ($configured_prices as $type => $configured_price) {
$cl_extras[$type.'_default'] = array(
'visible' => true,
'fixed' => 0,
'services' => 0,
'recurrent' => 0
);
}
}
$package_cl_extra_types = array_keys($cl_extras);
$customer_ids_with_extras = array();
foreach ($package_cl_extra_types as $package_cl_extra_type) {
$customer_id_with_extras = explode('_customer_', $package_cl_extra_type)[1];
if (isset($customer_id_with_extras) && ($customer_id_with_extras = absint($customer_id_with_extras)) > 0) {
$customer_ids_with_extras[] = $customer_id_with_extras;
}
}
$customer_ids_with_extras = array_unique($customer_ids_with_extras);
require 'views/html-cl-package-details.php';
}
/**
* @section Customize display of list table products for commercial lead
*/
/**
* Define columns for commercial lead view
* @param array $columns
*
* @return array
*/
public static function define_list_table_products_columns($columns) {
$cl_columns = array();
$cl_columns['thumb'] = $columns['thumb'];
$cl_columns['wiaas_cl_name'] = $columns['name'];
$cl_columns['taxonomy-product_tag'] = __( 'Reference', 'wiaas' );
$cl_columns['taxonomy-package_type'] = __('Type', 'wiaas');
$cl_columns['taxonomy-package_status'] = __('Status', 'wiaas');
$cl_columns['taxonomy-product_country'] = $columns['taxonomy-product_country'];
$cl_columns['date'] = $columns['date'];
return $cl_columns;
}
/**
* Hide list table products bulk actions for commercial lead view
*
* @return array
*/
public static function define_list_table_products_bulk_actions() {
return array();
}
/**
* Hide list table products views for commercial lead view
*
* @return array
*/
public static function define_list_table_products_views() {
return array();
}
/**
* Show only ID in table products views for commercial lead view
*
* @return array
*/
public static function define_list_table_products_row_actions($actions, $post) {
if ($post->post_type === 'product') {
return array( 'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $post->ID ) );
}
return $actions;
}
/**
* Define custom primary column in list table products for commercial lead view
*
* @param $default
* @param $screen_id
*
* @return string
*/
public static function define_list_table_products_primary_column($default, $screen_id) {
if ( 'edit-product' === $screen_id ) {
return 'wiaas_cl_name';
}
return $default;
}
public static function render_list_table_products_columns($column, $post_id) {
if ($column === 'wiaas_cl_name') {
$package = wc_get_product($post_id);
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-cl-package&cl_package_id=' . absint( $package->get_id() ) );
echo '<strong><a class="row-title" href="' . esc_url( $edit_link ) . '">' . esc_html( $package->get_title() ) . '</a></strong>';
}
}
// PRIVATE HANDLERS
private static function _handle_cl_extras_update($package_id) {
$cl_extras = wp_unslash($_POST['cl_extras']);
$pay_types = array_keys(Wiaas_Package_Pricing::get_available_pay_types());
$posted_cl_extras = array();
foreach ($cl_extras as $cl_extra) {
$customer_id = isset($cl_extra['customer']) ? absint($cl_extra['customer']) : 0;
$type = sanitize_key($cl_extra['type']);
$fixed_extra = isset($cl_extra['fixed']) ? floatval($cl_extra['fixed']) : 0;
$services_extra = isset($cl_extra['services']) ? floatval($cl_extra['services']) : 0;
$recurrent_extra = isset($cl_extra['recurrent']) ? floatval($cl_extra['recurrent']) : 0;
$extra_type = $customer_id > 0 ? $type.'_customer_'.$customer_id : $type.'_default';
if (in_array($type, $pay_types)) {
$posted_cl_extras[$extra_type] = array(
'type' => $type,
'visible' => $cl_extra['visible'] === 'on',
'fixed' => $fixed_extra,
'services' => $services_extra,
'recurrent' => $recurrent_extra,
);
}
}
Wiaas_Package_CL_Pricing::set_extras(
wiaas_get_current_user_organization_id(),
$package_id,
$posted_cl_extras
);
}
}
Wiaas_Admin_CL_Packages::init();

View File

@@ -0,0 +1,126 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<style>
select {
width: 300px;
max-width: 100%;
}
</style>
<div class="wrap">
<h1><?php esc_html_e( 'Customers', 'wiaas' ); ?> </h1>
<br class="clear" />
<div id="col-container">
<div id="col-right">
<div class="col-wrap">
<table class="widefat wp-list-table striped" style="width:100%">
<thead>
<tr>
<th scope="col"><?php esc_html_e( 'Name', 'wiaas' ); ?></th>
<th scope="col"><?php esc_html_e( 'Order type', 'wiaas' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($customers as $customer) {
$name = wiaas_get_organization_name($customer['customer_id']);
?>
<tr>
<td>
<h2><?php esc_html_e($name, 'wiaas') ?></h2>
</td>
<td>
<?php
esc_html_e(
$customer['order_type']=== 'commercial_lead' ? 'Commercial Lead' : 'Reseller',
'wiaas'
)
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<div id="col-left">
<div class="col-wrap">
<div class="inside">
<div class="form-wrap">
<h2><?php esc_html_e('Default order type:', 'wiaas') ?></h2>
<form class="form" action="" method="post">
<input type="hidden" name="page" value="wiaas-cl-customers"/>
<div class="form-field">
<select class="form-control" name="default_order_type">
<option
value="commercial_lead"
<?php selected('commercial_lead', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
>
<?php esc_html_e('Commercial Lead', 'wiaas') ?>
</option>
<option
value="reseller"
<?php selected('reseller', Wiaas_Shop::get_default_order_type($organization_id), true) ?>
>
<?php esc_html_e('Reseller', 'wiaas') ?>
</option>
</select>
</div>
<input class="button button-primary button-large" type="submit" value="Change"/>
<?php wp_nonce_field( 'wiaas_update_cl_default_order_type', 'wiaas_update_cl_default_order_type_nonce' ); ?>
</form>
</div>
<hr style="margin: 30px 0;" />
<div class="form-wrap">
<h2><?php esc_html_e('Update order type for customer', 'wiaas') ?></h2>
<form class="form" action="" method="post">
<div class="form-field">
<label><?php esc_html_e('Customer:', 'wiaas') ?> </label>
<select class="form-control" name="customer_order_type[customer_id]">
<?php
foreach ($customers as $customer) {
$name = wiaas_get_organization_name($customer['customer_id']);
?>
<option
value="<?php esc_html_e($customer['customer_id'], 'wiaas') ?>"
>
<?php esc_html_e($name, 'wiaas') ?>
</option>
<?php
}
?>
</select>
</div>
<div class="form-field">
<label><?php esc_html_e('Order type:', 'wiaas') ?> </label>
<select class="form-control" name="customer_order_type[order_type]">
<option value="commercial_lead">
<?php esc_html_e('Commercial Lead', 'wiaas') ?>
</option>
<option value="reseller">
<?php esc_html_e('Reseller', 'wiaas') ?>
</option>
</select>
</div>
<input class="button button-large" type="submit" value="Update"/>
<?php wp_nonce_field( 'wiaas_update_cl_customer_order_type', 'wiaas_update_cl_customer_order_type_nonce' ); ?>
</form>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,237 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<style>
#tabs-navigation {
height: 30px;
}
#tabs-navigation > li {
float: left;
line-height: 30px;
font-weight: bold;
}
#tabs-navigation > li.ui-state-active > a {
color: #000;
}
#tabs-navigation > li.ui-state-disabled > a {
color: #ccc;
cursor: default;
}
#tabs-navigation > li > a {
text-decoration: none;
padding: .5em;
}
.wiaas-configured-prices > thead {
background: #f2f2f2;
}
.wiaas-configured-prices > thead td {
vertical-align: middle;
position: relative;
}
.wiaas-configured-prices > thead i {
position: absolute;
vertical-align: top;
right: -8px;
top: -8px;
cursor: pointer;
}
.wiaas-configured-prices > tbody > tr > td {
vertical-align: middle;
}
.wiaas-configured-prices > tbody > tr > td:first-child {
max-width: 100px;
vertical-align: middle;
}
.wiaas-configured-prices > tbody > tr > td:nth-child(2) label {
float: left;;
width: 70px;
}
.wiaas-configured-prices input[type='text'] {
width: 100px;
}
#managed_36 > td:nth-child(2) > div:last-child {
position: relative;
padding-bottom: 20px;
}
#managed_36 > td:nth-child(2) > div:last-child > span {
position: absolute;
bottom: 0;
left: 70px;
}
</style>
<script>
</script>
<div class="wrap">
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="postbox-container-1" class="postbox-container">
<div class="postbox">
<div class="inside">
<div class="panel-wrap">
<div class="panel">
<div>
<?php
foreach ($bundled_items_per_category as $category => $category_bundled_items) {
echo sprintf(
'<strong style="text-transform: uppercase;" class="text-uppercase">%s (%s)</strong>',
esc_attr( $category ),
esc_attr(count($category_bundled_items)) );
foreach ($category_bundled_items as $bundled_item) {
$title = $bundled_item->product->get_title();
echo sprintf( '<p>%s x %s</p>', esc_attr($bundled_item->get_quantity('max')), esc_attr( $title ) );
}
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="postbox-container-2" class="postbox-container">
<div class="postbox">
<div class="inside">
<div class="panel-wrap">
<div class="panel">
<h1 style="padding: 0;"><?php echo $package->get_name(); ?></h1>
</div>
</div>
</div>
</div>
<?php
if (! empty($package->get_short_description())) {
?>
<div class="postbox">
<?php wp_editor( $package->get_short_description(), 'content', array(
'_content_editor_dfw' => $_content_editor_dfw,
'drag_drop_upload' => false,
'media_buttons' => false,
'quicktags' => false,
'tabfocus_elements' => 'content-html',
'tinymce' => array(
'resize' => false,
'wp_autoresize_on' => true,
'add_unload_trigger' => false,
'wp_keep_scroll_position' => ! $is_IE,
'readonly'=> true,
'toolbar' => false,
),
) ); ?>
</div>
<?php
}
?>
<div class="postbox">
<div class="inside">
<div class="panel-wrap">
<div class="panel">
<div class="wrap">
<div>
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
<strong><?php esc_html_e('EPR', 'wiaas') ?></strong>
<span><?php esc_html_e('= Extra package recurrent commission', 'wiaas') ?></span>
</div>
<div>
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
<strong><?php esc_html_e('ESR') ?></strong>
<span><?php esc_html_e('= Extra services and support recurrent commission', 'wiaas') ?></span>
</div>
<div>
<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
<strong><?php esc_html_e('Extra commission', 'wiaas') ?></strong>
<span><?php esc_html_e('= EPR + ESR', 'wiaas') ?></span>
</div>
</div>
<div id="tabs" data-disabled="<?php echo $has_default_cl_extras ? '' : '1' ; ?>">
<ul id="tabs-navigation">
<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
</ul>
<form id="wiaas_package_extras" action="" method="post">
<input type="hidden" name="page" value="wiaas-cl-package"/>
<input type="hidden" id="wiaas_cl_package_id" name="cl_package_id" value="<?php echo esc_attr($package->get_id()) ?>"/>
<div id="tabs-1">
<?php require 'html-cl-package-prices.php'; ?>
</div>
<div id="tabs-2">
<div class="form-group">
<select id="wiaas_cl_customers" class="form-control">
<option selected value="0" disabled> Select customer ...</option>
<?php
$customers = wiaas_get_customers();
foreach ($customers as $id => $name) {
// shik current organization if it has role of customer
if ($id === $cl_id) {
continue;
}
?>
<option
<?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
id="wiaas_cl_customer_<?php esc_attr_e($id, 'wiaas') ?>"
value="<?php esc_attr_e($id, 'wiaas') ?>"
>
<?php esc_html_e($name, 'wiaas') ?>
</option>
<?php
}
?>
</select>
<?php wp_nonce_field( 'wiaas_create_cl_customer_extras', 'wiaas_create_cl_customer_extras_nonce' ); ?>
<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
</div>
<?php
// Render customer specific prices if any
foreach ($customer_ids_with_extras as $customer_id) {
require 'html-cl-package-prices.php';
}
?>
</div>
<?php wp_nonce_field( 'wiaas_save_cl_extras', 'wiaas_save_cl_extras_nonce' ); ?>
<?php submit_button( __( 'Save', 'wiaas' ), 'primary', 'submit' ); ?>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br class="clear" />
</div>
</div>

View File

@@ -0,0 +1,162 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$id = isset($customer_id) ? 'extras_customer_'.$customer_id : 'extras_default';
?>
<table id="<?php esc_attr_e($id, 'wiaas') ?>" style="margin-top: 20px;" class="widefat wiaas-configured-prices">
<thead>
<tr>
<td>
<?php
if (isset($customer_id)) {
echo '<h4>'. esc_html(wiaas_get_organization_name($customer_id)). '</h4>';
}
?>
</td>
<td><?php esc_html_e('Minimal sell price', 'wiaas') ?></td>
<td><?php esc_html_e('Extra commision', 'wiaas') ?></td>
<td><?php esc_html_e('Default price', 'wiaas') ?></td>
<td><?php esc_html_e('Visible?', 'wiaas') ?>
<?php
if (isset($customer_id)) {
?>
<i
data-customer_id="<?php esc_attr_e($customer_id, 'wiaas') ?>"
class="dashicons dashicons-dismiss wiaas_remove_cl_extras"
></i>
<?php
}
?>
</td>
</tr>
</thead>
<tbody>
<?php
foreach ($configured_prices as $type => $configured_price) {
$extra_type = isset($customer_id) ? $type.'_customer_'.$customer_id : $type.'_default';
?>
<input
type="hidden"
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][type]"
value="<?php esc_attr_e($type, 'wiaas')?>"
>
<?php
if (isset($customer_id)) {
?>
<input
type="hidden"
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][customer]"
value="<?php esc_attr_e($customer_id, 'wiaas')?>"
>
<?php
}
?>
<tr id="<?php esc_attr_e($extra_type, 'wias')?>">
<td>
<strong><?php esc_html_e($configured_price['payment_type']) ?></strong>
</td>
<td class="form-group">
<div class="form-control">
<label>Fixed:</label>
<input type="text" value="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>" readonly>
</div>
<div class="form-control">
<label>Monthly:</label>
<input type="text" value="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>" readonly>
<?php
if($configured_price['package_pay_period'] > 0) {
echo sprintf( '<span>(%s for services)</span>', esc_attr( $configured_price['minimal_services_price'] ) );
}
?>
</div>
</td>
<td class="form-group">
<div class="form-control">
<label>+</label>
<input
class="wiaas-cl-extra-input"
data-target="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
data-type="fixed"
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][fixed]"
value="<?php esc_attr_e($cl_extras[$extra_type]['fixed'], 'wiaas') ?>"
type="text"
>
</div>
<?php
if($configured_price['package_pay_period'] > 0) {
?>
<div class="form-control">
<label>+</label>
<input
class="wiaas-cl-extra-input"
data-target="wiaas_cl_recurrent_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
data-type="recurrent"
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][recurrent]"
value="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
type="text"
>
<label><?php esc_html_e('(EPR)', 'wiaas') ?></label>
</div>
<?php
}
?>
<div class="form-control">
<label>+</label>
<input
class="wiaas-cl-extra-input"
data-target="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
data-type="services"
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][services]"
value="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
type="text"
>
<label><?php esc_html_e('(ESR)', 'wiaas') ?></label>
</div>
</td>
<td>
<div> =
<strong
id="wiaas_cl_fixed_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
data-base="<?php esc_attr_e($configured_price['minimal_fixed_price'], 'wiaas') ?>"
>
<?php esc_html_e($configured_price['minimal_fixed_price'] + $cl_extras[$extra_type]['fixed'], 'wiaas') ?>
</strong>
</div>
<div> =
<strong
id="wiaas_cl_monthly_extra_<?php esc_attr_e($extra_type, 'wiaas') ?>"
data-base="<?php esc_attr_e($configured_price['minimal_recurrent_price'], 'wiaas') ?>"
data-recurrent="<?php esc_attr_e($cl_extras[$extra_type]['recurrent'], 'wiaas') ?>"
data-services="<?php esc_attr_e($cl_extras[$extra_type]['services'], 'wiaas') ?>"
>
<?php
esc_html_e($configured_price['minimal_recurrent_price'] +
$cl_extras[$extra_type]['recurrent'] +
$cl_extras[$extra_type]['services'], 'wiaas')
?>
</div>
</td>
<td class="form-group">
<input
name="cl_extras[<?php esc_attr_e($extra_type, 'wiaas')?>][visible]"
<?php checked($cl_extras[$extra_type]['visible'], true, true) ?>
type="checkbox"
>
</td>
</tr>
<?php
}
?>
</tbody>
</table>

View File

@@ -0,0 +1,31 @@
<?php
add_action('wp_ajax_wiaas_create_cl_customer_extras', 'wiaas_ajax_create_cl_customer_extras');
function wiaas_ajax_create_cl_customer_extras() {
check_ajax_referer('wiaas_create_cl_customer_extras');
$customer_id = absint($_POST['customer_id']);
$package_id = absint($_POST['package_id']);
$package = wc_get_product($package_id);
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
$cl_extras = array();
foreach ($configured_prices as $type => $configured_price) {
$cl_extras[$type.'_customer_'.$customer_id] = array(
'type' => $type,
'visible' => true,
'fixed' => 0,
'services' => 0,
'recurrent' => 0
);
}
require_once 'views/html-cl-package-prices.php';
die();
}

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,45 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wiaas_Admin_CL {
public static function init() {
add_action('init', array(__CLASS__, 'init_admin_cl'));
}
public static function init_admin_cl() {
$current_user = wp_get_current_user();
$role = $current_user->roles[0];
$is_cl = $role === 'commercial_lead';
if ($is_cl) {
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-packages.php';
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-customers.php';
require_once dirname( __FILE__ ) . '/admin-cl/class-wiaas-admin-cl-orders.php';
require_once dirname( __FILE__ ) . '/admin-cl/wiaas-admin-cl-packages-ajax.php';
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
}
}
public static function enqueue_scripts() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
wp_enqueue_script( 'wiaas_admin_cl_packages', $plugin_url . '/assets/js/wiaas-admin-cl-packages.js' );
wp_enqueue_style( 'wiaas_admin_cl', $plugin_url . '/assets/css/wiaas-admin-cl.css' );
}
}
Wiaas_Admin_CL::init();

View File

@@ -0,0 +1,22 @@
<?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';
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

@@ -0,0 +1,14 @@
<?php
class Wiaas_Admin_Documents {
public static function init() {
require_once dirname( __FILE__ ) . '/documents/class-wiaas-admin-product-documents.php';
require_once dirname( __FILE__ ) . '/documents/class-wiaas-admin-document-editor.php';
require_once dirname( __FILE__ ) . '/documents/wiaas-admin-document-ajax.php';
}
}
Wiaas_Admin_Documents::init();

View File

@@ -0,0 +1,134 @@
<?php
class Wiaas_Admin_Order_Projects {
public static function init() {
// Add is available fields to create and edit forms
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
add_action( 'shop_order_project_edit_form_fields', array( __CLASS__, 'edit_is_available_field' ) );
// Add is available column
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'update_table_headers' ) );
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'update_table_column_content' ), 10, 3 );
// Save is available field when creating and editing
add_action( 'created_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
add_action( 'edit_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
add_action( 'load-term.php', array( __CLASS__, 'admin_menu_highlight' ) );
add_action( 'load-edit-tags.php', array( __CLASS__, 'admin_menu_highlight' ) );
}
/**
* Highlighting orders menu when shop orders page selected
*/
public static function admin_menu_highlight() {
global $plugin_page;
if ( isset( $_GET['taxonomy'] ) && ( $_GET['taxonomy'] === 'shop_order_project' ) ) {
$plugin_page = 'edit.php?post_type=shop_order';
}
}
/**
* Add is available field to order project creation form
*/
public static function add_is_available_field() {
?>
<div class="form-field form-required">
<input
type="checkbox"
class="postform"
style="float:left; margin-top: 4px; margin-right: 10px;"
id="is_available"
name="is_available"
/>
<label for="is_available"><?php _e( 'Is Available?', 'wiaas' ); ?></label>
</div>
<?php
}
/**
* Add is available field to order project edit form
* @param $order_project
*/
public static function edit_is_available_field($order_project) {
?>
<tr class="form-field">
<th scope="row" valign="top"><label><?php _e( 'Is Available?', 'wiaas' ); ?></label></th>
<td>
<input
type="checkbox"
class="checkbox"
id="is_available"
name="is_available"
<?php
checked( true, Wiaas_Order_Project::is_order_project_available($order_project), true )
?>
/>
</td>
</tr>
<?php
}
/**
* Update table headers for order projects
* Will add `is available` and `wiaas count` columns and remove default count column
*
* @param array $columns Available order project table headers
*
* @return array Edited order project table headers
*/
public static function update_table_headers($columns) {
$columns['wiaas_is_available'] = __( 'Is Available?', 'wiaas' );
$columns['wiaas_count'] = __('Count', 'wiaas');
unset($columns['posts']);
return $columns;
}
/**
* Render content for order project table column
* Will add content for `is available` and `wiaas count` columns
*
* @param string $columns Row content for order projects table
* @param string $column Current column header
* @param int $id Order project id
*
* @return string Edited row content with appended is available info
*/
public static function update_table_column_content($columns, $column, $id) {
if ($column === 'wiaas_is_available') {
$is_available = Wiaas_Order_Project::is_order_project_available($id);
$columns .= $is_available ? 'Yes' : 'No';
}
if ($column === 'wiaas_count') {
$term = get_term($id, 'shop_order_project');
$args = array(
'shop_order_project' => $term->slug,
'post_type' => 'shop_order'
);
$columns .= "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$term->count</a>";
}
return $columns;
}
/**
* Save posted is available field for created or edited order project
* @param $term_id
* @param string $tt_id
* @param string $taxonomy
*/
public static function save_is_available_field($term_id, $tt_id = '', $taxonomy = '') {
if ( 'shop_order_project' === $taxonomy ) {
Wiaas_Order_Project::set_is_order_project_available($term_id, $_POST['is_available'] === 'on');
}
}
}
Wiaas_Admin_Order_Projects::init();

View File

@@ -0,0 +1,242 @@
<?php
class Wiaas_Admin_Organization {
public static function init() {
// role switcher for organization
add_action( 'admin_bar_menu', array( __CLASS__, 'add_role_switcher_menu' ), 10, 2 );
// change user role if requested
add_action('admin_init', array(__CLASS__, 'maybe_change_user_role'));
add_filter('manage_users_columns', array(__CLASS__, 'manage_users_table_columns'));
add_filter('views_users', array(__CLASS__, 'hide_users_table_list_navigation'));
add_filter('get_role_list', array(__CLASS__, 'get_role_list_for_user'), 10, 2);
// hide woocommerce meta fields form customer user profile
add_filter('woocommerce_customer_meta_fields', array(__CLASS__, 'hide_woocommerce_customer_fields'));
// save related customers when organization form data has been saved by acf
add_action('acf/save_post', array(__CLASS__, 'maybe_save_related_customers'), 11);
// load related customers for organization form
add_filter('acf/load_value/name=_wiaas_organization_customers', array(__CLASS__, 'load_related_customer_organizations'), 10, 3);
// retrieve only customer organizations as options to link to commercial lead
add_filter('acf/fields/taxonomy/query/name=_wiaas_organization_customers', array(__CLASS__, 'filter_customer_organizations'));
}
public static function hide_woocommerce_customer_fields() {
return array();
}
public static function hide_users_table_list_navigation() {
return array();
}
/**
* Retrieve only customer organization as options to link customers to commercial lead
*
* @param $args
*
* @return array
*/
public static function filter_customer_organizations($args) {
$args['meta_key'] = '_wiaas_organization_roles';
$args['meta_value'] = 'customer';
$args['meta_compare'] = 'LIKE';
return $args;
}
/**
* Saves related customers if organization new/edit form has been submited
* Customer ids are collected from posted data of linked customers acf field and saved
*
* @param string $id in format `term_{$organization_id}`
*/
public static function maybe_save_related_customers($id) {
if ($_POST['taxonomy'] === Wiaas_User_Organization::TAXONOMY_NAME && ! empty($_POST['acf'])) {
$field = get_field_object('_wiaas_organization_customers', $id);
//get organization id
$id = absint(str_replace('term_', '', $id));
$customer_organization_ids = $_POST['acf'][$field['key']];
$customer_organization_ids = is_array($customer_organization_ids) ?
wp_parse_id_list($customer_organization_ids) :
array();
Wiaas_Shop::set_shop_customers($id, $customer_organization_ids);
}
}
/**
* Loads related customers for linked customers acf field on organization edit form
*
* @param array $value
* @param string $id in format `term_{$organization_id}`
* @param array $field acf field details
*
* @return array
*/
public static function load_related_customer_organizations($value, $id, $field) {
//get organization id
$id = absint(str_replace('term_', '', $id));
$customers = wp_list_pluck(
Wiaas_Shop::get_shop_customers($id),
'customer_id');
return $customers;
}
/**
* Render user organization roles as available user roles on user list
* @param $role_list
* @param $user
*
* @return mixed
*/
public static function get_role_list_for_user($role_list, $user) {
$organization_id = wiaas_get_user_organization_id($user->ID);
if (! empty($organization_id)) {
$organization_roles = wiaas_get_organization_roles($organization_id);
foreach ($organization_roles as $organization_role) {
$role_list[$organization_role] = translate_user_role( wp_roles()->role_names[ $organization_role ] );
}
if (! empty($organization_role)) {
unset($role_list['none']);
}
}
return $role_list;
}
/**
* Customize columns for users table list view
*
* @param array $defaults
*
* @return array
*/
public static function manage_users_table_columns( $defaults = array() ) {
$defaults['role'] = __('Roles', 'wiaas');
unset($defaults['posts']);
return $defaults;
}
/**
* Adds organization roles switcher menu to admin bar
*
* @param $admin_bar
*/
public static function add_role_switcher_menu($admin_bar) {
if (is_super_admin()) {
$roles = array( 'administrator' );
} else {
$organization_id = wiaas_get_current_user_organization_id();
$roles = wiaas_get_organization_roles($organization_id);
}
$user = wp_get_current_user();
$current_role = $user->roles[0];
// Add menu item.
$admin_bar->add_menu( array(
'id' => 'wiaas-view-as',
'parent' => 'top-secondary',
'title' => '<span>' .
__( 'View as:', 'wiaas' ) .
'</span>' .
'<span style="margin-left: 6px; font-weight: bold;">'.
__(translate_user_role( wp_roles()->role_names[ $current_role ] ), 'wiaas') .
'</span>' .
'<i style="float: right;" class="ab-icon dashicons dashicons-arrow-down"></i>',
'href' => false,
'meta' => array(
'title' => __( 'View As', 'wiaas' ),
'tabindex' => '0',
),
) );
foreach ($roles as $role) {
$role_name = translate_user_role( wp_roles()->role_names[ $role ] );
if ($role === $current_role) {
// highlight current role
$title = '<span class="ab-label">' . __( $role_name, 'wiaas' ) . '</span>';
$url = false;
} else if ($role === 'customer') {
// set external link for customer role
$title = '<span>' . __( $role_name, 'wiaas' ) . '</span>';
$title .= '<span class="ab-icon dashicons dashicons-external"></span>';
$url = WIAAS_CUSTOMER_INTERFACE;
$target = '_blank';
} else {
$title = '<span>' . __( $role_name, 'wiaas' ) . '</span>';
$url = wp_nonce_url(admin_url(), 'wiaas-set-role', 'wiaas-set-role-nonce');
$url = add_query_arg( 'wiaas-role', $role, $url );
$target = '_parent';
}
$admin_bar->add_menu( array(
'id' => 'wiaas_'.$role,
'parent' => 'wiaas-view-as',
'title' => $title,
'href' => $url,
'meta' => array(
'title' => __( $role_name, 'wiaas' ),
'target' => $target
),
) );
}
}
/**
*
* Process organization role switch request if needed
*
*/
public static function maybe_change_user_role() {
if (! empty($_GET['wiaas-set-role-nonce']) && ! empty($_GET['wiaas-role'])) {
if (wp_verify_nonce($_GET['wiaas-set-role-nonce'], 'wiaas-set-role')) {
$role_name = sanitize_key($_GET['wiaas-role']);
$role = wp_roles()->get_role($role_name);
if (! empty($role) && $role_name !== 'customer') {
// get current user
$current_user = wp_get_current_user();
update_user_meta($current_user->ID, '_wiaas_admin_role', $role->name);
// switch user role
$current_user->set_role($role->name);
}
}
wp_safe_redirect( admin_url('index.php') );
exit;
}
}
}
Wiaas_Admin_Organization::init();

View File

@@ -7,15 +7,45 @@ if ( ! defined( 'ABSPATH' ) ) {
class Wiaas_Admin_Package {
public static function init() {
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-linked-packages.php';
require_once dirname( __FILE__ ) . '/package/class-wiaas-admin-package-types.php';
add_action( 'manage_product_posts_columns', array( __CLASS__, 'manage_list_table_products_columns' ), 999, 2 );
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ), 999);
}
public static function enqueue_scripts() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
wp_enqueue_style( 'wiaas_admin_styles', $plugin_url . '/assets/css/package.css' );
/**
* Hide default WC_Product data panels.
*
* @param array $tabs
*
* @return mixed
*/
public static function package_data_tabs($tabs) {
$tabs['general']['class'] = array( 'show_if_simple', 'show_if_bundle');
unset($tabs['attribute']);
unset($tabs['variations']);
unset($tabs['advanced']);
unset($tabs['shipping']);
unset($tabs['inventory']);
return $tabs;
}
/**
* Customize list table product columns
*
* @param array $columns
*
* @return array
*/
public static function manage_list_table_products_columns($columns) {
$columns['product_tag'] = __( 'Reference', 'wiaas' );
return $columns;
}
}

View File

@@ -0,0 +1,151 @@
<?php
class Wiaas_Admin_Product {
public static function init() {
add_action('acf/save_post', array(__CLASS__, 'save_initial_product_country_and_type'), 20, 1);
add_action('woocommerce_after_register_post_type', array(__CLASS__, 'wiaas_register_product_status'));
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'wiaas_modify_product'));
add_action('add_meta_boxes', array(__CLASS__, 'maybe_remove_metaboxes'), 999);
add_filter('wp_insert_post_data', array(__CLASS__, 'wiaas_maybe_set_no_country_status'), 999, 2);
add_action('acf/render_field/type=group', array(__CLASS__, 'render_choose_button_for_new_product'), 10, 1);
}
public static function wiaas_modify_product($args) {
$args['supports'] = array('title');
return $args;
}
public static function wiaas_register_product_status() {
register_post_status('_wiaas_no_country', array(
'label' => _x('No Country', 'Product status', 'wiaas'),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => false,
'show_in_admin_status_list' => false,
));
}
public static function render_choose_button_for_new_product($field) {
if ($field['_name'] === '_wiaas_product_general') {
?>
<div id="submitpost" style="padding: 20px 0;">
<input style="float:right;" name="publish" id="publish" class="button button-large button-primary" type="submit" value="Choose"/>
</div>
<?php
}
}
public static function maybe_remove_metaboxes() {
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
if ($screen_id !== 'product') {
return;
}
global $post;
$post_id = $post->ID;
if ($post_id === 0 || $post->post_status === '_wiaas_no_country') {
remove_meta_box('woocommerce-product-data', 'product', 'normal');
remove_meta_box('slugdiv', 'product', 'normal');
remove_meta_box('postexcerpt', 'product', 'normal');
remove_meta_box('template_product_meta_box', 'product', 'normal');
remove_meta_box('submitdiv', 'product', 'side');
remove_meta_box('groups-permissions', 'product', 'side');
remove_meta_box('tagsdiv-product_tag', 'product', 'side');
remove_meta_box('tagsdiv-template_category', 'product', 'side');
remove_meta_box('tagsdiv-supplier', 'product', 'side');
remove_meta_box('postimagediv', 'product', 'side');
remove_meta_box('woocommerce-product-images', 'product', 'side');
remove_meta_box('wiaas_upload_and_link_document', 'product', 'side');
remove_meta_box('tagsdiv-product_country', 'product', 'side');
remove_meta_box('tagsdiv-wiaas_units', 'product', 'side');
}
//Always hide product category, it is added wit advanced custom fields plugin for simple product
remove_meta_box('product_catdiv', 'product', 'side');
// Always hide
remove_meta_box('tagsdiv-product_country', 'product', 'side');
}
public static function wiaas_maybe_set_no_country_status($data, $postarr) {
if ($postarr['post_type'] === 'product' && (!isset($postarr['ID']) || !$postarr['ID'])) {
$data['post_status'] = '_wiaas_no_country';
}
return $data;
}
/**
* Check for post status and and if there is country available
* Set post status to draft if the country is added
*
* @param $post_id
*/
public static function save_initial_product_country_and_type($post_id) {
global $post;
if ($post->post_type !== 'product') {
return;
}
$general = get_field('_wiaas_product_general', $post_id);
$country = $general['_wiaas_product_country'];
$type = $general['_wiaas_product_type'];
/**
* If type is missing set status to no country
*
* If this is not template product type and country is missing set status to no country
*
*/
if (empty($type) || ( empty($country) && $type !== 'wiaastemplate' )) {
wp_update_post(array(
'ID' => $post_id,
'post_status' => '_wiaas_no_country'
));
return;
}
/**
* Country and type are selected for simple and bundle products so
* link them
*/
wp_set_object_terms($post_id, $type, 'product_type', true);
if ($type !== 'wiaastemplate') {
wp_set_object_terms($post_id, $country, 'product_country', true);
}
/**
* If product had no country status change it to draft status
*/
if ($post->post_status === '_wiaas_no_country') {
wp_update_post(array(
'ID' => $post_id,
'post_status' => 'draft'
));
}
}
}
Wiaas_Admin_Product::init();

View File

@@ -0,0 +1,13 @@
<?php
class Wiaas_Admin_Simple_Product {
public static function init() {
require_once dirname( __FILE__ ) . '/simple-product/class-wiaas-admin-product-additional-info.php';
}
}
Wiaas_Admin_Simple_Product::init();

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,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,221 @@
<?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) ) {
$order = wc_get_order($order_id);
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country(
Wiaas_Countries::get_country_code_by_currency($order->get_currency())
);
?>
<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

@@ -0,0 +1,92 @@
<?php
/**
* Editor for wiaas document post screen
*
* Class Wiaas_Admin_Document_Editor
*/
class Wiaas_Admin_Document_Editor {
public static function init() {
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
add_action( 'save_post', array( __CLASS__, 'save' ), 1, 2 );
}
/**
* Add wiaas document editor metaboxes
*/
public static function add_meta_boxes() {
add_meta_box( 'wiaas_document_details', __( 'Details', 'wiaas' ), array(
__CLASS__,
'document_info'
), 'wiaas_doc', 'normal', 'low');
}
/**
* Save wiaas document informations
* @param $post_id
* @param $post
*/
public static function save ($post_id, $post) {
if ( empty( $post_id ) || empty( $post ) || empty( $_POST ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( is_int( wp_is_post_revision( $post ) ) ) {
return;
}
if ( is_int( wp_is_post_autosave( $post ) ) ) {
return;
}
if ( empty( $_POST['wiaas_doc_nonce'] ) || ! wp_verify_nonce( $_POST['wiaas_doc_nonce'], 'save_wiaas_doc' ) ) {
return;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
if ( $post->post_type != 'wiaas_doc' ) {
return;
}
// unset nonce because it's only valid of 1 post
unset( $_POST['wiaas_doc_nonce'] );
if (isset($_POST['wiaas_doc_version']) && $_POST['wiaas_doc_version'] !== '') {
$version = sanitize_text_field($_POST['wiaas_doc_version']);
if(wiaas_document_version_exists($version)) {
Wiaas_Document::add_document_version($post_id, $version);
}
}
if (isset($_POST['wiaas_doc_type'])) {
Wiaas_Document::set_doc_type($post_id, sanitize_key($_POST['wiaas_doc_type']));
}
Wiaas_Document::set_is_doc_visible($post_id, $_POST['wiaas_doc_visible'] === 'on');
}
/**
* Render wiaas document info metabox
*/
public static function document_info() {
global $post;
$parent_post_type = $post->post_type;
$document_id = $post->ID;
$ajax_action = 'wiaas_upload_file';
require 'views/html-document-info.php';
}
}
Wiaas_Admin_Document_Editor::init();

View File

@@ -0,0 +1,78 @@
<?php
class Wiaas_Admin_Product_Documents {
public static function init() {
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'add_linked_documents_tab' ) );
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'linked_documents_tab' ) );
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ));
}
/**
* Add upload and link document metabox to product screen
*/
public static function add_meta_boxes() {
add_meta_box( 'wiaas_upload_and_link_document', __( 'Upload and link document', 'wiaas' ), array(
__CLASS__,
'upload_and_link_document'
), 'product', 'side');
}
/**
* Render upload and link document metabox to product screen
*/
public static function upload_and_link_document() {
$ajax_action = 'wiaas_quick_add_document';
require 'views/html-document-form.php';
}
/**
* Add linked documents tabs for product screen
*
* @param array $tabs
*
* @return array
*/
public static function add_linked_documents_tab($tabs) {
$tabs['wiaas_documents'] = array(
'label' => __( 'Linked Documents', 'wiaas' ),
'target' => 'wiaas_documents',
'class' => array('show_if_bundle', 'show_if_simple'),
'priority' => 20,
);
return $tabs;
}
/**
* Render linked documents tab content for product screen
*/
public static function linked_documents_tab() {
global $post;
$documents_ids = wiaas_get_object_attached_documents($post->ID);
include 'views/html-product-documents.php';
}
/**
* Save linked document for product
*
* @param int $package_id
*/
public static function process_meta_box($package_id) {
$documents = isset($_POST['wiaas_attached_documents']) && is_array($_POST['wiaas_attached_documents']) ?
$_POST['wiaas_attached_documents'] : array();
wiaas_attach_documents_to_object($package_id, $documents);
}
}
Wiaas_Admin_Product_Documents::init();

View File

@@ -0,0 +1,51 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* int $id ID of the attached document
*/
$doc_info = Wiaas_Document::get_doc_info($id);
$type = isset($doc_info['type']) && is_array($doc_info['type']) ? $doc_info['type']['name'] : ' - ';
$visible = Wiaas_Document::is_doc_visible($id);
?>
<tr id="wiaas_attached_document_<?php echo esc_attr($id); ?>">
<td width="1%">
<?php
if ($visible) {
echo '<span class="dashicons dashicons-visibility"></span>';
} else {
echo '<span class="dashicons dashicons-hidden"></span>';
}
?>
</td>
<td>
<div>
<input type="hidden" name="wiaas_attached_documents[]" value="<?php echo esc_attr($id); ?>" />
<b>
<?php esc_html_e($doc_info['name'], 'wiaas'); ?>
</b>
</div>
</td>
<td>
<span>
<?php esc_html_e($type, 'wiaas'); ?>
</span>
</td>
<td width="1%"><a href="<?php echo esc_attr($doc_info['url']) ?>" download>
<span class="dashicons dashicons-download"></span>
</a>
</td>
<td width="1%">
<button
data-id="<?php echo esc_attr($id); ?>"
class="button wiaas-remove-attached-document">
<small><?php esc_html_e('Remove', 'wiaas'); ?></small>
</button>
</td>
</tr>

View File

@@ -0,0 +1,270 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
*
*/
$is_update = isset($document_id);
global $post;
$insert_new_document = $post->post_type !== 'wiaas_doc';
?>
<style>
#wiaas_document_form .form-group {
margin-bottom:15px;
min-height: 30px;
}
#wiaas_document_form .form-control {
width: 100%;
height: 34px;
padding:6px 12px;
border: 1px solid #d5d5d5;
}
#wiaas_document_form #plupload-browse-button {
color: #444 !important;
background-color: #FFFFFF !important;
border-color: #CCCCCC !important;
text-transform: uppercase !important;
letter-spacing: 1px !important;
border-radius: 2px !important;
}
#wiaas_document_form #plupload-upload-ui {
height: 230px;
}
#wiaas_document_form #drag-drop-area {
max-height: 200px;
}
#wiaas_document_form .drag-drop .drag-drop-inside {
margin: 50px auto 0;
}
</style>
<script>
jQuery(document).ready(function ($) {
<?php
if ($insert_new_document) {
$nonce = wp_create_nonce('wiaas_quick_add_document');
$action = 'wiaas_quick_add_document';
} else {
$nonce = wp_create_nonce('wiaas_upload_file');
$action = 'wiaas_upload_file';
}
$plupload_init = array(
'runtimes' => 'html5,silverlight,flash,html4',
'browse_button' => 'plupload-browse-button',
'container' => 'plupload-upload-ui',
'drop_element' => 'drag-drop-area',
'file_data_name' => 'wiaas_file',
'multiple_queues' => false,
'url' => admin_url('admin-ajax.php'),
'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
'filters' => array(array(
'title' => __('Allowed Files'),
'extensions' => join(',', Wiaas_Document_Upload::allowed_extensions()))
),
'multipart' => true,
'urlstream_upload' => true,
// additional post data to send to our ajax hook
'multipart_params' => array(
'_ajax_nonce' => $nonce,
'action' => $action,
'type' => 'wiaas_doc'
),
);
if(get_option('__wpdm_chunk_upload',0) == 1){
$plupload_init['chunk_size'] = get_option('__wpdm_chunk_size', 1024).'kb';
$plupload_init['max_retries'] = 3;
} else
$plupload_init['max_file_size'] = wp_max_upload_size().'b';
?>
// create the uploader and pass the config from above
var uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
// checks if browser supports drag and drop upload, makes some css adjustments if necessary
uploader.bind('Init', function(up){
var uploaddiv = jQuery('#plupload-upload-ui');
if(up.features.dragdrop){
uploaddiv.addClass('drag-drop');
jQuery('#drag-drop-area')
.bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
.bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
}else{
uploaddiv.removeClass('drag-drop');
jQuery('#drag-drop-area').unbind('.wp-uploader');
}
});
uploader.init();
// a file was added in the queue
uploader.bind('FilesAdded', function(up, files){
//var hundredmb = 100 * 1024 * 1024, max = parseInt(up.settings.max_file_size, 10);
<?php
if ($insert_new_document) {
?>
var params = uploader.getOption('multipart_params');
params['doc_title'] = $('#wiaas_new_doc_title').val();
params['doc_type'] = $('#wiaas_new_doc_type').val();
params['doc_visible'] = $('#wiaas_new_doc_visible').is(':checked');
uploader.setOption('multipart_params', params);
plupload.each(files, function(file){
jQuery('#wiaas_selected_file').val(file.name);
});
<?php
}
?>
uploader.refresh();
uploader.start();
});
$("#wiaas_document_add_version").click(function(e) {
e.preventDefault();
uploader.start();
});
// a file was uploaded
uploader.bind('FileUploaded', function(up, file, response) {
response = response.response;
var infoContainer = jQuery('#wiaas_upload_info');
if (response.substring(0, 6) === 'ERROR:') {
infoContainer.html('<span style="color: darkred;">' +
'<i class="dashicons dashicons-warning"></i>' +
' &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 {
?>
$('#wiaas_uploaded_file').val(response);
jQuery('#publish').click();
<?php
}
?>
});
});
</script>
<div id="wiaas_document_form">
<?php
if ($insert_new_document) {
?>
<p class="form-group">
<input
id="wiaas_new_doc_title"
type="text"
placeholder="Title"
class="form-control input-lg" />
</p>
<?php
}
?>
<p class="form-group">
<select
id="wiaas_new_doc_type"
name="wiaas_doc_type"
class="form-control input-lg">
<?php
$all_doc_types = Wiaas_Document::get_available_doc_types();
if (!$insert_new_document) {
$selected_doc_type = Wiaas_Document::get_doc_type($post->ID);
$selected_doc_type = is_array($selected_doc_type) ? $selected_doc_type['id'] : '';
}
foreach ($all_doc_types as $doc_type) {
if (!$doc_type['is_special_type']) {
?>
<option
value="<?php echo $doc_type['id'] ?>"
<?php selected($doc_type['id'], $selected_doc_type, true)?>
>
<?php esc_html_e($doc_type['name'], 'wiaas') ?>
</option>
<?php
}
}
?>
</select>
</p>
<p class="form-group">
<input
id="wiaas_new_doc_visible"
name="wiaas_doc_visible"
<?php if (!$insert_new_document)
checked(Wiaas_Document::is_doc_visible($post->ID), true, true) ?>
type="checkbox"
/>
<label><?php echo __( 'Visible to customer?', 'wiaas' ); ?></label>
</p>
<input id="wiaas_uploaded_file" name="wiaas_doc_version" type="hidden">
<div>
<div id="plupload-upload-ui" class="hide-if-no-js">
<div id="drag-drop-area" style="height:240px">
<div class="drag-drop-inside">
<p class="drag-drop-info"><?php _e( 'Drop file here', 'wiaas' ); ?></p>
<p><?php echo _x( 'or', 'Drop file here *or* select file', 'wiaas' ); ?></p>
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button"
value="<?php esc_attr_e( 'Select File', 'wiaas' ); ?>"
class="button"/></p>
</div>
</div>
</p>
</div>
</div>
<div id="wiaas_upload_info">
</div>
</div>

View File

@@ -0,0 +1,87 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* int $document_id ID of the document
*/
?>
<style>
#wiaas_document_info table {
margin-top: 25px;
}
#wiaas_document_info table > thead {
background: #f5f5f5;
}
#wiaas_document_info table b {
color: #72777c;
}
#tagsdiv-wiaas_doc_type {
display: none;
}
#wiaas_document_new_version {
max-width: 320px;
margin: auto;
}
</style>
<div id="wiaas_document_info">
<?php echo wp_nonce_field('save_wiaas_doc', 'wiaas_doc_nonce') ?>
<div id="wiaas_document_new_version">
<?php
require 'html-document-form.php';
?>
</div>
<div class="form-group">
<table class="widefat">
<thead>
<tr>
<td></td>
<td><b>Versions</b></td>
<td></td>
</tr>
</thead>
<tbody id="wiaas_doc_versions">
<?php
$versions = Wiaas_Document::get_document_versions($document_id);
foreach ($versions as $index => $version) {
?>
<tr>
<td><?php esc_html_e('#' . ($index + 1), 'wiaas') ?></td>
<td><?php
esc_html_e(
wiaas_get_doc_version_filename($version).'.'.wiaas_get_doc_version_extension($version),
'wiaas')
?></td>
<td>
<a
href="<?php echo esc_attr(Wiaas_Document::get_doc_download_link($document_id, $index)) ?>"
download>
<span class="dashicons dashicons-download"></span>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>

View File

@@ -0,0 +1,39 @@
<?php
/**
* Wiaas Linked Packages Editor
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="wiaas_documents" class="panel woocommerce_options_panel">
<div class="options_group">
<p class="form-field">
<label style="font-weight: bold;" for="wiaas_addon_packages"><?php esc_html_e( 'Search documents:', 'wiaas' ); ?></label>
<input
type="text"
data-target="wiaas_attached_documents"
data-search-nonce="<?php echo wp_create_nonce('wiaas_json_search_documents') ?>"
data-link-nonce="<?php echo wp_create_nonce('wiaas_link_document') ?>"
class="wiaas-search-documents"
/>
</p>
</div>
<div class="options_group">
<div class="form-field">
<div style="margin:20px">
<table id="wiaas_attached_documents" class="widefat wp-list-table">
<tbody>
<?php
foreach ($documents_ids as $id) {
require 'html-attached-document.php';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,105 @@
<?php
add_action( 'wp_ajax_wiaas_upload_file', 'wiaas_ajax_upload_document_version' );
add_action( 'wp_ajax_wiaas_quick_add_document', 'wiaas_ajax_quick_add_document' );
add_action( 'wp_ajax_wiaas_link_document', 'wiaas_ajax_link_document' );
add_action( 'wp_ajax_wiaas_json_search_documents','wiaas_ajax_json_search_documents' );
/**
* Upload document version file with ajax
*/
function wiaas_ajax_upload_document_version() {
check_ajax_referer('wiaas_upload_file');
if (!isset($_FILES['wiaas_file']) || empty($_FILES['wiaas_file'])) {
echo "ERROR: No file present!";
die();
}
$version = Wiaas_Document_Upload::upload_document_version('wiaas_file');
if (is_wp_error($version)) {
echo 'ERROR:' . $version->get_error_message();
die();
}
echo $version;
die();
}
/**
* Quick add new document and return attachment view for it
*/
function wiaas_ajax_quick_add_document() {
check_ajax_referer('wiaas_quick_add_document');
//validate file
if (!isset($_FILES['wiaas_file']) || empty($_FILES['wiaas_file'])) {
echo "ERROR: No file present!";
die();
}
// Upload document version file
$version = Wiaas_Document_Upload::upload_document_version('wiaas_file');
// Upload failed so return the error
if (is_wp_error($version)) {
echo 'ERROR:' . $version->get_error_message();
die();
}
// Get document title
$title = isset($_POST['doc_title']) && $_POST['doc_title'] !== '' ?
sanitize_text_field($_POST['doc_title']) :
pathinfo( $version, PATHINFO_FILENAME );
// Try to create new document
$id = Wiaas_Document::add_document(
$title,
$version,
$_POST['doc_visible'] === 'true');
// Document creation failed so return the error
if (!$id) {
echo "ERROR: Document could not be created!";
die();
}
// If document type is sent then assign new document to it
if (isset($_POST['doc_type'])) {
Wiaas_Document::set_doc_type( $id, sanitize_key($_POST['doc_type']) );
}
require 'views/html-attached-document.php';
die();
}
/**
* Render attacment view for linked document
*/
function wiaas_ajax_link_document() {
check_ajax_referer('wiaas_link_document');
$id = absint($_GET['id']);
require 'views/html-attached-document.php';
die();
}
/**
*
*Search wiaas documents by name
*/
function wiaas_ajax_json_search_documents() {
check_ajax_referer('wiaas_json_search_documents');
$q = ( ! empty( $_GET['query'] ) ? sanitize_text_field($_GET['query']) : '' );
$result = Wiaas_Document::search($q);
wp_send_json( $result );
}

View File

@@ -28,20 +28,6 @@ if ( ! defined( 'ABSPATH' ) ) {
}
}
function showDownloadableFiles() {
$('#general_product_data').find('.show_if_downloadable').each(function() {
$(this).show();
$(this).removeClass('hidden');
$(this).removeClass('show_if_downloadable');
$(this).addClass('show_if_simple');
$(this).addClass('show_if_bundle');
$(this).find('._download_limit_field, ._download_expiry_field').hide();
});
}
showDownloadableFiles();
handlePackageTypeToolsVisiblity();
});
</script>

View File

@@ -11,12 +11,49 @@ class Wiaas_Admin_Package_Pricing {
public static function init() {
add_action( 'woocommerce_product_data_tabs', array( __CLASS__, 'package_data_tabs' ) );
add_action( 'woocommerce_product_data_panels', array( __CLASS__, 'package_data_panel' ) );
add_action( 'admin_menu', array(__CLASS__, 'add_package_pricing_editor_page') );
add_action( 'wp_ajax_create_empty_pricing_rule', array(__CLASS__, 'create_empty_pricing_rule') );
add_action( 'woocommerce_process_product_meta', array( __CLASS__, 'process_meta_box' ), 1, 2 );
add_action('woocommerce_product_options_general_product_data', array(__CLASS__, 'render_edit_prices_link'));
add_filter('woocommerce_bundle_price_html', array( __CLASS__, 'get_package_price_html' ), 10, 2);
}
public static function get_package_price_html($price_html, $package) {
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-package_price_editor&id=' . absint( $package->get_id() ) );
return '<a class="button button-link" href="' . esc_url($edit_link) .'" target="_blank">Edit price<a>';
}
public static function render_edit_prices_link() {
global $post;
$edit_link = admin_url( 'edit.php?post_type=product&page=wiaas-package_price_editor&id=' . absint( $post->ID ) );
?>
<div class="options_group hide_if_simple hide_if_wiaastemplate">
<p>
<a href="<?php echo esc_url($edit_link) ?>" target="_blank">
<span>Edit prices</span>
</a>
</p>
</div>
<?php
}
public static function add_package_pricing_editor_page() {
add_submenu_page(
'edit.php?post_type=product',
__( 'Edit prices', 'wiaas' ),
null,
'create_products',
'wiaas-package_price_editor',
array(__CLASS__, 'package_pricing_editor')
);
}
/**
@@ -32,46 +69,87 @@ class Wiaas_Admin_Package_Pricing {
die();
}
/**
* Registers wiaas pricing tab for package data
* @param $tabs
*
* @return array
*/
public static function package_data_tabs($tabs) {
$tabs[ 'bundled_packages_price' ] = array(
'label' => __( 'Pricing', 'wiaas' ),
'target' => 'wiaas_package_price',
'class' => array( 'show_if_bundle', 'bundled_package_tab' ),
'priority' => 50
);
return $tabs;
}
/**
* Renderes wiaas pricing tab content for package
*/
public static function package_data_panel() {
public static function package_pricing_editor() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
wp_enqueue_script('admin_package_edit_prices', $plugin_url . '/assets/js/wiaas-admin-package-edit-prices.js');
$package_id = absint($_GET['id']);
$package = wc_get_product( $package_id );
if (empty($package) || $package->get_type() !== 'bundle') {
return;
}
// save prices
if (! empty($_POST['wiaas_save_package_prices_nonce']) &&
wp_verify_nonce($_POST['wiaas_save_package_prices_nonce'], 'wiaas_save_package_prices')) {
self::_save_posted_package_prices($package_id);
}
global $post;
$package = wc_get_product( $post->ID );
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
$max_cost_margin = Wiaas_Package_Pricing::get_package_max_cost_margin($package);
include 'views/html-package-pricing.php';
// collect package bundle items pricing info to display
$bundled_items = $package->get_bundled_items();
$bundled_items_per_category = array();
foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product;
$product_cat = Wiaas_Product_Category::get_category($product);
if ($product_cat === 'hardware' || $product_cat === 'software') {
$product_cat = 'product';
}
$bundled_items_per_category[$product_cat] ?: array( );
$bundled_items_per_category[$product_cat][] = $bundled_item;
}
include 'views/html-package-pricing-page.php';
}
// PRIVATE HELPERS
/**
* Saves posted package pricing rules
* @param $post_id
* @param $post
* Save posted package pricing information
*
* @param int $package_id
*/
public function process_meta_box( $post_id, $post ) {
private static function _save_posted_package_prices($package_id) {
$commission = wp_unslash($_POST['wiaas_pricing_rules_commision']);
$max_cost_margin = wp_unslash($_POST['wiaas_max_cost_margin']);
$pricing_rules = array();
$posted_pricing_rules = isset($_POST['wiaas_pricing_rules']) ? wp_unslash($_POST['wiaas_pricing_rules']) : array();
foreach ($posted_pricing_rules as $rule_type => $posted_prices) {
$posted_prices = wp_unslash($posted_prices);
$prices = array();
foreach ($posted_prices as $posted_price_type => $posted_price) {
$prices[sanitize_key($posted_price_type)] = wp_unslash($posted_price);
}
$pricing_rules[sanitize_key($rule_type)] = $prices;
}
Wiaas_Package_Pricing::set_package_prices(
wc_get_product( $post_id ),
$_POST['wiaas_pricing_rules'],
$_POST['wiaas_pricing_rules_commision']);
wc_get_product( $package_id ),
$pricing_rules,
$commission,
$max_cost_margin);
Wiaas_Access_Management::maybe_handle_product_access($package_id, get_post($package_id));
}
}

View File

@@ -0,0 +1,276 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<style>
table tr:not(.wiaas-package-price) td:not(:first-child) {
text-align: center;
vertical-align: middle; !important;
}
</style>
<div id="wiaas_package_pricing_editor" class="wrap">
<h1>
<?php
esc_html_e($package->get_title(), 'wiaas');
$country = Wiaas_Countries::get_package_country($package);
if (! empty($country)) {
esc_html_e(' (sold in ' . $country['name'] . ')', 'wiaas');
}
?>
</h1>
<br class="clear" />
<div id="col-container">
<div id="post-body" class="metabox-holder columns-2">
<div id="col-right">
<div class="col-wrap">
<div class="inside">
<table class="widefat">
<tbody>
<?php
$products_total_cost = 0;
$one_time_services_cost = 0;
$recurring_services_cost = 0;
$installation_cost = 0;
foreach ($bundled_items_per_category as $cat => $items) {
?>
<tr style="background: #F5F5F5;">
<td colspan="4">
<strong style="text-transform: uppercase;">
<?php esc_html_e($cat . ' (' . count($items) . ')', 'wiaas') ?>
</strong>
</td>
</tr>
<?php
foreach ($items as $item) {
$product = $item->product;
$product_price = Wiaas_Product_Pricing::get_product_price($product);
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
?>
<tr>
<td>
<span>
<?php esc_html_e($item->get_quantity(), 'wiaas') ?>
x
<?php esc_html_e($product->get_title(), 'wiaas') ?>
</span>
</td>
<td>
<?php
esc_html_e(
$total_cost * $item->get_quantity(),
'wiaas')
?>
</td>
<td>
<?php
esc_html_e(
$total_cost . ' per unit',
'wiaas');
?>
</td>
<td>
<?php
if ($product_price['is_recurring']) {
esc_html_e(
$product_price['price'] . ' / month for ' . $product_price['pay_period'] . ' months',
'wiaas');
} else {
echo '-';
}
?>
</td>
</tr>
<?php
}
?>
<tr class="wiaas-package-price">
<td style="border-top: 1px solid #e5e5e5;"></td>
<td colspan="3" style="border-top: 1px solid #e5e5e5;">
<strong>
<?php
if ($cat === 'product') {
$products_total_cost = wiaas_get_package_product_procurement_cost($package);
esc_html_e('Total: ' . $products_total_cost, 'wiaas');
}
if ($cat === 'service') {
$one_time_services_cost = wiaas_get_package_one_time_services_procurement_cost($package);
$recurring_services_cost = wiaas_get_package_recurring_services_procurement_cost($package);
esc_html_e('One time services: ' . $one_time_services_cost, 'wiaas');
echo '<br>';
esc_html_e('Recurring services: ' . $recurring_services_cost . ' / month ', 'wiaas');
}
if ($cat === 'installation') {
$installation_cost = wiaas_get_package_installation_procurement_cost($package);
esc_html_e('Installation: ' . $installation_cost, 'wiaas');
}
?>
</strong>
</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr class="wiaas-package-price">
<td>
<h4>TOTAL COST :</h4>
</td>
<td colspan="3">
<strong>Fixed: <?php esc_html_e($products_total_cost + $one_time_services_cost + $installation_cost)?></strong>
<br>
<strong>Recurring: <?php esc_html_e($recurring_services_cost)?> / month</strong>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<div id="col-left">
<div class="col-wrap">
<div class="form-wrap">
<h2><?php esc_html_e('Set package prices', 'wiaas') ?></h2>
<form action="" method="post">
<input type="hidden" name="page" value="wiaas-package_price_editor">
<input type="hidden" name="id" value="<?php esc_attr_e($package->get_id(), 'wiaas') ?>">
<div class="form-field">
<label><?php esc_html_e('Max cost margin:', 'wiaas') ?></label>
<input
id="wiaas_pricing_rules_max_cost_margin"
name="wiaas_max_cost_margin"
type="number"
min="0"
value="<?php esc_attr_e($max_cost_margin, 'wiaas') ?>"
data-total="<?php esc_attr_e(Wiaas_Pricing::get_package_total_cost($package), 'wiaas') ?>"
>
<p
id="wiaas_pricing_rules_max_cost_margin_error"
<?php if(Wiaas_Package_Status::get_package_status($package->get_id()) !== Wiaas_Package_Status::INVALID_MARGIN) echo 'style="display: none;"' ?>
class="wiaas-package-error"
>The total costs are greater than the package max margin!</p>
</div>
<div class="form-field">
<label><?php esc_html_e('Commision ( % ):', 'wiaas') ?></label>
<input
id="wiaas_pricing_rules_commision"
name="wiaas_pricing_rules_commision"
type="number"
value="<?php esc_attr_e($commission, 'wiaas') ?>"
min="0" max="100"
>
<p id="wiaas_pricing_rules_commission_details">
<?php esc_html_e('Commercial lead: ' . (100 - $commission) .'%', 'wiaas') ?>
</p>
</div>
<div class="form-field">
<div class="wrap">
<select id="wiaas_pay_types" name="wiaas-pay-type" class="pricing_rule_mode">
<option selected value="0" disabled> Select payment type ...</option>
<?php
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
foreach ($available_pay_types as $name => $pay_type) {
$is_added = ! empty( $pricing_rules[$name])
?>
<option
value="<?php esc_attr_e($name, 'wiaas') ?>"
id="wiaas_pay_type_<?php esc_attr_e($name, 'wiaas') ?>"
<?php disabled($is_added, true, true) ?>
>
<?php esc_html_e( $pay_type['title'], 'wiaas' ); ?>
</option>
<?php
}
?>
</select>
<button
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
id="wiaas-add-pricing"
type="button"
class="button">
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
</button>
</div>
</div>
<div id="wiaas_package_pricing_rules">
<?php
require 'html-package-pricing-rules-list.php';
?>
</div>
<?php wp_nonce_field( 'wiaas_save_package_prices', 'wiaas_save_package_prices_nonce' ); ?>
<input type="submit" value="Save" class="button button-primary button-large">
</form>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -6,13 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php
$value = $pricing_rule['minimal_services_price'];
if ($pricing_rule['principal_amount'] > 0 && $pay_type['package_pay_period'] > 0) {
$value += wiaas_PMT(
Wiaas_Pricing::INTEREST_RATE,
$pay_type['package_pay_period'],
$pricing_rule['principal_amount']);
}
$value = $pricing_rule['minimal_recurrent_price'];
?>
<tr>

View File

@@ -8,7 +8,7 @@ $available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
foreach ( $pricing_rules as $name => $pricing_rule ) {
$pay_type = $available_pay_types[$name];
?>
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule">
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule form-field">
<div class="section">
<h4 class="first"><?php echo $pay_type['title']; ?>
<a href="#" data-name="<?php echo $name; ?>"

View File

@@ -1,209 +0,0 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div id="wiaas_package_price" class="panel woocommerce_options_panel">
<script type="text/javascript">
jQuery(document).ready(function ($) {
$("#wiaas-add-pricing").click(function (event) {
event.preventDefault();
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
$("#wiaas_package_pricing_rules").data('setindex', set_index);
var pay_type = $('#wiaas_pay_type').val();
var data = {
'pay_type': pay_type,
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
action: 'create_empty_pricing_rule'
};
$.post(ajaxurl, data, function (response) {
$('#wiaas_package_pricing_rules').append(response);
$(`#wiaas_pay_type_${pay_type}`).addClass('wiaas_hidden');
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
if (available_options.length === 0) {
$('#wiaas_package_price_controls').addClass('wiaas_hidden');
} else {
$('#wiaas_pay_type').val(available_options.first().val());
}
});
});
//Remove Pricing Type
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
event.preventDefault();
if (confirm("<?php _e( 'Are you sure you would like to remove this pay type?', 'wiaas' ); ?>")) {
var name = $(this).data('name');
$('#wiaas-pricing-rule-' + name).slideUp().remove();
// append new option to controls
$(`#wiaas_pay_type_${name}`).removeClass('wiaas_hidden');
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
if (available_options.length === 1) {
$('#wiaas_package_price_controls').removeClass('wiaas_hidden');
$('#wiaas_pay_type').val(available_options.first().val());
}
}
});
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
event.preventDefault();
var minimal_services_price = parseFloat($(this).val()) || 0;
var principal_amount = 0;
var name = $(this).data('name');
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
if (principal_amount_input) {
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
}
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
var services_contract_period = $(this).data('period');
if (services_contract_period > 0) {
var final_services_price = minimal_services_price * services_contract_period;
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
}
});
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
event.preventDefault();
var value = parseFloat($(this).val());
var period = parseFloat($(this).data('period'));
var interestRate = 0.58;
var principal_amount = calculateFinancing(interestRate, period, value);
var minimal_services_price = 0;
var name = $(this).data('name');
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
if (minimal_services_price_input) {
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
}
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(0));
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(0));
});
/**
* Copy of Excel's PMT function.
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
*
* @param ratePerPeriod The interest rate for the loan.
* @param numberOfPayments The total number of payments for the loan in months.
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
* Also known as the principal.
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
* 0 = At the end of period
* 1 = At the beginning of the period
* @returns {number}
*/
function calculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
/*var q = 0;
var c = 0;
const monthlyRatePerPeriod = ratePerPeriod / 12;
if (monthlyRatePerPeriod !== 0.0) {
// Interest rate exists
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
return c.toFixed(2);
} else if (numberOfPayments !== 0.0) {
// No interest rate, but number of payments exists
return -(futureValue + presentValue) / numberOfPayments;
}
return 0;*/
const rates = {
24 : 4.282,
30 : 3.451,
36 : 2.896,
42 : 2.500,
48 : 2.223,
54 : 2.025,
60 : 1.834
};
const interest = rates[numberOfPayments] || 10;
return presentValue * (interest / 100);
}
});
</script>
<div class="options_group">
<?php
woocommerce_wp_text_input(
array(
'id' => '_wiaas_price_commision',
'name' => 'wiaas_pricing_rules_commision',
'value' => $commission,
'label' => __( 'Commision (Percent):', 'wiaas' ),
'type' => 'number',
)
);
?>
</div>
<div class="options_group">
<div class="wc-metaboxes-wrapper">
<?php
$has_available_pay_types = false;
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
foreach ($available_pay_types as $name => $pay_type) {
if (!isset($pricing_rule_sets[$name])) {
$has_available_pay_types = true;
break;
}
}
$class = $has_available_pay_types ? '' : 'wiaas_hidden';
?>
<div id="wiaas_package_price_controls" class="toolbar toolbar-top <?php echo $class ?>">
<select id="wiaas_pay_type" name="wiaas-pay-type" class="pricing_rule_mode">
<?php
foreach ($available_pay_types as $name => $pay_type) {
?>
<option
value="<?php echo $name ?>"
id="wiaas_pay_type_<?php echo $name ?>"
class="<?php echo $class ?>"
>
<?php _e( $pay_type['title'], 'wiaas' ); ?>
</option>
<?php
}
?>
</select>
<button
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
id="wiaas-add-pricing"
type="button"
class="button button-primary">
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
</button>
</div>
<div id="wiaas_package_pricing_rules" class="wc-metaboxes">
<?php
require 'html-package-pricing-rules-list.php';
?>
</div>
</div>
</div>
</div>

View File

@@ -4,24 +4,13 @@ if ( ! defined( 'ABSPATH' ) ) {
}
?>
<script>
jQuery(document).ready(function($) {
$("#general_product_data").find('.pricing').addClass('hide_if_bundle');
$("#general_product_data").find('.pricing').removeClass('show_if_bundle');
if ($('#product-type').val() === 'bundle') {
$("#general_product_data .pricing").hide();
}
});
</script>
<?php
woocommerce_wp_checkbox(
array(
'id' => '_wiaas_recurring_price',
'value' => $product_pricing['is_recurring'] ? 'yes' : 'no',
'data_type' => 'price',
'label' => __( $product->get_category_ids()[0], 'wiaas' ),
'label' => __( 'Is recurring?', 'wiaas' ),
)
);

View File

@@ -0,0 +1,104 @@
<?php
class Wiaas_Admin_Product_Additional_Info {
public static function init() {
add_action('woocommerce_product_options_general_product_data', array(__CLASS__, 'display_additional_fields'));
add_action('woocommerce_process_product_meta', array(__CLASS__, 'save_additional_fields'));
add_filter('woocommerce_json_search_found_products', array(__CLASS__, 'filter_product_by_country'));
}
/**
* Add Manufacturer product and Supplier product number fields to
* Simple product general tab
*
*/
public static function display_additional_fields() {
global $post;
$product = wc_get_product( $post->ID );
if ($product->get_type() === 'simple') {
echo '<div class=" product_custom_field ">';
woocommerce_wp_text_input(
array(
'id' => '_manufacturer_product_no',
'label' => __('Manufacturer product number', 'woocommerce'),
'type' => 'text'
)
);
woocommerce_wp_text_input(
array(
'id' => '_supplier_product_no',
'label' => __('Supplier product number', 'woocommerce'),
'type' => 'text'
)
);
echo '</div>';
}
}
/**
* This method filters search results by template country
* In addition it adds template category to label of every product
*
* @param $search_results array provided by filter
* @return mixed array of filtered search results
*/
public static function filter_product_by_country($search_results) {
$url = wp_get_referer();
if (strpos($url, 'post') === false) {
return $search_results;
}
$post_param = explode("&", parse_url($url, PHP_URL_QUERY))[0];
$post_id = explode("=", $post_param)[1];
$country_id = wp_get_post_terms($post_id, 'product_country', array('fields' => 'ids'))[0];
if (!empty($search_results)) {
$search_result_objects = array_map('wc_get_product', array_keys($search_results));
foreach ($search_result_objects as $result_id => $product_form_search) {
if (Wiaas_Countries::get_product_country_term_id($product_form_search) !== $country_id) {
unset($search_results[$product_form_search->get_id()]);
} else {
$template_category = wp_get_object_terms($product_form_search->get_id(), 'template_category', array('fields' => 'names'));
if(!empty($template_category)){
$search_results[$product_form_search->get_id()] = $search_results[$product_form_search->get_id()].' ['.$template_category[0].']';
}
}
}
}
return $search_results;
}
/**
* Save Manufacturer product and Supplier product number fields to
* Simple product meta data
*
*/
public static function save_additional_fields($post_id) {
$manufacturer_product_no = $_POST['_manufacturer_product_no'];
if (!empty($manufacturer_product_no))
update_post_meta($post_id, '_manufacturer_product_no', esc_attr($manufacturer_product_no));
$supplier_product_no = $_POST['_supplier_product_no'];
if (!empty($supplier_product_no))
update_post_meta($post_id, '_supplier_product_no', esc_attr($supplier_product_no));
}
}
Wiaas_Admin_Product_Additional_Info::init();

View File

@@ -3,27 +3,35 @@
class Wiaas_Admin_Template_Selection {
public static function init() {
add_action('add_meta_boxes', array(__CLASS__, 'create_custom_meta_box'), 100);
add_action('woocommerce_process_product_meta_bundle', array(__CLASS__, 'save_custom_content_meta_box'), 10, 1);
add_action('add_meta_boxes', array(__CLASS__, 'create_template_meta_box'), 100);
add_action('woocommerce_process_product_meta_bundle', array(__CLASS__, 'save_template_content_meta_box'), 10, 1);
// Processes and saves type-specific data.
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'validate_bundle'), 11);
}
public static function create_custom_meta_box() {
/**
* Renders template selection meta box
*/
public static function create_template_meta_box() {
add_meta_box(
'template_product_meta_box',
__('Choose package template <em>(optional)</em>', 'cmb'),
'Wiaas_Admin_Template_Selection::add_custom_content_meta_box',
'Wiaas_Admin_Template_Selection::add_template_content_meta_box',
'product',
'normal',
'high'
);
}
public static function add_custom_content_meta_box($post) {
/**
* Fill in the value of template selection dropdown,
* and render template categories of the selected template
*
* @param $post WP_Post object
*/
public static function add_template_content_meta_box($post) {
$value = get_post_meta($post->ID, '_select_template', true);
@@ -48,150 +56,147 @@ class Wiaas_Admin_Template_Selection {
<div id="wiaas_selected_template_items_container"><?php
$template_products_data = self::show_template_products($value);
self::render_template_products($template_products_data['hardware']);
self::render_template_products($template_products_data['service']);
self::render_template_products($template_products_data['installation']);
self::render_template_products($template_products_data['software']);
$product = wc_get_product( $post->ID );
if ($product->get_type() == 'bundle') {
$bundled_items = $product->get_bundled_items('view');
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
self::render_template_products($template_products_data['hardware'], $categories_form_bundle);
self::render_template_products($template_products_data['services'], $categories_form_bundle);
self::render_template_products($template_products_data['installation'], $categories_form_bundle);
self::render_template_products($template_products_data['software'], $categories_form_bundle);
}
?></div><?php
}
public static function get_categories_from_templates($products_form_template) {
/**
* Extract template categories for all of the main product categories
* (software , hardware, services, installation) and combine them in one array
*
* @param $categories_form_template
* @return array of Wiaas_Template_Category_Object
*/
public static function get_categories_from_templates($categories_form_template) {
$all_template_categories = array();
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['hardware']));
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['service']));
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['installation']));
$all_template_categories = array_merge($all_template_categories, self::get_product_categories($products_form_template['software']));
$all_template_categories = array_merge($all_template_categories,
WC_Product_Template::extract_template_product_categories($categories_form_template['hardware']));
$all_template_categories = array_merge($all_template_categories,
WC_Product_Template::extract_template_product_categories($categories_form_template['services']));
$all_template_categories = array_merge($all_template_categories,
WC_Product_Template::extract_template_product_categories($categories_form_template['installation']));
$all_template_categories = array_merge($all_template_categories,
WC_Product_Template::extract_template_product_categories($categories_form_template['software']));
return $all_template_categories;
}
/**
* Return all of the template product meta_data from selected template
*
* @param $selected_template integer an id of selected template
* @return array of template categories
*/
public static function show_template_products($selected_template) {
if (empty($selected_template)) {
return;
return array();
} else {
$template_products_hardware = (get_post_meta($selected_template, '_template_items_hardware', true));
$template_products_service = (get_post_meta($selected_template, '_template_items_service', true));
$template_products_installation = (get_post_meta($selected_template, '_template_items_installation', true));
$template_products_software = (get_post_meta($selected_template, '_template_items_software', true));
$template_products_hardware = WC_Product_Template::get_template_categories_from_meta(
$selected_template, '_template_items_hardware');
$template_products_services = WC_Product_Template::get_template_categories_from_meta(
$selected_template, '_template_items_services');
$template_products_installation = WC_Product_Template::get_template_categories_from_meta(
$selected_template, '_template_items_installation');
$template_products_software = WC_Product_Template::get_template_categories_from_meta(
$selected_template, '_template_items_software');
}
return array(
'hardware' => $template_products_hardware,
'service' => $template_products_service,
'services' => $template_products_services,
'installation' => $template_products_installation,
'software' => $template_products_software
);
}
public static function render_template_products($template_products) {
/**
* Render html of template categories
*
* @param $template_products array containing template category information
* @param $categories_form_bundle
*/
public static function render_template_products($template_products, $categories_form_bundle = array()) {
if (!empty($template_products)) {
foreach ($template_products as $item) {
$connected_product = $categories_form_bundle[$item['template_category_id']] ?
$categories_form_bundle[$item['template_category_id']]->product_name : '';
$product_id = $item['template_category_id'];
$title = $item['template_category_title'];
$quantity = $item['quantity'];
$connected_product_name = $connected_product;
include('views/html-wiaas-template-selection.php');
}
}
}
public static function get_product_categories($category_meta) {
$category_objects = array();
/**
* Save selected template
*
* @param $post_id WP_Post
*/
if (empty($category_meta)) {
return array();
}
foreach ($category_meta as $meta) {
if (!empty($meta)) {
$category_template_id = $meta['template_category_id'];
$template_category_object = new Wiaas_Template_Category_Object(
$category_template_id,
$meta['template_category_title'],
$meta['quantity']);
$category_objects[$category_template_id] = $template_category_object;
}
}
return empty($category_objects) ? null : $category_objects;
}
public static function get_bundled_product_categories($bundled_items) {
$template_category_objects = array();
foreach ($bundled_items as $item_id => $item) {
$item_data = $item->get_data();
$post_terms = wp_get_object_terms($item->get_product_id(), 'template_category', array('fields' => 'id=>name'));
if (!empty($post_terms) && !is_wp_error($post_terms)) {
$cat = '';
$category_template_id = '';
foreach ($post_terms as $id => $term) {
$cat = $term;
$category_template_id = $id;
}
$template_category_object = new Wiaas_Template_Category_Object(
$category_template_id,
$cat,
$item_data['quantity_max']);
$template_category_objects[$category_template_id] = $template_category_object;
}
}
return $template_category_objects;
}
function save_custom_content_meta_box($post_id) {
function save_template_content_meta_box($post_id) {
$selected_template = $_POST['_select_template'];
if (!empty($selected_template))
update_post_meta($post_id, '_select_template', esc_attr($selected_template));
else {
update_post_meta($post_id, '_select_template', '');
}
WC_Product_Template::bind_selected_template_to_product($selected_template, $post_id);
}
/**
* Get the template categories from bundle products and selected template
* Compare template categories and quantities that are required by the template with those in bundle products
*
* Admin error is added if validation is not satisfied
*
* @param $product WC_Product_Bundle
*/
public static function validate_bundle($product) {
if ($product->get_type() == 'bundle') {
$selected_template = $_POST['_select_template'];
$bundled_items = $product->get_bundled_items('view');
$products_form_template = self::show_template_products($selected_template);
$template_categories_form_template = self::show_template_products($selected_template);
$missing_categories = array();
$insufficient_product_quantities = array();
$missing_template_categories = array();
$insufficient_template_category_quantities = array();
$categories_form_template = self::get_categories_from_templates($products_form_template);
$categories_form_bundle = self::get_bundled_product_categories($bundled_items);
$categories_form_template = self::get_categories_from_templates($template_categories_form_template);
$categories_form_bundle = WC_Product_Template::extract_bundled_product_categories($bundled_items);
$bundle_category_keys = array_keys($categories_form_bundle);
if (!empty($categories_form_template)) {
foreach ($categories_form_template as $category) {
@@ -200,7 +205,7 @@ class Wiaas_Admin_Template_Selection {
if (!in_array($template_cat_id, $bundle_category_keys)) {
array_push($missing_categories, $category->name);
array_push($missing_template_categories, $category->name);
} else {
@@ -208,37 +213,25 @@ class Wiaas_Admin_Template_Selection {
$quantity_from_template = $category->quantity;
if ((int)($quantity_from_template) !== $product_from_bundle_quantity) {
array_push($insufficient_product_quantities, $category->name);
array_push($insufficient_template_category_quantities, $category->name);
}
}
}
}
$categories_message = implode(',', $missing_categories);
$quantity_message = implode(',', $insufficient_product_quantities);
$template_categories_message = implode(',', $missing_template_categories);
$quantity_message = implode(',', $insufficient_template_category_quantities);
if (!empty($missing_categories)) {
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $categories_message, 'woocommerce-product-bundles'));
if (!empty($missing_template_categories)) {
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories missing: ' . $template_categories_message, 'woocommerce-product-bundles'));
}
if (!empty($insufficient_product_quantities)) {
if (!empty($insufficient_template_category_quantities)) {
WC_PB_Meta_Box_Product_Data::add_admin_error(__(' <strong> WIAAS This product bundle does not correspond to selected template</strong> Categories with different quantities: ' . $quantity_message, 'woocommerce-product-bundles'));
}
}
}
public static function get_category_ids_form_bundle($product) {
$products_form_budnle = $product->get_bundled_data_items();
$product_ids = array();
foreach ($products_form_budnle as $product) {
array_push($product_ids, $product->get_id());
}
return self::get_product_categories($product_ids);
}
}
Wiaas_Admin_Template_Selection::init();

View File

@@ -21,6 +21,10 @@ class Wiaas_Template_Admin_Ajax {
}
/**
* An ajax callback action for handling template selection
*/
public static function ajax_handle_template_selection() {
$selected_template_id = intval($_POST['selected_template']);
@@ -34,7 +38,7 @@ class Wiaas_Template_Admin_Ajax {
if (!empty($template_products)) {
ob_start();
Wiaas_Admin_Template_Selection::render_template_products($template_products['hardware']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['service']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['services']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['installation']);
Wiaas_Admin_Template_Selection::render_template_products($template_products['software']);
@@ -53,7 +57,7 @@ class Wiaas_Template_Admin_Ajax {
check_ajax_referer('wc_bundles_add_bundled_product', 'security');
$loop = intval($_POST['id']);
$product_id = intval($_POST['product_id']);
$template_category_id = intval($_POST['template_category_id']);
$title = $_POST['title'];
$options = $_POST['options'];
@@ -70,16 +74,17 @@ class Wiaas_Template_Admin_Ajax {
}
/**
*
* Handles adding template categories search.
*/
public static function ajax_wiaas_template_category_search() {
$term = ($_POST['term']);
$term = wp_unslash($_GET['term']);
$response = array();
$terms = get_terms(array(
'taxonomy' => 'template_category',
'name__like' => $term
'name__like' => $term,
'hide_empty' => false
));
foreach ($terms as $t) {

View File

@@ -7,11 +7,9 @@ class Wiaas_template {
public static function init() {
add_filter('product_type_selector', array(__CLASS__, 'add_template_product_type'));
add_action('admin_footer', array(__CLASS__, 'templates_custom_js'));
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'custom_product_tabs'));
add_action('woocommerce_product_data_panels', array(__CLASS__, 'wiaastemplate_product_tab_content_all'));
add_action('woocommerce_admin_process_product_object', array(__CLASS__, 'save_wiaastemplate'));
add_filter('woocommerce_product_data_tabs', array(__CLASS__, 'hide_attributes_data_panel'));
add_action('woocommerce_process_product_meta_wiaastemplate', array(__CLASS__, 'save_wiaastemplate'));
// Enqueue scripts.
@@ -35,7 +33,7 @@ class Wiaas_template {
}
/**
* Add to product type drop down.
* Add template product type drop down.
*/
function add_template_product_type($types) {
@@ -48,27 +46,7 @@ class Wiaas_template {
/**
* Show pricing fields for template product.
*/
function templates_custom_js() {
if ('product' != get_post_type()) :
return;
endif;
?>
<script type='text/javascript'>
jQuery(document).ready(function () {
jQuery('.options_group.pricing').addClass('show_if_simple_template').show();
});
</script><?php
}
/**
* Add a custom product tab.
* Add template product, hardware, services, installation and software tabs product tab.
*/
function custom_product_tabs($tabs) {
@@ -100,6 +78,10 @@ class Wiaas_template {
}
/**
* Add content do template tabs
*/
public static function wiaastemplate_product_tab_content_all() {
self::wiaastemplate_product_tab_content('hardware');
@@ -110,8 +92,11 @@ class Wiaas_template {
/**
* Contents of the template options product tab.
* Html contents of the template options product tab.
*
* @param $options string main wiaas category
*/
public static function wiaastemplate_product_tab_content($options) {
global $post;
@@ -128,7 +113,7 @@ class Wiaas_template {
foreach ($template_items as $item) {
$product_id = $item['template_category_id'];
$template_category_id = $item['template_category_id'];
$title = $item['template_category_title'];
$quantity = $item['quantity'];
@@ -142,7 +127,7 @@ class Wiaas_template {
<select class="wiaas-term-search" id="wiaastemplate_products<?php echo '_' . $options ?>" style="width: 250px;"
name="template_product"
data-placeholder="<?php _e('Add product to template&hellip;', 'wiaas'); ?>"
data-action="woocommerce_json_search_products" multiple="multiple" data-limit="500">
multiple="multiple" data-limit="500">
<option></option>
</select>
<?php echo wc_help_tip(__('Search for a product and add it to this template by clicking its name in the results list.', 'wiaas')); ?>
@@ -154,7 +139,7 @@ class Wiaas_template {
/**
* Save the custom fields.
* Save the template categories that are bind to template.
*/
function save_wiaastemplate($post_id) {
@@ -163,14 +148,21 @@ class Wiaas_template {
$posted_template_data_installation = isset($_POST['template_data_installation']) ? $_POST['template_data_installation'] : false;
$posted_template_data_software = isset($_POST['template_data_software']) ? $_POST['template_data_software'] : false;
self::save_template_product_meta($post_id, $posted_template_data_hardware, 'hardware');
self::save_template_product_meta($post_id, $posted_template_data_services, 'services');
self::save_template_product_meta($post_id, $posted_template_data_installation, 'installation');
self::save_template_product_meta($post_id, $posted_template_data_software, 'software');
self::process_and_save_template_product_meta($post_id, $posted_template_data_hardware, 'hardware');
self::process_and_save_template_product_meta($post_id, $posted_template_data_services, 'services');
self::process_and_save_template_product_meta($post_id, $posted_template_data_installation, 'installation');
self::process_and_save_template_product_meta($post_id, $posted_template_data_software, 'software');
}
public static function save_template_product_meta($post_id, $posted_template_data, $option) {
/**
* Get extract posted data and save them to meta
*
* @param $post_id integer id of the template
* @param $posted_template_data mixed
* @param $option string indicating main wiaas category
*/
public static function process_and_save_template_product_meta($post_id, $posted_template_data, $option) {
$processed_template_data = array();
// Sort posted data by menu order.
@@ -178,24 +170,24 @@ class Wiaas_template {
foreach ($posted_template_data as $data) {
$product_id = isset($data['product_id']) ? absint($data['product_id']) : false;
$product_title = isset($data['product_title']) ? $data['product_title'] : false;
$template_category_id = isset($data['template_category_id']) ? absint($data['template_category_id']) : false;
$template_category_title = isset($data['template_category_title']) ? $data['template_category_title'] : false;
$quantity = isset($data['quantity']) ? absint($data['quantity']) : false;
$item_data = array(
'template_category_id' => $product_id,
'template_category_title' => trim($product_title),
'template_category_id' => $template_category_id,
'template_category_title' => trim($template_category_title),
'quantity' => $quantity
);
$processed_template_data[$product_id] = $item_data;
$processed_template_data[$template_category_id] = $item_data;
}
update_post_meta($post_id, '_template_items_' . $option, $processed_template_data);
WC_Product_Template::save_template_product_meta($post_id, $option, $processed_template_data);
}
public static function menu_sort_order($a, $b) {
@@ -205,21 +197,6 @@ class Wiaas_template {
return isset($a['menu_order']) ? 1 : -1;
}
}
/**
* Hide Attributes data panel.
*/
function hide_attributes_data_panel($tabs) {
$tabs['advanced']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
$tabs['shipping']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
$tabs['linked_product']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
$tabs['attribute']['class'][] = 'hide_if_simple_wiaastemplate hide_if_wiaastemplate';
return $tabs;
}
}
Wiaas_template::init();

View File

@@ -18,8 +18,8 @@ if (!defined('ABSPATH')) {
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][item_id]" class="item_id" value="<?php echo $item_id; ?>" /><?php
}
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][product_title]" class="product_title" value="<?php echo $title; ?>" /><?php
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][product_id]" class="product_id" value="<?php echo $product_id; ?>" />
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][template_category_title]" class="product_title" value="<?php echo $title; ?>" /><?php
?><input type="hidden" name="template_data_<?php echo $options?>[<?php echo $loop; ?>][template_category_id]" class="product_id" value="<?php echo $template_category_id; ?>" />
</div><?php

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

@@ -6,348 +6,333 @@ class Wiaas_Cart_API {
*
* @var string
*/
private static $namespace = 'wiaas/cart';
private static $namespace = 'wiaas';
private static $rest_base = 'cart';
public static function register_routes() {
register_rest_route( self::$namespace, 'count', array(
'methods' => 'GET',
register_rest_route( self::$namespace, '/' . self::$rest_base . '/count', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(__CLASS__, 'get_cart_count'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
'permission_callback' => 'is_user_logged_in',
) );
register_rest_route( self::$namespace, 'items', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_cart_items'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
register_rest_route( self::$namespace, '/' . self::$rest_base . '/items', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(__CLASS__, 'get_cart_items'),
'permission_callback' => 'is_user_logged_in',
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(__CLASS__, 'add_package_to_cart'),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'package_id' => array(
'description' => __( 'Wiaas package ID.', 'wiaas' ),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
'cl_id' => array(
'description' => __( 'Commercial lead ID.', 'wiaas' ),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
'price_id' => array(
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
'type' => 'string',
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
'required' => true,
'sanitize_callback' => 'sanitize_key',
),
'options_ids' => array(
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
'sanitize_callback' => 'absint',
)
),
'addons_ids' => array(
'description' => __( 'Wiaas package addons IDs.', 'wiaas' ),
'type' => 'array',
'items' => array(
'type' => 'integer',
'sanitize_callback' => 'absint',
)
)
)
),
) );
register_rest_route( self::$namespace, 'documents', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_cart_documents'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
register_rest_route( self::$namespace, '/' . self::$rest_base . '/items/(?P<key>[\w-]+)', array(
'args' => array(
'key' => array(
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
),
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array(__CLASS__, 'remove_package_from_cart'),
'permission_callback' => 'is_user_logged_in',
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array(__CLASS__, 'update_package_quantity'),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'quantity' => array(
'description' => __( 'New quantity cart package item.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
)
)
)
) );
register_rest_route( self::$namespace, 'add', array(
'methods' => 'post',
'callback' => array(__CLASS__, 'add_package_to_cart'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
) );
register_rest_route(self::$namespace, '/' . self::$rest_base . '/documents', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(__CLASS__, 'get_cart_documents'),
'permission_callback' => 'is_user_logged_in',
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(__CLASS__, 'upload_cart_document'),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'doc_type' => array(
'description' => __( 'Category of uploaded document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'required' => true
),
'package_key' => array(
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'required' => true
),
'type' => array(
'default' => 'wiaas_doc'
)
)
)
));
register_rest_route( self::$namespace, 'remove', array(
'methods' => 'post',
'callback' => array(__CLASS__, 'remove_package_from_cart'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
) );
register_rest_route(self::$namespace, '/' . self::$rest_base . '/items/(?P<key>[\w-]+)/documents/(?P<type>[\w-]+)', array(
'args' => array(
'key' => array(
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
),
'type' => array(
'description' => __( 'Cart document Type.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
),
),
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(__CLASS__, 'download_cart_document'),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'document_key' => array(
'description' => __( 'Unique key identifier for cart document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'required' => true
),
)
),
));
register_rest_route( self::$namespace, 'update-quantity', array(
'methods' => 'post',
'callback' => array(__CLASS__, 'update_package_quantity'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
register_rest_route( self::$namespace, '/' . self::$rest_base . '/checkout', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(__CLASS__, 'checkout'),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'vat' => array(
'description' => __( 'Vat Code for new order.', 'wiaas' ),
'type' => 'string',
'required' => true,
'sanitize_callback' => 'sanitize_key',
),
'company' => array(
'description' => __( 'Company name for new order.', 'wiaas' ),
'type' => 'string',
'required' => true,
'sanitize_callback' => 'sanitize_key',
),
'reference' => array(
'description' => __( 'Location details for new order.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
),
'tender' => array(
'description' => __( 'Invoice reference for new order.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
),
'project_id' => array(
'description' => __( 'Order project ID for new order.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
),
'delivery_address_id' => array(
'description' => __( 'ID of delivery address for new order.', 'wiaas' ),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
'billing_address_id' => array(
'description' => __( 'ID of billing address for new order.', 'wiaas' ),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
)
) );
register_rest_route( self::$namespace, 'place-order', array(
'methods' => 'post',
'callback' => array(__CLASS__, 'place_order'),
'permission_callback' => array( __CLASS__, 'permission_check' ),
) );
}
public static function permission_check() {
if (!is_user_logged_in()) {
return new WP_Error( 'wiaas_rest_authorization_required',
__( 'Sorry, only authorized users can access!', 'wiaas' ),
array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
/**
* Get cart count
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
* @return WP_REST_Response
*/
public static function get_cart_count() {
$items = WC()->cart->get_cart_contents();
$count = 0;
foreach ($items as $key => $item) {
if (isset($item['_wiaas_standard_package'])) {
$count++;
}
}
return new WP_REST_Response(array(
'count' => $count,
return rest_ensure_response(array(
'count' => Wiaas_Cart::get_cart_packages_count(),
));
}
/**
* Get cart items
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
*
* @return WP_REST_Response
*/
public static function get_cart_items() {
$items = WC()->cart->get_cart_contents();
$result = array();
foreach ($items as $key => $item) {
if (!isset($item['_wiaas_standard_package'])) {
continue;
}
$package = wc_get_product($item['product_id']);
// Retrieve package addons
$addon_cart_items = wiaas_get_cart_item_addons($item);
$additional_packages = array();
foreach ($addon_cart_items as $addon_cart_item) {
$additional_package = wc_get_product($addon_cart_item['product_id']);
$additional_packages[] = array(
'idAdditionalPackage' => $additional_package->get_id(),
'packageName' => $additional_package->get_title(),
'prices' => array(
'fixedExtra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
'recurrentExtra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
'servicesExtra' => $addon_cart_item['_wiaas_payment']['services_extra'],
)
);
}
// Retrieve package options
$option_cart_items = wiaas_get_cart_item_options($item);
$package_options = array();
foreach ($option_cart_items as $option_cart_item) {
$option_package = wc_get_product($option_cart_item['product_id']);
$package_options[] = array(
'idOptionPackage' => $option_package->get_id(),
'groupName' => $option_cart_item['_wiaas_option_group_name'],
'packageName' => $option_package->get_title(),
'prices' => array(
'fixedExtra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
'recurrentExtra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
'servicesExtra' => $option_cart_item['_wiaas_payment']['services_extra'],
)
);
}
$totalPrices = Wiaas_Cart::get_cart_item_total($item);
$country = Wiaas_Countries::get_package_country($package);
return rest_ensure_response(array(
'items' => Wiaas_Cart::get_cart_packages(),
));
}
$result[] = array(
'idPackage' => $item['product_id'],
'key' => $item['key'],
'packageName' => $package->get_title(),
'additionalPackages' => $additional_packages,
'areAdditionalAvailable' => true,
'areOptionsAvailable' => true,
'bids' => array(),
'commercialLead' => 'Coor Service Management',
'country' => array(
'currency' => $country['currency']
),
'options' => $package_options,
'quantity' => $item['quantity'],
/**
* @param WP_REST_Request $request Request data.
*
* @return WP_REST_Response
*/
public static function add_package_to_cart($request) {
'idPayType' => $item['_wiaas_payment']['id'],
'payType' => $item['_wiaas_payment']['payment_type'],
'periodUnit' => $item['_wiaas_payment']['period_unit'],
'idPrice' => $item['_wiaas_payment']['id'],
'fixedPrice' => $item['_wiaas_payment']['fixed_extra'],
'recurrentPrice' => $item['_wiaas_payment']['recurrent_extra'],
'servicesPrice' => $item['_wiaas_payment']['services_extra'],
'totalPrices' => array(
'fixedPrice' => $totalPrices['fixed_extra'],
'recurrentPrice' => $totalPrices['recurrent_extra'],
'servicesPrice' => $totalPrices['services_extra'],
),
'status' => 'available',
'idCommercialLead' => 14,
);
}
return new WP_REST_Response(
array(
'cartItems' => $result,
'items' => $items,
'totalPrice' => ''
)
$success = Wiaas_Cart::add_package_to_cart(
$request['package_id'],
$request['price_id'],
$request['cl_id'],
$request['addons_ids'],
$request['options_ids']
);
if (!$success) {
return (wc_notice_count('error') > 0) ?
wiaas_api_cart_error_notices() :
wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
}
return wiaas_api_notice('PACKAGE_ADDED', 'success');
}
/**
* Get cart documents
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
* @param WP_REST_Request $request Request data.
*
* @return WP_REST_Response
*/
public static function get_cart_documents() {
return new WP_REST_Response(array(
'areFilesUploaded' => true,
'templates' => array(),
'uploaded' => array()
));
}
public static function remove_package_from_cart($request) {
/**
* Add package to cart
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
* @return WP_REST_Response
* @throws Exception
*/
public static function add_package_to_cart() {
$package_id = $_POST['package_id'];
$success = Wiaas_Cart::remove_package_from_cart($request['key']);
$success = WC()->cart->add_to_cart($package_id, 1, 0, array(), array(
'_wiaas_standard_package' => true
));
if ($success) {
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'success',
'message' => 'PACKAGE_ADDED'
)
)
));
if (!$success) {
return (wc_notice_count('error') > 0) ?
wiaas_api_cart_error_notices() :
wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
}
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'error',
'message' => 'PACKAGE_ALREADY_IN_CART'
)
)
));
}
/*
* Remove package from cart
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
*/
public static function remove_package_from_cart() {
$package_cart_key = $_POST['package_item_key'];
$success = WC()->cart->remove_cart_item($package_cart_key);
if ($success) {
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'success',
'message' => 'PACKAGE_REMOVED_FROM_CART'
)
)
));
}
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'error',
'message' => 'INVALID_PACKAGE_FOR_REMOVE'
)
)
));
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
}
/**
* Update package quantity in cart
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
* @return WP_REST_Response
*/
public static function update_package_quantity() {
$package_item_key = $_POST['package_item_key'];
$new_quantity = $_POST['quantity'];
public static function update_package_quantity($request) {
$success = WC()->cart->set_quantity($package_item_key, $new_quantity, true);
$success = Wiaas_Cart::update_package_quantity($request['key'], $request['quantity']);
if ($success) {
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'success',
'message' => 'QUANTITY_UPDATED'
)
)
));
if (!$success) {
return (wc_notice_count('error') > 0) ?
wiaas_api_cart_error_notices() :
wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
}
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'error',
'message' => 'QUANTITY_NOT_UPDATED'
)
)
));
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
}
/**
* Placing order as part of checkout process
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
* @return WP_REST_Response
* @throws Exception
* Retrive cart documents info
*
* @return mixed|WP_REST_Response
*/
public static function place_order() {
public static function get_cart_documents() {
return rest_ensure_response( Wiaas_Cart::get_cart_documents());
}
$details = $_POST['details'];
$vat_code = $_POST['vat'];
$company_name = $_POST['companyName'];
$delivery_address = $_POST['delivery'];
$billing_address = $_POST['billing'];
/**
* Upload document to cart
* @param WP_REST_Request $request
*
* @return mixed|WP_REST_Response
*/
public static function upload_cart_document($request) {
$success = Wiaas_Cart::upload_cart_document($request['doc_type'], $request['package_key']);
$order_id = WC()->checkout()->create_order(array());
$order = wc_get_order( $order_id );
// set order currency
$line_items = $order->get_items();
foreach ($line_items as $line_item) {
if (isset($line_item['wiaas_currency'])) {
$order->set_currency($line_item['wiaas_currency']);
break;
}
if (!$success) {
return (wc_notice_count('error') > 0) ?
wiaas_api_cart_error_notices() :
wiaas_api_generate_error('UPLOAD_ERROR');
}
$order->set_shipping_city($delivery_address['city']);
$order->set_shipping_country($delivery_address['countryName']);
$order->set_shipping_address_1($delivery_address['detailedAddress']);
$order->set_shipping_postcode($delivery_address['zipCode']);
return wiaas_api_notice('FILE_UPLOADED', 'success');
}
$order->set_billing_city($billing_address['city']);
$order->set_billing_country($billing_address['countryName']);
$order->set_billing_address_1($billing_address['detailedAddress']);
$order->set_billing_postcode($billing_address['zipCode']);
$order->set_billing_first_name($billing_address['firstName']);
$order->set_billing_last_name($billing_address['lastName']);
$order->payment_complete();
/**
* Download cart document
* @param WP_REST_Request $request
*/
public static function download_cart_document($request) {
Wiaas_Document_Download::download_cart_document(
$request['key'],
$request['type'],
$request['document_key']);
}
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
add_post_meta($order_id, '_wiaas_company_name', $company_name);
add_post_meta($order_id, '_wiaas_project_id', $details['idProject']);
add_post_meta($order_id, '_wiaas_reference', $details['reference']);
add_post_meta($order_id, '_wiaas_tender', $details['tender']);
/**
* @param WP_REST_Request $request Request data.
*
* @return WP_REST_Response
*/
public static function checkout($request) {
// $order->get_li
Wiaas_Checkout::process_checkout($request->get_body_params());
WC()->cart->empty_cart( true );
if (wc_notice_count('error') > 0) {
return wiaas_api_cart_error_notices();
}
return new WP_REST_Response(array(
'messages' => array(
array(
'code' => 'success',
'message' => 'ORDER_PLACED'
)
),
'details' => $details
));
return wiaas_api_notice('ORDER_PLACED', 'success');
}
}

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 {
@@ -17,26 +16,101 @@ class Wiaas_Document_API {
private static $namespace = 'wiaas';
public static function register_routes() {
register_rest_route( self::$namespace, 'download-package-file', array(
register_rest_route( self::$namespace, 'documents', array(
'methods' => 'GET',
'permission_callback' => 'is_user_logged_in',
'callback' => array(__CLASS__, 'download_package_file'),
'args' => array(
'document_id' => array(
'description' => __( 'Document ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
)
)
) );
register_rest_route( self::$namespace, 'order/(?P<id>\d+)/item/(?P<item_id>\d+)/document/(?P<key>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Order ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
)
),
array(
'methods' => 'GET',
'permission_callback' => 'is_user_logged_in',
'callback' => array(__CLASS__, 'download_order_item_document'),
'args' => array(
'item_id' => array(
'description' => __( 'Package Order Item ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
'required' => true
),
'key' => array(
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'required' => true
),
)
)
) );
register_rest_route(self::$namespace, 'order/(?P<id>\d+)/document/(?P<key>[\w-]+)', array(
'args' => array(
'id' => array(
'description' => __( 'Order ID.', 'wiaas' ),
'type' => 'integer',
'sanitize_callback' => 'absint',
)
),
array(
'methods' => 'GET',
'permission_callback' => 'is_user_logged_in',
'callback' => array(__CLASS__, 'download_order_other_document'),
'args' => array(
'key' => array(
'description' => __( 'Unique key identifier for order document.', 'wiaas' ),
'type' => 'string',
'sanitize_callback' => 'sanitize_key',
'required' => true
),
)
)
));
}
/**
* Download package document
*
* @param WP_REST_Request $request
*/
public static function download_package_file() {
$document_id = $_GET['document_id'];
$package_id = $_GET['package_id'];
public static function download_package_file($request) {
$document_id = $request['document_id'];
$package = wc_get_product($package_id);
Wiaas_Document_Download::download_document($document_id);
}
$file = $package->get_file($document_id);
/**
* Download order item document
*
* @param WP_REST_Request $request
*/
public static function download_order_item_document($request) {
Wiaas_Document_Download::download_order_item_document(
$request['id'],
$request['item_id'],
$request['key']);
}
if ($file) {
WC_Download_Handler::download_file_force($package->get_file_download_path($document_id), $file->get_name());
}
/**
* Download order document
*
* @param WP_REST_Request $request
*/
public static function download_order_other_document($request) {
Wiaas_Document_Download::download_order_other_document($request['id'], $request['key']);
}
}

View File

@@ -0,0 +1,83 @@
<?php
class Wiaas_Order_Projects_API {
/**
* Endpoint namespace.
*
* @var string
*/
private static $namespace = 'wiaas';
private static $rest_base = 'order-projects';
public static function register_routes() {
register_rest_route( self::$namespace, '/' . self::$rest_base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( __CLASS__, 'get_order_projects' ),
'permission_callback' => 'is_user_logged_in',
'args' => array(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( __CLASS__, 'create_order_project' ),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'name' => array(
'type' => 'string',
'description' => __( 'Order project name.', 'wiaas' ),
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function($param, $request, $key) {
if ($param === '') {
return new WP_Error(
'rest_invalid_param',
'Order project name cannot be empty!'
);
}
if (strlen($param) > 100) {
return new WP_Error(
'rest_invalid_param',
'Order project name cannot be longer than 100 characters!'
);
}
},
),
),
)
) );
}
/**
* Retrieves available order projects
*
* @return WP_REST_Response
*/
public static function get_order_projects() {
$projects = Wiaas_Order_Project::get_available_order_projects();
return rest_ensure_response($projects);
}
/**
* Creates new available order project
*
* @param WP_REST_Request $request Request data.
*
* @return WP_REST_Response
*/
public static function create_order_project($request) {
$name = $request['name'];
$success = Wiaas_Order_Project::add_order_project($name);
if ($success) {
return wiaas_api_notice('PROJECT_ADDED', 'success');
}
return wiaas_api_notice('INVALID_DATA', 'error');
}
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* TODO: Refactor this class so it reflects the fact that customer is an organization
* TODO: Format should be `customer/(?P<organization_id>\d+)/user/(?P<id>\d+)
*
* Class Wiaas_REST_Customer_API
*/
class Wiaas_REST_Customer_API {
/**
* Endpoint namespace.
*
* @var string
*/
private static $namespace = 'wiaas';
public function __construct() {
include_once dirname( __FILE__ ) . '/../user/class-wiaas-customer.php';
}
public static function register_routes() {
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/shops', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_customer_shops'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses', array(
'methods' => 'PUT',
'callback' => array(__CLASS__, 'update_customer_profile_addresses'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses/(?P<address_id>\d+)', array(
'methods' => 'DELETE',
'callback' => array(__CLASS__, 'delete_customer_profile_address'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/billing-addresses', array(
'methods' => 'PUT',
'callback' => array(__CLASS__, 'update_customer_billing_addresses'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/billing-addresses/(?P<address_id>\d+)', array(
'methods' => 'DELETE',
'callback' => array(__CLASS__, 'delete_customer_billing_addresses'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/personal-info', array(
'methods' => 'PUT',
'callback' => array(__CLASS__, 'update_customer_personal_info'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/company-info', array(
'methods' => 'PUT',
'callback' => array(__CLASS__, 'update_customer_company_info'),
'permission_callback' => 'is_user_logged_in'
) );
}
public static function get_customer_shops() {
$customer_shops = Wiaas_Customer::get_customer_shops();
$customer_shops = array_map(function($customer_shop) {
return array(
'id' => $customer_shop['owner_id'],
'type' => $customer_shop['order_type'],
'name' => wiaas_get_organization_name($customer_shop['owner_id'])
);
}, $customer_shops);
return rest_ensure_response($customer_shops);
}
public static function update_customer_profile_addresses(WP_REST_Request $request){
$customer_id = $request['id'];
$params = $request->get_body_params();
$new_address = json_decode($params['profile_address']);
if (!Wiaas_Customer::update_customer_profile_addresses($customer_id, $new_address)){
return wiaas_api_notice('PROFILE_ADDRESS_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
}
return wiaas_api_notice('PROFILE_ADDRESS_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
}
public static function delete_customer_profile_address(WP_REST_Request $request){
$customer_id = $request['id'];
$address_id = $request['address_id'];
if (!Wiaas_Customer::delete_customer_profile_address($customer_id, $address_id)){
return wiaas_api_notice('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
return wiaas_api_notice('ADDRESS_REMOVED', 'success', Wiaas_Customer::get_customer_info($customer_id));
}
public static function update_customer_billing_addresses(WP_REST_Request $request){
$customer_id = $request['id'];
$params = $request->get_body_params();
$new_address = json_decode($params['billing_address']);
if (!Wiaas_Customer::update_customer_billing_addresses($customer_id, $new_address)){
return wiaas_api_notice('BILLING_ADDRESS_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
}
return wiaas_api_notice('BILLING_ADDRESS_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
}
public static function delete_customer_billing_addresses(WP_REST_Request $request){
$customer_id = $request['id'];
$address_id = $request['address_id'];
if (!Wiaas_Customer::delete_customer_billing_address($customer_id, $address_id)){
return wiaas_api_notice('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
return wiaas_api_notice('ADDRESS_REMOVED', 'success', Wiaas_Customer::get_customer_info($customer_id));
}
public static function update_customer_personal_info(WP_REST_Request $request){
$customer_id = $request['id'];
$params = $request->get_body_params();
$first_name = $params['first_name'];
$last_name = $params['last_name'];
$phone = $params['phone'];
$name = $first_name . ' ' . $last_name;
if (!is_string($name) || strlen($name) === 1){
return wiaas_api_notice('ADD_NAME', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
if (!is_string($phone) || strlen($phone) < 1){
return wiaas_api_notice('ADD_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
if (!Wiaas_Customer::update_customer_profile_info($customer_id, $first_name, $last_name, $phone)){
return wiaas_api_notice('PROFILE_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
}
return wiaas_api_notice('PROFILE_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
}
public static function update_customer_company_info(WP_REST_Request $request){
$customer_id = $request['id'];
$params = $request->get_body_params();
$company_name = $params['company_name'];
$vat_code = $params['vat_code'];
if (!is_string($company_name) || strlen($company_name) < 1){
return wiaas_api_notice('ADD_COMPANY_NAME', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
if (!is_string($vat_code) || strlen($vat_code) < 1){
return wiaas_api_notice('ADD_VAT', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
if (!Wiaas_Customer::update_customer_company_info($customer_id, $company_name, $vat_code)){
return wiaas_api_notice('COMPANY_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
}
return wiaas_api_notice('COMPANY_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
}
}

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) {
@@ -93,211 +102,79 @@ class Wiass_REST_Delivery_Process_API {
);
}
$response = new WP_REST_Response( $data );
return rest_ensure_response($data);
}
return $response;
public function get_customer_questionnaires(WP_REST_Request $request) {
$order_id = absint($request['order_id']);
$data = Wiaas_Delivery_Process::get_customer_questionnaires_data($order_id);
return rest_ensure_response($data);
}
public function upload_customer_questionnaire(WP_REST_Request $request) {
$order_id = absint($request['order_id']);
$action_entry_id = absint($request['action_entry_id']);
Wiaas_Delivery_Process::upload_customer_questionnaire($order_id, $action_entry_id);
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
}
public static function get_customer_acceptance(WP_REST_Request $request){
$entry = GFAPI::get_entry($request['entry_id']);
if (is_wp_error($entry)){
return self::generate_error('Customer acceptance entry not found', 404);
}
$acceptance_documents = array();
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
$order_id = absint($request['order_id']);
foreach($uploaded_files as $file_url){
//example of decoded url :
//http://localhost/wp/index.php?gf-download=2018/08/rokovi-1535378841.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534
$decoded_url = urldecode($file_url);
$url_parts = explode('?', $decoded_url);
$file_name_base_parts = explode('&', $url_parts[1]);
$file_name_parts = explode('/', $file_name_base_parts[0]);
$file_name_with_extension_parts = explode('.', $file_name_parts[2]);
$data = Wiaas_Delivery_Process::get_customer_acceptance_data($order_id);
$acceptance_documents_entry = array(
'name' => $file_name_with_extension_parts[0],
'extension' => $file_name_with_extension_parts[1],
'url' => $file_url
);
array_push($acceptance_documents, $acceptance_documents_entry);
}
$acceptance_status = 0;
if ($entry[self::ACCEPTANCE_STATUS_FIELD_ID]){
$acceptance_status = ($entry[self::ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1;
}
$result = array(
'documents' => $acceptance_documents,
'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
'status' => $acceptance_status,
'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
);
return new WP_REST_Response($result);
return rest_ensure_response($data);
}
public static function submit_customer_acceptance(WP_REST_Request $request){
$entry = GFAPI::get_entry($request['entry_id']);
if (is_wp_error($entry)){
return self::generate_error('Customer acceptance entry not found', 404);
}
public static function submit_customer_acceptance(WP_REST_Request $request) {
$status = $request['actionType'];
$reason = $request['declineReason'];
$status = $request['action_type'];
$reason = $request['decline_reason'];
if (!in_array($status, self::ACCEPTABLE_STATUS)){
return self::generate_wiaas_response('ACCEPTANCE_STATUS_MISSING', 'error');
return wiaas_api_notice('ACCEPTANCE_STATUS_MISSING', 'error');
}
$installation_declined = ($status === self::DECLINE_STATUS_LABEL);
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
if ($installation_declined && $reason === ''){
return self::generate_wiaas_response('DECLINE_REASON_EMPTY', 'error');
return wiaas_api_notice('DECLINE_REASON_EMPTY', 'error');
}
if (!$installation_declined && (count($uploaded_files)===0)){
return self::generate_wiaas_response('ACCEPTANCE_NOT_UPLOADED', 'error');
$order_id = $request['order_id'];
if (! $installation_declined && ! Wiaas_Delivery_Process::is_customer_acceptance_uploaded($order_id)) {
return wiaas_api_notice('ACCEPTANCE_NOT_UPLOADED', 'error');
}
$entry[self::DECLINE_REASON_FIELD_ID] = $reason;
$entry[self::ACCEPTANCE_STATUS_FIELD_ID] = $status;
if (!GFAPI::update_entry( $entry )){
return self::generate_wiaas_response('INTERNAL_SERVER_ERROR', 'error');
}
//Check if step is already completed, to not submit again
$gf_api = new Gravity_Flow_API($entry['form_id']);
$current_step = $gf_api->get_current_step($entry);
if ($current_step->get_name() !== self::USER_INPUT_STEP_NAME){
return self::generate_wiaas_response('ACCEPTANCE_STATUS_UPDATED', 'success');
}
if ( $current_step ) {
$current_step->purge_assignees();
$current_step->update_step_status( 'complete' );
}
$entry_id = $entry['id'];
$new_step_id = $current_step->get_id() + 1;
$new_step = $gf_api->get_step( $new_step_id, $entry );
$feedback = sprintf( esc_html__( 'Sent to step: %s', 'gravityflow' ), $new_step->get_name() );
$gf_api->add_timeline_note( $entry_id, $feedback );
$gf_api->log_activity( 'workflow', 'sent_to_step', $gf_api->form_id, $entry_id, $step_id );
gform_update_meta( $entry_id, 'workflow_final_status', 'pending' );
$new_step->start();
$gf_api->process_workflow( $entry_id );
Wiaas_Delivery_Process::update_customer_acceptance_status($order_id, $status, $reason);
if ($installation_declined){
return self::generate_wiaas_response('INSTALLATION_DECLINED', 'success');
return wiaas_api_notice('INSTALLATION_DECLINED', 'success');
}
return self::generate_wiaas_response('INSTALLATION_ACCEPTED', 'success');
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
}
public static function upload_file(WP_REST_Request $request){
$files = $request->get_file_params();
if (!$files[self::FILE_KEY_NAME]){
return self::generate_wiaas_response('NO_FILES_UPLOADED', 'error');
public static function upload_customer_acceptance(WP_REST_Request $request){
$order_id = $request['order_id'];
$success = Wiaas_Delivery_Process::upload_customer_acceptance_document($order_id);
if ($success) {
return wiaas_api_notice('FILE_UPLOADED','success');
}
$entry = GFAPI::get_entry($request['entry_id']);
if (is_wp_error($entry)){
return self::generate_error('Customer acceptance entry not found', 404);
}
$form = GFAPI::get_form($entry['form_id']);
$form_upload_path = GFFormsModel::get_upload_path( $form['id'] );
$target_path = $form_upload_path . '/' . date('Y') . '/' . date('m') . '/';
wp_mkdir_p( $target_path );
GFCommon::recursive_add_index_file( $target_path );
$upload_file_field = GFAPI::get_field($form['id'], self::UPLOADED_FILES_FIELD_ID);
$file_name = sanitize_file_name($files[self::FILE_KEY_NAME]['name']);
$file_path_details = pathinfo($file_name);
if ( GFCommon::file_name_has_disallowed_extension( $file_name ) ) {
return self::generate_wiaas_response('INVALID_FILE_ACCEPTANCE', 'error');
}
$allowed_extensions = ! empty( $upload_file_field->allowedExtensions ) ? GFCommon::clean_extensions( explode( ',', strtolower( $upload_file_field->allowedExtensions ) ) ) : array();
if ( ! empty( $allowed_extensions ) ) {
if ( ! GFCommon::match_file_extension( $file_name, $allowed_extensions ) ) {
return self::generate_wiaas_response('INVALID_FILE_ACCEPTANCE', 'error');
}
}
$new_file_name = $file_path_details['filename'] . '-' . time() . '.' . $file_path_details['extension'];
// Bypasses security checks when running unit tests.
if ( defined( 'WP_TEST_IN_PROGRESS' ) && WP_TEST_IN_PROGRESS ) {
return self::generate_wiaas_response('FILE_UPLOADED', 'success');
}
if ( move_uploaded_file($files[self::FILE_KEY_NAME]['tmp_name'], $target_path . $new_file_name ) ) {
GFFormsModel::set_permissions( $target_path . $new_file_name );
} else {
return self::generate_wiaas_response('INTERNAL_SERVER_ERROR', 'error');
}
//Extract path relative to the root
//Last 6 strings (excluding last empty) are path relative to the root
$path_parts = explode('/', $target_path);
$relative_path = '';
$i = count($path_parts) - self::PATH_PARTS_TO_EXTRACT;
while($i < count($path_parts)-1){
$relative_path = $relative_path . $path_parts[$i] . '/';
$i++;
}
$file_url = self::BASE_NAME . $relative_path . $new_file_name;
$url_for_download = $upload_file_field->get_download_url($file_url);
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
if ($uploaded_files === NULL){
$uploaded_files = [];
}
array_push($uploaded_files, $url_for_download);
$entry[self::UPLOADED_FILES_FIELD_ID] = json_encode($uploaded_files);
if (GFAPI::update_entry( $entry )) {
return self::generate_wiaas_response('FILE_UPLOADED','success');
}
return self::generate_wiaas_response('NOT_UPLOADED', 'error');
}
//Helper function
private static function generate_error($message, $code = 500){
$error = array(
'status' => $code,
'message' => $message,
);
$result = new WP_REST_Response($error);
$result->set_status($code);
return $result;
}
private static function generate_wiaas_response($message, $code, $data = NULL){
$response = array(
'messages' => [
array(
'code' => $code,
'message' => $message
)
],
'data' => $data
);
return new WP_REST_Response($response);
return wiaas_api_notice('NOT_UPLOADED', 'error');
}
}

View File

@@ -0,0 +1,50 @@
<?php
class Wiass_REST_User_API {
/**
* Endpoint namespace.
*
* @var string
*/
private static $namespace = 'wiaas';
public function __construct() {
include_once dirname( __FILE__ ) . '/../class-wiaas-countries.php';
}
public static function register_routes() {
register_rest_route( self::$namespace, 'user/validate-token', array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'validate_token'),
'permission_callback' => 'is_user_logged_in'
) );
register_rest_route( self::$namespace, 'user/get-countries', array(
'methods' => 'GET',
'callback' => array(__CLASS__, 'get_countries'),
'permission_callback' => 'is_user_logged_in'
) );
}
public static function validate_token() {
$user = wp_get_current_user();
return rest_ensure_response(array(
'userInfo' => array(
'wiaas_id_user' => $user->ID,
'wiaas_is_company_admin' => 1, //TODO: don't hardcode this
'wiaas_user_full_name' => $user->first_name . ' ' . $user->last_name,
'wiaas_user_type' => $user->roles,
'wiaas_username' => $user->data->user_login
)
));
}
public static function get_countries(){
$countries = Wiaas_Countries::get_list_of_countries();
return rest_ensure_response($countries);
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* Implements wiaas shop based search on top of woocommerce product api
*
* Class Wiaas_WC_Package_API_Integration
*/
class Wiaas_WC_Package_API_Integration {
/**
* Rest base for woocommerce product search
*
* @var string
*/
private static $wc_rest_base = '/wc/v2/products';
public static function init() {
add_filter('woocommerce_rest_product_object_query', array(__CLASS__, 'filter_packages'), 10, 2);
add_filter('rest_dispatch_request', array(__CLASS__, 'validate_package_search_request'), 10, 4);
}
/**
* Force wc api request to send shop id when searching packages
*
* @param $null
* @param $request
* @param $route
* @param $handler
*
* @return null|WP_Error
*/
public static function validate_package_search_request($null, $request, $route, $handler) {
if (strpos($route, self::$wc_rest_base) !== false) {
if (empty($request['shop_id']) || ! absint($request['shop_id'])) {
return new WP_Error(
'missing_shop',
'Shop parameter is missing',
array ( 'status' => 400 )
);
}
}
return null;
}
/**
* Filter woocommerce REST API query so only valid wiaas packages are returned to the customer
*
* @param $args
* @param $request
*
* @return mixed
*/
public static function filter_packages($args, $request) {
if ( empty($args['tax_query']) ){
$args['tax_query'] = array();
}
// Retrieve only packages with available package status
$args['tax_query'][] = array(
'taxonomy' => 'package_status',
'field' => 'name',
'terms' => Wiaas_Package_Status::AVAILABLE
);
/**
* Retrieve packages that satisfy one of two:
*
* 1) Package has at least one visible customer specific price set (for current customer)
* 2) Package has at least one visible default price set and not customer specific prices set (for current customer)
*
* This approach enables us that if package has specific prices set for current customer only those prices
* are taken into account and default ones are ignored.
* Only if package has no specific prices for current customer default prices are taken into account.
*
*/
$shop_id = absint($request['shop_id']);
$customer_id = wiaas_get_current_user_organization_id();
$default_price_search_term = '_' . $shop_id . '_default';
$customer_visible_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_visible';
$customer_hidden_price_search_term = '_' . $shop_id . '_customer_' . $customer_id . '_hidden';
$args['tax_query'][] = array(
'relation' => 'OR',
array(
'taxonomy' => '_wiaas_shop_prices',
'terms' => $customer_visible_price_search_term,
'field' => 'slug'
),
array(
array(
'taxonomy' => '_wiaas_shop_prices',
'terms' => $default_price_search_term,
'field' => 'slug'
),
array(
'taxonomy' => '_wiaas_shop_prices',
'terms' => $customer_hidden_price_search_term,
'field' => 'slug',
'operator' => 'NOT IN'
)
)
);
return $args;
}
}
Wiaas_WC_Package_API_Integration::init();

View File

@@ -0,0 +1,93 @@
<?php
/**
* Generates REST API notice response
*
* @param string $message
* @param string $code
* @param array|null $data
*
* @return WP_REST_Response
*/
function wiaas_api_notice($message, $code, $data = null) {
return rest_ensure_response(array(
'messages' => [
array(
'code' => $code,
'message' => $message
)
],
'data' => $data
));
}
/**
* Generates REST API notice responses with wc error notices
*
* @param array|null $data
*
* @return WP_REST_Response
*/
function wiaas_api_cart_error_notices($data = null) {
return wiaas_api_cart_notices('error', $data);
}
/**
* Generates REST API notice responses with wc warning notices
*
* @param array|null $data
*
* @return WP_REST_Response
*/
function wiaas_api_cart_warning_notices($data = null) {
return wiaas_api_cart_notices('notice', $data);
}
/**
* Generates REST API notice responses with wc notices
*
* @param string $types Notice types (error, success)
* @param array|null $data
*
* @return WP_REST_Response
*/
function wiaas_api_cart_notices($types, $data = null) {
$types = is_array($types) ? $types : array( $types );
$messages = array();
foreach ($types as $type) {
$messages = array_merge($messages, wc_get_notices($type));
}
wc_clear_notices();
$messages = array_map(function($message) {
return array(
'code' => 'error',
'message' => $message
);
}, $messages);
return rest_ensure_response(array(
'messages' => $messages,
'data' => $data
));
}
/**
* Generate REST API error
*
* @param string $message
* @param int $code
*
* @return WP_REST_Response
*/
function wiaas_api_generate_error($message, $code = 500) {
$response = rest_ensure_response(array(
'status' => $code,
'message' => $message,
));
$response->set_status($code);
return $response;
}

View File

@@ -0,0 +1,36 @@
<?php
class Wiaas_Cart_Documents {
private static $document_types = array(
'template_questionaire' => 'template_agreement',
'order_questionaire' => 'order_agreement'
);
public static function get_cart_documents() {
$packages_data = Wiaas_Cart::get_cart_packages();
$templates = array();
foreach ($packages_data as $package_data) {
$package = wc_get_product($packages_data['package_id']);
$documents = $package->get_downloads();
}
get_terms(array(
'taxonomy' => 'wiaas_document_types',
'include' => 'template_questionaire, order_questionaire'
));
}
private static function _get_packages_templates($packages) {
$documents_ids = array_map(function($package) {
return array_keys($package->get_downloads());
}, $packages);
wp_get_object_terms($documents_ids, 'wiaas_document_types', array(
));
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* Class Wiaas_Access_Management
*/
class Wiaas_Access_Management {
/**
* Handles organization and role based access management to wiaas objects (orders, products)
*
* Using Groups Access for achieve this
*
*/
public static function init() {
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
add_action('woocommerce_payment_complete', array( __CLASS__, 'assign_order_to_suppliers'),20,1 );
}
/**
* Automatize access control for product and packages
*
* @param int $post_id
* @param WP_Post $post
*/
public static function maybe_handle_product_access($post_id, $post) {
// $post_id and $post are required
if ( empty( $post_id ) || empty( $post ) || $post->post_type !== 'product') {
return;
}
$product = wc_get_product($post_id);
$access_group = null;
// if product is not bundle or it not completed set it visible only for admin
if ($product->get_type() !== 'bundle' ||
$product->get_status() !== 'publish' ||
empty(Wiaas_Package_Pricing::get_package_prices($product))) {
$access_group = Groups_Group::read_by_name('admin');
} else {
$access_group = Groups_Group::read_by_name('Registered');
}
if ($access_group) {
Groups_Post_Access::update(
array(
'post_id' => $product->get_id(),
'groups_read' => $access_group->group_id
)
);
}
}
/**
* Assignees order to corresponding user organization when order is created.
*
* @param int $order_id
*/
public static function assign_order_to_organization($order_id) {
// assign order to customer organization
$customer_id = wiaas_get_current_user_organization_id();
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
$order = wc_get_order($order_id);
// assign order to commercial lead organization
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
if ($commercial_lead_id) {
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
}
}
/**
* Assignees order to supplier organizations extracted from ordered items when order payment is complete.
*
* @param int $order_id
*/
public static function assign_order_to_suppliers($order_id){
$order = wc_get_order($order_id);
$product_from_order = $order->get_items('line_item');
foreach ($product_from_order as $product_item) {
$supplier_organisation_id = Wiaas_Product_Supplier
::get_supplier_organisation_id_from_product($product_item->get_product_id());
Wiaas_User_Organization::assign_post_to_organization($order_id, $supplier_organisation_id);
}
}
}
Wiaas_Access_Management::init();

View File

@@ -1,18 +1,46 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Wiaas_Admin {
public static function init() {
require_once dirname( __FILE__ ) . '/admin/class-wiaas-admin-package.php';
require_once dirname( __FILE__ ) . '/admin/class-wiaas-admin-pricing.php';
require_once dirname(__FILE__) . '/admin/template/class-wiaas-admin-template-selection.php';
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-products.php';
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-admin-ajax.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-simple-product.php';
// Admin order projects interface
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-projects.php';
// Admin documents
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
// Admin organization interface
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
// Admin order delivery process
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-product.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-delivery-process.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-supplier.php';
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
}
public static function enqueue_scripts() {
$plugin_url = untrailingslashit( plugins_url( '/', WIAAS_FILE ) );
wp_enqueue_style( 'wiaas_admin_menu', $plugin_url . '/assets/css/menu.css' );
wp_enqueue_style( 'wiaas_admin_packages', $plugin_url . '/assets/css/wiaas-admin-package.css' );
wp_enqueue_script( 'wiaas_admin_packages', $plugin_url . '/assets/js/wiaas-admin-package.js' );
}
}
Wiaas_Admin::init();

View File

@@ -34,13 +34,30 @@ class Wiaas_API {
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-delivery-process-api.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-cart-api.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-document-api.php';
#User controller
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-user-api.php';
#Customer controller
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-customer.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
// API functions
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
}
public static function register_rest_routes() {
$controllers = array(
'Wiass_REST_Delivery_Process_API',
'Wiaas_Cart_API',
'Wiaas_Document_API'
'Wiaas_Document_API',
'Wiass_REST_User_API',
'Wiaas_REST_Customer_API',
'Wiaas_Order_Projects_API',
);
foreach ( $controllers as $controller ) {

View File

@@ -0,0 +1,185 @@
<?php
/**
* Handles user authentication for wiaas
*
* User roles are inherited from organization
*
* Class Wiaas_Authentication
*/
class Wiaas_Authentication {
const SUPER_ADMIN_USER_ID = 1;
public static function init() {
// authenticate current user
add_action('determine_current_user', array(__CLASS__, 'authenticate_current_user'), 999);
// authenticates user on login
add_filter( 'authenticate', array( __CLASS__, 'authenticate_user_on_login' ), 999, 3);
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'authenticate_rest_user_on_login'), 999, 2);
// redirect to dashboard after login
add_filter( 'login_redirect', array( __CLASS__, 'login_redirect' ) );
}
/**
* Redirect admin user to dashboard
*
* @return string
*/
public static function login_redirect() {
return admin_url('index.php') ;
}
/**
* Authenticate current user based on roles assigned to organization
*
* If this is non admin request successfully validate user if he can have customer role.
*
* If this is admin panel request successfully validate user if has admin panel role selected
* and also he still can have that role (role was not removed from his customer organization)
*
* @param int|false $user_id
* @return int|false|WP_Error
*/
public static function authenticate_current_user($user_id) {
// do nothing if user not authenticated, user is super admin or this is REST API request
if (! $user_id || (int) $user_id === self::SUPER_ADMIN_USER_ID) {
return $user_id;
}
global $current_user;
if (empty($current_user)) {
$current_user = new WP_User($user_id);
}
$rest_api_slug = rest_get_url_prefix();
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
if ($valid_api_uri) {
//for non admin request check if user has customer role
$role = 'customer';
} else {
// for admin panel request check if user has selected role
$role = get_user_meta($user_id, '_wiaas_admin_role', true);
}
if ( empty($role) || ! user_can($user_id, 'wiaas_' . $role)) {
// not available roles for user
$current_user->set_role('');
return new WP_Error('wiaas_authentication_error', 'No set permissions!', array(
'status' => 403,
));
}
// authenticate valid admin panel user
$current_user->set_role($role);
return $user_id;
}
/**
* Authenticate wiaas user on login based on roles assigned to organization
*
* If this is non admin panel request authenticate user if he can be customer.
*
* If this is admin panel login request user will be authenticated with previously selected or first available role
* from his organization roles.
*
* @param WP_User $user
* @return WP_User|WP_Error
*/
public static function authenticate_user_on_login($user) {
// do nothing if there is an error already,
// user is super admin
if (is_wp_error($user) || $user->ID === self::SUPER_ADMIN_USER_ID ) {
return $user;
}
$rest_api_slug = rest_get_url_prefix();
$valid_api_uri = strpos($_SERVER['REQUEST_URI'], $rest_api_slug);
/**
* CUSTOMER API AUTHENTICATION
*/
// validate customer user login
if ($valid_api_uri) {
$role = user_can($user->ID, 'wiaas_customer') ? 'customer' : '';
$user->set_role($role);
return empty($role) ?
new WP_Error('wiaas_authentication_error', 'No Customer permissions!', array(
'status' => 403,
)) :
$user;
}
/**
* ADMIN PANEL AUTHENTICATION
*/
// retrieve selected role for user
$role = get_user_meta($user->ID, '_wiaas_admin_role', true);
// if user has selected role then use it
if (! empty($role) && user_can($user->ID, 'wiaas_' . $role)) {
return $user;
}
// user does not have selected role so try to assign one in order of access
if (user_can($user->ID, 'wiaas_administrator')) {
$role = 'administrator';
} else if (user_can($user->ID, 'wiaas_commercial_lead')) {
$role = 'commercial_lead';
} else if (user_can($user->ID, 'wiaas_supplier')) {
$role = 'supplier';
}
if (empty($role)) {
return new WP_Error('wiaas_authentication_error', 'No permissions!', array(
'status' => 403,
));
}
update_user_meta($user->ID, '_wiaas_admin_role', $role);
$user->set_role($role);
return $user;
}
/**
* validate that successfully logged in rest api user can be customer
*
* @param array $data
* @param WP_User $user
* @return array | WP_Error
*
*/
public static function authenticate_rest_user_on_login($data, $user) {
// if admin do nothing
if ($user->ID === self::SUPER_ADMIN_USER_ID) {
return $data;
}
$role = user_can($user->ID, 'wiaas_customer') ? 'customer' : '';
$user->set_role($role);
return empty($role) ?
new WP_Error('wiaas_authentication_error', 'No Customer permissions!', array(
'status' => 403,
)) :
$data;
}
}
Wiaas_Authentication::init();

View File

@@ -6,121 +6,301 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* TODO: This implementation is temporary and will probably be changed during implementation of currently pending cart task
* Handles Wiaas Cart specific tasks
*
* Class Wiaas_Cart
*/
class Wiaas_Cart {
private static $cart_doc_types = array(
'template_questionaire' => 'order_questionaire',
'template_agreement' => 'order_agreement'
);
public static function init() {
add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
// Add options and addons to cart.
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
add_action('woocommerce_checkout_create_order', array(__CLASS__, 'add_additional_order_data'), 99);
add_action('woocommerce_set_cart_cookies', array(__CLASS__, 'do_not_set_cart_cookies'));
}
/**
* Do not set cart cookies
*/
public static function do_not_set_cart_cookies() {
if ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) {
wc_setcookie( 'woocommerce_items_in_cart', 0, time() - HOUR_IN_SECONDS );
wc_setcookie( 'woocommerce_cart_hash', '', time() - HOUR_IN_SECONDS );
}
}
/**
* Retrieve cart documents (templates and uploded documents)
* @return array
*/
public static function get_cart_documents() {
$templates = self::_get_cart_templates();
$uploaded_documents = self::_get_cart_uploaded_documents();
$has_pending_uploads = false;
foreach ($templates as $type => $package_documents) {
$uploaded_type = self::$cart_doc_types[$type];
if (!isset($uploaded_documents[$uploaded_type])) {
$has_pending_uploads = true;
break;
}
$uploaded_package_documents = $uploaded_documents[$uploaded_type];
foreach ($package_documents as $package_id => $package_document) {
if (!isset($uploaded_package_documents[$package_id])) {
$has_pending_uploads = true;
break;
}
}
}
return array(
'templates' => $templates,
'uploaded' => $uploaded_documents,
'pending' => $has_pending_uploads
);
}
/** Uploaded document for cart
*
* @param $doc_type
* @param $package_item_key
*
* @return string | WP_Error
*/
public static function upload_cart_document($doc_type, $package_item_key) {
try {
$result = Wiaas_Document_Upload::upload_document_version();
// File upload failed
if (is_wp_error($result)) {
$code = $result->get_error_code();
if ($code === 'wiaas_upload_error_missing_file' || $code === 'wiaas_upload_error_invalid_extension') {
wc_add_notice($result->get_error_message(), 'error');
} else {
wc_add_notice('File upload failed!', 'error');
}
return false;
}
// save uploaded cart documents info to cart item
WC()->cart->cart_contents[ $package_item_key ]['_wiaas_documents'][$doc_type] = array(
'version' => $result,
'key' => wp_generate_uuid4(),
);;
// persist changes
WC()->cart->calculate_totals();
return true;
} catch( Exception $e) {
wc_add_notice('Could not upload cart document!', 'error');
return false;
}
}
/**
* Handles adding standard wiaas package to cart along with selected addons and options
*
* Extend cart item data with wiaas package payment info and addons and options
*
* Every package cart item will be extended with its payment info but only standard package type
* will be extended with addons and options arrays
*
* @param $cart_item_data
* @param $package_id
* @param int $package_id Package ID of selected package
* @param string $price_id Price ID of selected package payment
* @param int $shop_owner_id Shop owner commercial lead ID
* @param array $addons_ids Array of selected additional packages IDs
* @param array $options_ids Array of selected option packages IDs
*
* @return array
* @return bool TRUE if all packages are succesfully added to cart, FALSE otherwise
*/
public static function add_cart_item_data($cart_item_data, $package_id) {
public static function add_package_to_cart($package_id, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
// try adding package to cart
try {
// Check if package is in cart
if (self::_is_package_in_cart($package_id)) {
wc_add_notice('Package already in cart!', 'error');
return false;
}
$is_valid = isset( $_POST[ 'price_id' ]) &&
WC_Product_Factory::get_product_type( $package_id ) === 'bundle';
//Check if package exists
$package = wc_get_product( $package_id );
if (!$package) {
wc_add_notice('Package does not exists!', 'error');
return false;
}
if (!$is_valid) {
return $cart_item_data;
//Check if package is available for adding to cart
if (Wiaas_Package_Status::get_package_status($package_id) !== Wiaas_Package_Status::AVAILABLE){
wc_add_notice('Package cannot be purchased at the moment!', 'error');
return false;
}
// Retrieve package country
$country = Wiaas_Countries::get_package_country($package);
if (empty($country)) {
wc_add_notice('Package cannot be added do cart!', 'error');
return false;
}
// Validate that order contains only stuff from single commercial lead / reseller / shop owner
if ( ! WC()->cart->is_empty() ) {
$current_shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
if (absint($shop_owner_id) !== absint($current_shop_owner_id)) {
wc_add_notice('Only packages from one catalogue can be purchased at the same time!', 'error');
return false;
}
} else {
update_user_meta( get_current_user_id(), '_wiaas_cart_shop_owner_id', $shop_owner_id);
}
// Validate that order contains only items for single country
if ( ! WC()->cart->is_empty() ) {
$current_country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
if ($country !== $current_country) {
wc_add_notice('Only packages from one country can be purchased at the same time!', 'error');
return false;
}
} else {
update_user_meta( get_current_user_id(), '_wiaas_cart_items_country', $country);
}
$customer_id = wiaas_get_current_user_organization_id();
// Retrieve package price
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $shop_owner_id);
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
// Initialize additional cart item data for wiaas packages
$wiaas_cart_item_data = array(
'_wiaas_standard_package' => true,
'_wiaas_addon_items' => array(),
'_wiaas_option_items' => array(),
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
'_wiaas_documents' => array()
);
$cart_item_key = WC()->cart->add_to_cart($package_id, 1, 0, array(), $wiaas_cart_item_data);
if (!$cart_item_key) {
wc_add_notice('Package could not be added to cart!', 'error');
return false;
}
// Add selected additional packages and options
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids);
// Trigger calculation of total prices after additional packages are added
WC()->cart->calculate_totals();
return true;
} catch( Exception $e) {
return false;
}
}
/**
* Remove given package item key from cart
*
* @param string $package_cart_item_key
*
* @return bool
*/
public static function remove_package_from_cart($package_cart_item_key) {
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
if (!$cart_item) {
return false;
}
$package_type = Wiaas_Package_Type::get_package_type($package_id);
$package_addon_item_keys = $cart_item['_wiaas_addon_items'];
$package_option_item_keys = $cart_item['_wiaas_option_items'];
$package = wc_get_product( $package_id );
$success = WC()->cart->remove_cart_item($package_cart_item_key);
switch ($package_type) {
case 'standard':
if ($success) {
foreach ($package_addon_item_keys as $package_addon_item_key) {
WC()->cart->remove_cart_item($package_addon_item_key);
}
$cart_item['_wiaas_standard_package'] = true;
// Prepare addons additional data for later use.
if ( ! isset( $cart_item_data['_wiaas_addon_items'] ) ) {
$cart_item_data['_wiaas_addon_items' ] = array();
}
// Prepare options additional data for later use.
if ( ! isset( $cart_item_data['_wiaas_option_items'] ) ) {
$cart_item_data['_wiaas_option_items' ] = array();
}
$country = Wiaas_Countries::get_package_country($package);
if (isset($country)) {
$cart_item_data['_wiaas_currency'] = $country['currency'];
}
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
break;
case 'add_on':
$parent_key = $cart_item_data['_wiaas_addon_for'];
$parent_item = WC()->cart->get_cart_item($parent_key);
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($package, $parent_item['data']);
break;
case 'option':
$parent_key = $cart_item_data['_wiaas_option_for'];
$parent_item = WC()->cart->get_cart_item($parent_key);
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $package);
$cart_item_data['_wiaas_option_group_name' ] = $option_group_name;
$package_prices = Wiaas_Pricing::get_option_package_customer_price($package, $parent_item['data']);
break;
foreach ($package_option_item_keys as $package_option_item_key) {
WC()->cart->remove_cart_item($package_option_item_key);
}
}
$selected_price_index = array_search($_POST['price_id'], array_column($package_prices, 'id'));
if (is_numeric($selected_price_index) && isset($package_prices[$selected_price_index])) {
$cart_item_data['_wiaas_payment'] = $package_prices[$selected_price_index];
}
return $cart_item_data;
return $success;
}
/**
* Add selected package options and addons after parent standard package is added to cart
* Update quantity of package in cart
* @param string $package_cart_item_key
* @param int $new_quantity
*
* @param $cart_item_key
* @param $package_id
* @param $quantity
* @param $variation_id
* @param $variation
* @param $cart_item_data
* @return bool
*/
public static function add_additional_packages_to_cart($cart_item_key, $package_id, $quantity, $variation_id, $variation, $cart_item_data) {
public static function update_package_quantity($package_cart_item_key, $new_quantity) {
if ($new_quantity > 65000){
return false;
}
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
remove_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ));
if (!$cart_item) {
return false;
}
self::_add_options_to_cart($cart_item_key, $package_id, $cart_item_data);
$package_addon_item_keys = $cart_item['_wiaas_addon_items'];
$package_option_item_keys = $cart_item['_wiaas_option_items'];
self::_add_addons_to_cart($cart_item_key, $package_id, $cart_item_data);
$success = WC()->cart->set_quantity($package_cart_item_key, $new_quantity, true);
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
if ($success) {
foreach ($package_addon_item_keys as $package_addon_item_key) {
WC()->cart->set_quantity($package_addon_item_key, $new_quantity, true);
}
foreach ($package_option_item_keys as $package_option_item_key) {
WC()->cart->set_quantity($package_option_item_key, $new_quantity, true);
}
}
return $success;
}
/**
* Update package cart item with `minimal_fixed_price` as its price
* so resulting totals would be sum of these prices
@@ -142,18 +322,26 @@ class Wiaas_Cart {
}
/**
* Persist used payment type information for package in corresponding order line item.
* Also for standard package type list of addons and options will be saved.
* Persist additional metadata for every order item
* This includes:
*
* 1. payment info
* 2. relation info for addons and options
* 3. prices for simple products
*
* @param $order_item
* @param $cart_item_key
* @param $cart_item
* @param $order
*
* @return array
* @return WC_Order_Item
*/
public static function add_order_item_meta( $order_item, $cart_item_key, $cart_item ) {
if (wc_pb_is_bundle_container_cart_item($cart_item) && isset($cart_item['_wiaas_payment'])) {
$is_bundle_item = wc_pb_is_bundle_container_cart_item($cart_item);
$is_bundled_item = wc_pb_is_bundled_cart_item($cart_item);
if ($is_bundle_item && isset($cart_item['_wiaas_payment'])) {
$payment = $cart_item['_wiaas_payment'];
@@ -171,9 +359,6 @@ class Wiaas_Cart {
if (isset($cart_item['_wiaas_standard_package'])) {
$order_item->add_meta_data( '_wiaas_standard_package', $cart_item['_wiaas_standard_package'], true );
}
if (isset($cart_item['_wiaas_currency'])) {
$order_item->add_meta_data( '_wiaas_currency', $cart_item['_wiaas_currency'], true );
}
// add options metadata
if (isset($cart_item['_wiaas_option_items'])) {
@@ -193,6 +378,70 @@ class Wiaas_Cart {
if (isset($cart_item['_wiaas_addon_for'])) {
$order_item->add_meta_data( '_wiaas_addon_for', $cart_item['_wiaas_addon_for'], true );
}
// add documents associated with the item
$cart_documents = isset($cart_item['_wiaas_documents']) ? $cart_item['_wiaas_documents'] : array();
$attachment_document_ids = wiaas_get_object_attached_documents($cart_item['product_id']);
$item_documents = array();
foreach ($cart_documents as $type => $cart_document) {
$item_documents[] = array(
'key' => $cart_document['key'],
'version' => $cart_document['version'],
'type' => $type
);
}
foreach ($attachment_document_ids as $attachment_document_id) {
$doc_info = Wiaas_Document::get_doc_info($attachment_document_id);
// add customer visible attachment documents to order
if ($doc_info['visible'] || !$doc_info['type']) {
$item_documents[] = array(
'key' => wp_generate_uuid4(),
'name' => $doc_info['name'],
'version' => $doc_info['version'],
'type' => $doc_info['type']['id'],
);
}
}
if (count($item_documents) > 0) {
$order_item->add_meta_data( '_wiaas_documents', $item_documents, true );
}
// save simple product information that needs to be available later on
// even if this data is changed or removed from product at that time
if($is_bundled_item) {
$product = wc_get_product($cart_item['product_id']);
$order_item->add_meta_data('_wiaas_category', Wiaas_Product_Category::get_category($product), true);
$order_item->add_meta_data('_wiaas_manufacturer_product_no', $product->get_meta('_manufacturer_product_no'), true);
$order_item->add_meta_data('_wiaas_supplier_product_no', $product->get_meta('_supplier_product_no'), true);
// get supplier
if ($supplier_organization_id = Wiaas_Product_Supplier::get_supplier_organisation_id_from_product($cart_item['product_id'])) {
$order_item->add_meta_data('_wiaas_supplier_organization_id', $supplier_organization_id, true);
}
// save bundled product item total cost (price x period)
$product_price = Wiaas_Pricing::get_product_total_cost($product);
$order_item->add_meta_data('_wiaas_product_price', $product_price, true);
}
// save number of days before earliest installation for bundles
if ($is_bundle_item) {
$order_item->add_meta_data(
'_wiaas_earliest_installation_additional_days',
Wiaas_Package::get_earliest_installation_additional_days($cart_item['product_id']),
true);
}
return $order_item;
}
/**
@@ -217,10 +466,119 @@ class Wiaas_Cart {
'_wiaas_option_for',
'_wiaas_option_group_name',
'_wiaas_standard_package',
'_wiaas_currency',
'_wiaas_documents',
'_wiaas_category',
'_wiaas_manufacturer_product_no',
'_wiaas_supplier_product_no',
'_wiaas_supplier_organization_id',
'_wiaas_product_price',
'_wiaas_earliest_installation_additional_days',
'wiaas_installation',
'wiaas_installation_date'
) );
}
/**
* Sets additional order data form cart after order is successfully created
*
* @param WC_Order $order
*
* @throws WC_Data_Exception
*
*/
public static function add_additional_order_data($order) {
// set order currency
$country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
$currency = empty($country) ? get_woocommerce_currency() : $country['currency'];
$order->set_currency($currency);
// get order commercial lead
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
$shop_owner_id = absint($shop_owner_id);
// save commercial lead info in case it gets deleted
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
$commercial_lead_organization_info = wiaas_get_organization_info($shop_owner_id);
$order->add_meta_data('_wiaas_commercial_lead_info', $commercial_lead_organization_info);
// save customer organization info in case it gets deleted
$customer_user_id = $order->get_customer_id();
$customer_organization_id = wiaas_get_user_organization_id($customer_user_id);
$order->add_meta_data('_wiaas_customer_id', $customer_organization_id);
$customer_organization_info = wiaas_get_organization_info($customer_organization_id);
$order->add_meta_data('_wiaas_customer_info', $customer_organization_info);
// add supplier organizations information to order in case supplier organizations are deleted
// save installation suppliers separately
$suppliers_info = array();
$installation_suppliers_info = array();
$items = $order->get_items('line_item');
foreach($items as $item) {
$supplier_organization_id = $item['wiaas_supplier_organization_id'];
if (! empty($supplier_organization_id) && $item['wiaas_category'] !== 'installation' &&
empty($suppliers_info[$supplier_organization_id]) ) {
$suppliers_info[$supplier_organization_id] = array(
'id' => $supplier_organization_id,
'estimated_delivery_date' => null,
'confirmed_delivery_date' => null,
'tracking_info' => array(),
);
$supplier_organization_info = wiaas_get_organization_info($supplier_organization_id);
foreach ($supplier_organization_info as $key => $info) {
$suppliers_info[$supplier_organization_id][$key] = $info;
}
}
if (! empty($supplier_organization_id) && $item['wiaas_category'] === 'installation' &&
empty($installation_suppliers_info[$supplier_organization_id]) ) {
$installation_suppliers_info[$supplier_organization_id] = array(
'id' => $supplier_organization_id,
);
$supplier_organization_info = wiaas_get_organization_info($supplier_organization_id);
foreach ($supplier_organization_info as $key => $info) {
$installation_suppliers_info[$supplier_organization_id][$key] = $info;
}
}
}
$order->add_meta_data('_wiaas_delivery_suppliers', $suppliers_info, true);
$order->add_meta_data('_wiaas_installation_suppliers', $installation_suppliers_info, true);
// add additional date fields to order
$order->add_meta_data('_wiaas_estimated_delivery_date', null, true);
$order->add_meta_data('_wiaas_final_estimated_delivery_date', null, true);
$order->add_meta_data('_wiaas_final_confirmed_delivery_date', null, true);
$order->add_meta_data('_wiaas_earliest_installation_date', null, true);
// calculate number of days before earlier installation for whole order
$earliest_installation_additional_days = 0;
$items = $order->get_items('line_item');
foreach($items as $item) {
if (! empty($item['_wiaas_earliest_installation_additional_days'])) {
$additional_days = absint($item['_wiaas_earliest_installation_additional_days']);
$earliest_installation_additional_days = max($additional_days, $earliest_installation_additional_days);
}
}
$order->add_meta_data('_wiaas_order_additional_days_prior_installation', $earliest_installation_additional_days, true);
}
/**
* Calculate total cost for cart item
*
@@ -264,72 +622,335 @@ class Wiaas_Cart {
);
}
/**
* Retrieves count of wiaas standard packages in cart
*
* @return int Number of wiaas standard packages in cart
*/
public static function get_cart_packages_count() {
$items = WC()->cart->get_cart_contents();
return array_reduce($items, function($count, $item) {
if (isset($item['_wiaas_standard_package'])) {
$count++;
}
return $count;
}, 0);
}
/**
* Retrieves packages data from cart
* @return array
*/
public static function get_cart_packages() {
$items = WC()->cart->get_cart_contents();
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
$shop_owner_id = absint($shop_owner_id);
$package_items = array();
foreach ($items as $key => $item) {
if (!isset($item['_wiaas_standard_package'])) {
continue;
}
$package = wc_get_product($item['product_id']);
// Collect additional packages
$additional_packages = array_map(
function($addon_cart_item) {
$additional_package = wc_get_product($addon_cart_item['product_id']);
return array(
'package_id' => $additional_package->get_id(),
'package_name' => $additional_package->get_title(),
'prices' => array(
'fixed_extra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
'recurrent_extra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
'services_extra' => $addon_cart_item['_wiaas_payment']['services_extra'],
)
);
},
wiaas_get_cart_item_addons($item));
// Collect package options
$package_options = array_map(
function($option_cart_item) {
$option_package = wc_get_product($option_cart_item['product_id']);
return array(
'package_id' => $option_package->get_id(),
'group_name' => $option_cart_item['_wiaas_option_group_name'],
'package_name' => $option_package->get_title(),
'prices' => array(
'fixed_extra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
'recurrent_extra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
'services_extra' => $option_cart_item['_wiaas_payment']['services_extra'],
)
);
},
wiaas_get_cart_item_options($item));
$package_items[] = array(
'package_id' => $item['product_id'],
'key' => $item['key'],
'package_name' => $package->get_title(),
'quantity' => $item['quantity'],
'commercial_lead_id' => $shop_owner_id,
'commercial_lead' => wiaas_get_organization_name($shop_owner_id),
'country' => Wiaas_Countries::get_package_country($package),
'are_additional_available' => true,
'additional_packages' => $additional_packages,
'are_options_available' => true,
'options' => $package_options,
'bids' => array(),
'payment_info' => array(
'id' => $item['_wiaas_payment']['id'],
'type' => $item['_wiaas_payment']['payment_type'],
'period_unit' => $item['_wiaas_payment']['period_unit'],
'fixed_extra' => $item['_wiaas_payment']['fixed_extra'],
'recurrent_extra' => $item['_wiaas_payment']['recurrent_extra'],
'services_extra' => $item['_wiaas_payment']['services_extra'],
),
'total_prices' => Wiaas_Cart::get_cart_item_total($item),
'status' => 'available',
);
}
return $package_items;
}
//PRIVATE
/**
* Add selected package options to cart
* @param $cart_item_key
* @param $package_id
* @param $cart_item_data
*
* @throws Exception
* Retrieve cart templates
* @return array
*/
private static function _add_options_to_cart($cart_item_key, $package_id, $cart_item_data) {
$is_option_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_option_items']);
$has_selected_options = isset($_POST['options']) && is_array($_POST['options']);
private static function _get_cart_templates() {
$items = WC()->cart->get_cart_contents();
if ($is_option_parent && $has_selected_options) {
$documents_ids = array();
$options_ids = $_POST['options'];
// Retrieve all document ids attached to cart content
foreach ($items as $key => $item) {
if (!isset($item['_wiaas_standard_package'])) {
continue;
}
foreach ($options_ids as $option_id) {
$option_package = wc_get_product($option_id);
if (is_object($option_package)) {
$package_documents_ids = get_post_meta(
$item['product_id'],
'_wiaas_attached_documents',
true);
$option_cart_item_key = WC()->cart->add_to_cart($option_id, 1, 0, array(), array(
'_wiaas_option_for' => $cart_item_key
));
if ($option_cart_item_key) {
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_option_items'][] = $option_cart_item_key;
}
}
foreach ($package_documents_ids as $package_document_id) {
$package_document_id = absint($package_document_id);
$documents_ids[$package_document_id] ?: array();
$documents_ids[$package_document_id][] = $item['product_id'];
}
}
// Retrieve all customer visible template documents attached to cart content
$q = new WP_Query();
$retrieved_items = $q->query(array(
'post_status' => 'publish',
'post_type' => 'wiaas_doc',
'post__in' => array_keys($documents_ids),
'meta_key' => '_wiaas_doc_visible',
'meta_value' => 'yes', // visible to customer
'tax_query' => array(
array(
'taxonomy' => 'wiaas_doc_type',
'field' => 'slug',
'terms' => array_keys(self::$cart_doc_types), // templates only
)
)
));
$cart_documents = array();
foreach ($retrieved_items as $retrieved_item) {
$doc_info = Wiaas_Document::get_doc_info($retrieved_item->ID);
$type = $doc_info['type']['id'];
$cart_documents[$type] ?: array();
$package_ids = $documents_ids[$doc_info['id']] ?: array();
foreach ($package_ids as $package_id) {
$cart_documents[$type][$package_id] = array(
'id' => $doc_info['id'],
'name' => $doc_info['name'],
'type' => $type,
'extension' => $doc_info['extension']
);
}
}
return $cart_documents;
}
/**
* Add selected package addons to cart
*
* @param $cart_item_key
* @param $package_id
* @param $cart_item_data
*
* @throws Exception
* Retrieve cart uploaded documents
* @return array
*/
private static function _add_addons_to_cart($cart_item_key, $package_id, $cart_item_data) {
private static function _get_cart_uploaded_documents() {
$items = WC()->cart->get_cart_contents();
$is_addon_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_addon_items']);
$has_selected_addons = isset($_POST['addons']) && is_array($_POST['addons']);
$cart_documents = array();
if ($is_addon_parent && $has_selected_addons) {
$addons_ids = $_POST['addons'];
foreach ($items as $key => $item) {
if (!isset($item['_wiaas_standard_package'])) {
continue;
}
foreach ($addons_ids as $addon_id) {
$addon_package = wc_get_product($addon_id);
if (is_object($addon_package)) {
$package_id = $item['product_id'];
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id, 1, 0, array(), array(
'_wiaas_addon_for' => $cart_item_key
));
$documents = isset($item['_wiaas_documents']) ? $item['_wiaas_documents'] : array();
if ($addon_cart_item_key) {
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_addon_items'][] = $addon_cart_item_key;
}
}
foreach ($documents as $type => $document) {
$cart_documents[$type] ?: array();
$cart_documents[$type][$package_id] = array(
'key' => $document['key'],
'name' => wiaas_get_doc_version_filename($document['version']),
'type' => $type,
'extension' => wiaas_get_doc_version_extension($document['version'])
);
}
}
return $cart_documents;
}
/**
* Add selected package options and addons after parent standard package is added to cart
*
* @param string $package_cart_item_key
* @param int $price_id
* @param int $shop_owner_id
* @param array $addons_ids
* @param array $options_ids
*
* @throws Exception if any of the addons or options cannot be added to cart
*/
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $shop_owner_id, $addons_ids, $options_ids) {
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
$addon_items_keys = array();
$option_items_keys = array();
$customer_id = wiaas_get_current_user_organization_id();
// Try adding package addons to cart
foreach ($addons_ids as $addon_id) {
//Check if addon package exists
$addon_package = wc_get_product($addon_id);
if (!$addon_package) {
throw new Exception( __( 'Sorry, additional package does not exist.', 'wiaas' ) );
}
// Retrieve addon package price
$package_prices = Wiaas_Pricing::get_addon_package_customer_price(
$addon_package,
$parent_item['data'],
$customer_id,
$shop_owner_id
);
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
// Initialize additional cart item data for wiaas addon packages
$wiaas_addon_cart_item_data = array(
'_wiaas_addon_for' => $package_cart_item_key,
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null
);
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id,
1,
0,
array(),
$wiaas_addon_cart_item_data
);
if (!$addon_cart_item_key) {
throw new Exception( __( 'Sorry, additional package could not be added to cart.', 'wiaas' ) );
}
$addon_items_keys[] = $addon_cart_item_key;
}
// Try adding package options to cart
foreach ($options_ids as $option_id) {
//Check if option package exists
$option_package = wc_get_product($option_id);
if (!$option_package) {
throw new Exception( __( 'Sorry, option package does not exist.', 'wiaas' ) );
}
// Retrieve option package price
$package_prices = Wiaas_Pricing::get_option_package_customer_price(
$option_package,
$parent_item['data'],
$customer_id,
$shop_owner_id);
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
// Retrieve option package group name
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $option_package);
// Initialize additional cart item data for wiaas option packages
$wiaas_option_cart_item_data = array(
'_wiaas_option_for' => $package_cart_item_key,
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
'_wiaas_option_group_name' => $option_group_name,
);
$option_cart_item_key = WC()->cart->add_to_cart($option_id,
1,
0,
array(),
$wiaas_option_cart_item_data
);
if (!$option_cart_item_key) {
throw new Exception( __( 'Sorry, package option could not be added to cart.', 'wiaas' ) );
}
$option_items_keys[] = $option_cart_item_key;
}
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_addon_items'] = $addon_items_keys;
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_option_items'] = $option_items_keys;
}
/**
* Check if package is added to cart
* @param int $package_id
*
* @return bool
*/
private static function _is_package_in_cart($package_id) {
$cart_item = WC()->cart->get_cart_contents();
foreach ($cart_item as $item) {
if($item['product_id'] === $package_id) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,102 @@
<?php
class Wiaas_Checkout {
public static function init(){
add_action( 'woocommerce_check_cart_items', array(__CLASS__, 'validate_wiaas_packages'));
}
public static function validate_wiaas_packages(){
//check if any package became invalid
$items = WC()->cart->get_cart();
foreach($items as $item) {
$item_id = $item['data']->get_id();
if (wc_pb_is_bundle_container_cart_item($item) &&
(Wiaas_Package_Status::get_package_status($item_id) !== Wiaas_Package_Status::AVAILABLE)){
wc_add_notice( 'Package ' . $item['data']->get_title() . ' cannot be purchased at the moment', 'error' );
return false;
}
}
}
/**
* Process the order checkout.
*
* @param array $data Posted data.
*
* @return bool
*/
public static function process_checkout($data) {
try {
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
wc_set_time_limit( 0 );
do_action( 'woocommerce_before_checkout_process' );
// Check if cart empty before proceeding
if (WC()->cart->is_empty()) {
return false;
}
do_action( 'woocommerce_checkout_process' );
// Validate cart items before proceeding
WC()->checkout()->check_cart_items();
// if something is wrong bail out
if(wc_notice_count( 'error' ) > 0) {
return false;
}
// try processing order
$order_id = WC()->checkout()->create_order($data);
$order = wc_get_order( $order_id );
if ( is_wp_error( $order_id ) ) {
throw new Exception( $order_id->get_error_message() );
}
if ( ! $order ) {
throw new Exception( __( 'Unable to create order.', 'woocommerce' ) );
}
self::_add_wiaas_checkout_data($order, $data);
do_action( 'woocommerce_checkout_order_processed', $order_id, array(), $order );
//Change order status from default 'Pending payment' to open (custom wiaas status)
$order->update_status('open');
WC()->cart->empty_cart( true );
return true;
} catch (Exception $e) {
wc_add_notice( $e->getMessage(), 'error' );
return false;
}
}
/**
* Add additional wiaas checkout info for order
* @param $order
* @param array $data
*/
private static function _add_wiaas_checkout_data($order, $data) {
// save additional wiaas order info
Wiaas_Order::set_order_vat($order->get_id(), $data['vat']);
Wiaas_Order::set_order_company($order->get_id(), $data['company_name']);
Wiaas_Order::set_order_reference($order->get_id(), $data['reference']);
Wiaas_Order::set_order_tender($order->get_id(), $data['tender']);
// add order to project
if (isset($data['project_id'])) {
Wiaas_Order_Project::set_project_for_order($order->get_id(), $data['project_id']);
}
}
}
Wiaas_Checkout::init();

View File

@@ -17,18 +17,21 @@ class Wiaas_Countries {
*/
private static $available_countries = array(
'Sweden' => array(
'id' => 1,
'name' => 'Sweden',
'code' => 'se',
'vat' => 9 ,
'currency' => 'SEK'
),
'Denmark' => array(
'id' => 2,
'name' => 'Denmark',
'code' => 'dk',
'vat' => 9 ,
'currency' => 'DKK'
),
'Finland' => array(
'id' => 3,
'name' => 'Finland',
'code' => 'fi',
'vat' => 9 ,
@@ -41,6 +44,37 @@ 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']
));
}
return $result;
}
public static function get_country_name_by_id($id){
foreach(self::$available_countries as $country){
if ($country['id'] == $id) return $country['name'];
}
return '';
}
public static function get_country_code_by_currency($currency) {
foreach (self::$available_countries as $country) {
if ($country['currency'] === $currency) {
return $country['code'];
}
}
return null;
}
/**
* Registers product taxonomy for avaiable countries
*/
@@ -93,12 +127,25 @@ class Wiaas_Countries {
*
* @return array|null
*/
public static function get_product_country($product) {
public static function get_product_country($product) {
$product_country = get_the_terms($product->get_id(), 'product_country');
return is_array($product_country) && isset($product_country[0]) ?
self::$available_countries[$product_country[0]->name] :
null;
}
/**
* Retrieves country term id from db for provided product
* @param $product
*
* @return int|null
*/
public static function get_product_country_term_id($product) {
$product_country = get_the_terms($product->get_id(), 'product_country');
return is_array($product_country) && isset($product_country[0]) ?
$product_country[0]->term_id :
null;
}
}
Wiaas_Countries::init();

View File

@@ -5,15 +5,28 @@ defined( 'ABSPATH' ) || exit;
class Wiaas_DB_Update {
private static $db_updates = array(
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
'20180801222206' => 'wiaas_db_update_setup_gravity',
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
'20180813134511' => 'wiaas_db_update_enable_order_numbers',
'20180826153509' => 'wiaas_create_broker_access_group',
'20180911101010' => 'wiaas_db_setup_exclusive_taxonomies',
'20180912101010' => 'wiaas_db_setup_default_cl'
'20181003164100' => 'wiaas_db_setup_customer_capabilities',
'20181012164450' => 'wiaas_db_update_add_user_organization_ui_fields',
'20181017164550' => 'wiaas_db_update_create_default_roles',
'20181017174550' => 'wiaas_db_import_aam_role_settings',
'20181018014550' => 'wiaas_db_update_update_supplier_capabilities',
'20181018024550' => 'wiaas_db_update_update_admin_capabilities',
'20181018034550' => 'wiaas_admin_create_role_access_groups',
'20181018044450' => 'wiaas_db_setup_create_customer_commercial_lead_table',
'20181018054450' => 'wiaas_db_update_update_commercial_lead_capabilities',
'20181018064450' => 'wiaas_db_update_add_organization_info_ui_fields',
'20191019014550' => 'wiaas_db_update_add_general_ui_fields',
'20191019014650' => 'wiaas_db_update_add_product_properties_ui_fields',
'20191020014650' => 'wiaas_create_organization_roles_capabilities',
'20191030162450' => 'wiaas_db_update_update_supplier_order_capabilities',
'20191102112451' => 'wiaas_disable_processing_order_email_delivery',
'20191131172850' => 'wiaas_db_update_update_delivery_forms',
'20191131182856' => 'wiaas_db_update_enable_workflow_inbox_for_roles',
'20191201133550' => 'wiaas_db_update_add_bundle_properties_ui_field',
'20191202133553' => 'wiaas_db_update_add_installation_date_delivery_action_form'
);
public static function execute() {

View File

@@ -0,0 +1,11 @@
<?php
class Wiaas_DB {
public static function init() {
require_once dirname( __FILE__ ) . '/db/class-wiaas-shop-db.php';
}
}
Wiaas_DB::init();

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

@@ -5,98 +5,21 @@ if ( ! defined( 'ABSPATH' ) ) {
}
/**
* Implements Wiaas Document types
* Implements Wiaas Documents
*
* Class Wiaas_Documents
*/
class Wiaas_Documents {
/**
* Default available document types for wiaas
* @var array
*/
private static $available_doc_types = array(
'template_questionaire' => array(
'name' => 'Template Questionaire',
'is_special_type' => false,
),
'order_questionaire' => array(
'name' => 'Order Questionaire',
'is_special_type' => true,
),
'configuration' => array(
'name' => 'Configuration',
'is_special_type' => true,
),
'install_guide' => array(
'name' => 'Install guide',
'is_special_type' => false,
),
'customer_acceptance' => array(
'name' => 'Customer acceptance',
'is_special_type' => true,
),
'template_agreement' => array(
'name' => 'Template Agreement',
'is_special_type' => false,
),
'order_agreement' => array(
'name' => 'Order Agreement',
'is_special_type' => true,
),
'installation_protocol' => array(
'name' => 'Installation protocol',
'is_special_type' => true,
),
'statements' => array(
'name' => 'Statements',
'is_special_type' => false,
),
'customer_acceptance_template' => array(
'name' => 'Customer acceptance template',
'is_special_type' => false,
),
);
public static function init() {
add_action( 'init', array( __CLASS__, 'register_wiaas_document_types' ));
}
/**
* Registers taxonomy and default values for wiaas document types
*/
public static function register_wiaas_document_types() {
$labels = array(
'name' => _x( 'Document type', 'taxonomy general name', 'wiaas' ),
'singular_name' => _x( 'Document type', 'taxonomy singular name', 'wiaas' ),
'menu_name' => _x( 'Document types', 'Admin menu name', 'wiaas' ),
'search_items' => __( 'Search Document types', 'wiaas' ),
'all_items' => __( 'All Document types', 'wiaas' ),
'parent_item' => __( 'Parent Document type', 'wiaas' ),
'parent_item_colon' => __( 'Parent Document type:', 'wiaas' ),
'edit_item' => __( 'Edit Document type', 'wiaas' ),
'update_item' => __( 'Update Document type', 'wiaas' ),
'add_new_item' => __( 'Add New Document type', 'wiaas' ),
'new_item_name' => __( 'New Document type Name', 'wiaas' ),
);
require_once dirname( __FILE__ ) . '/document/class-wiaas-document.php';
$args = array(
'hierarchical' => false,
'label' => __( 'Document types', 'wiaas' ),
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'wiaas_document_types' ),
);
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-upload.php';
register_taxonomy( 'wiaas_document_types', array( 'attachment' ), $args );
require_once dirname( __FILE__ ) . '/document/class-wiaas-document-download.php';
foreach (self::$available_doc_types as $key => $available_doc_type) {
wp_insert_term($available_doc_type['name'], 'wiaas_document_types', array(
'slug' => $key
));
}
require_once dirname( __FILE__ ) . '/document/wiaas-document-functions.php';
}
}

View File

@@ -16,7 +16,17 @@ class Wiaas_Order {
private static $object_order_type = 'shop_order';
public static function init() {
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
require_once dirname( __FILE__ ) . '/order/wiaas-order-functions.php';
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
add_filter( 'woocommerce_register_shop_order_post_statuses', array(__CLASS__, 'register_custom_order_statuses'), 10, 1);
add_filter( 'wc_order_statuses', array(__CLASS__, 'add_custom_statuses_to_list' ), 10, 1);
add_filter( 'bulk_actions-edit-shop_order', array(__CLASS__, 'add_custom_statuses_to_bulk_edit' ), 10, 1);
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
@@ -25,6 +35,252 @@ class Wiaas_Order {
add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2);
add_filter('woocommerce_new_order_note_data', array( __CLASS__, 'update_new_order_comment_date'), 10, 3);
add_filter('woocommerce_order_number', array( __CLASS__, 'format_order_number'));
}
/**
* Prefix order number
*
* @param int $number
*
* @return string
*/
public static function format_order_number($number) {
return "1000000$number";
}
public static function get_additional_days_prior_installation($order_id){
$order = wc_get_order($order_id);
return $order->get_meta('_wiaas_order_additional_days_prior_installation');
}
public static function add_additional_tracking_info($order_id, $supplier_id){
$suppliers = self::get_suppliers($order_id);
foreach($suppliers as $key => $supplier){
if ($supplier['id'] === $supplier_id){
$suppliers[$key]['tracking_info'][] = array(
'number' => '',
'url' => ''
);
$order = wc_get_order($order_id);
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
$order->save_meta_data();
return true;
}
}
return false;
}
public static function save_tracking_info($order_id, $supplier_id, $tracking_index, $tracking_num, $tracking_url){
$suppliers = self::get_suppliers($order_id);
foreach($suppliers as $key => $supplier){
if ($supplier['id'] === $supplier_id){
$suppliers[$key]['tracking_info'][$tracking_index]['number'] = $tracking_num;
$suppliers[$key]['tracking_info'][$tracking_index]['url'] = $tracking_url;
$order = wc_get_order($order_id);
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
$order->save_meta_data();
return true;
}
}
return false;
}
public static function delete_tracking_info($order_id, $supplier_id, $tracking_index){
$suppliers = self::get_suppliers($order_id);
foreach($suppliers as $key => $supplier){
if ($supplier['id'] === $supplier_id){
unset($suppliers[$key]['tracking_info'][$tracking_index]);
$order = wc_get_order($order_id);
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
$order->save_meta_data();
return true;
}
}
return false;
}
public static function save_estimated_date($order_id, $supplier_id, $date){
$suppliers = self::get_suppliers($order_id);
$updated = false;
foreach($suppliers as $key => $supplier){
if ($supplier['id'] === $supplier_id){
$suppliers[$key]['estimated_date'] = $date;
$updated = true;
}
}
if (!$updated){
return false;
}
$order = wc_get_order($order_id);
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
self::_update_max_and_earliest_dates($order, $suppliers);
$order->save_meta_data();
return true;
}
public static function save_confirmed_date($order_id, $supplier_id, $date){
$suppliers = self::get_suppliers($order_id);
$updated = false;
foreach($suppliers as $key => $supplier){
if ($supplier['id'] === $supplier_id){
$suppliers[$key]['confirmed_date'] = $date;
$updated = true;
if (!$suppliers[$key]['estimated_date']){
$suppliers[$key]['estimated_date'] = $date;
}
}
}
if (!$updated){
return false;
}
$order = wc_get_order($order_id);
$order->update_meta_data('_wiaas_delivery_suppliers', $suppliers);
self::_update_max_and_earliest_dates($order, $suppliers);
$order->save_meta_data();
return true;
}
public static function get_order_estimated_date($order_id){
$order = wc_get_order($order_id);
if (!$order){
return NULL;
}
return $order->get_meta('_wiaas_order_estimated_delivery_date') ?: NULL;
}
public static function save_order_estimated_date($order_id, $date){
return update_post_meta($order_id, '_wiaas_order_estimated_delivery_date', $date);
}
public static function get_final_estimated_date($order_id){
$order = wc_get_order($order_id);
if (!$order){
return 0;
}
return $order->get_meta('_wiaas_final_estimated_delivery_date') ?: 0;
}
public static function get_final_confirmed_date($order_id){
$order = wc_get_order($order_id);
if (!$order){
return 0;
}
return $order->get_meta('_wiaas_final_confirmed_delivery_date') ?: 0;
}
public static function get_earliest_installation_date($order_id){
$order = wc_get_order($order_id);
if (!$order){
return 0;
}
return $order->get_meta('_wiaas_earliest_installation_date') ?: 0;
}
/**
* Get suppliers related to order
*/
public static function get_suppliers($order_id){
$order = wc_get_order($order_id);
return $order->get_meta('_wiaas_delivery_suppliers');
}
/**
* Register additional order statuses
*
* @param array $order_statuses
*
* @return array
*/
public static function register_custom_order_statuses($order_statuses){
// Status must start with "wc-"
$order_statuses['wc-open'] = array(
'label' => _x( 'Open', 'Order status', 'woocommerce' ),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Open <span class="count">(%s)</span>', 'Open <span class="count">(%s)</span>', 'woocommerce' ),
);
return $order_statuses;
}
/**
* display custom wiaas statuses in order status dropdown
*
* @param array $order_statuses
*
* @return array
*/
public static function add_custom_statuses_to_list($order_statuses){
$order_statuses['wc-open'] = _x( 'Open', 'Order status', 'woocommerce' );
return $order_statuses;
}
/**
* display custom wiaas statuses in bulk actions
*
* @param array $bulk_actions
*
* @return array
*/
public static function add_custom_statuses_to_bulk_edit($bulk_actions){
// Note: "mark_" must be there instead of "wc"
$bulk_actions['mark_open'] = 'Change status to open';
return $bulk_actions;
}
/**
* Update `shop_order` post type settings before creation to enable better order management for wiaas
*
* @param array $args
*
* @return array
*/
public static function manage_order_settings($args) {
// show orders in backend menu
$args['show_in_menu'] = true;
//set icon
$args['menu_icon'] = 'dashicons-cart';
// set capabilities
$args['capabilities'] = array(
'edit_post' => 'edit_shop_order',
'read_post' => 'read_shop_order',
'delete_post' => 'delete_shop_order',
'edit_posts' => 'edit_shop_orders',
'edit_others_posts' => 'edit_others_shop_orders',
'publish_posts' => 'publish_shop_orders',
'read_private_posts' => 'read_private_shop_orders',
'create_posts' => 'create_shop_orders', // use `create_shop_orders` instead of `edit_shop_orders`
);
return $args;
}
public static function update_new_order_comment_date($comment_data, $order_data) {
@@ -36,16 +292,6 @@ class Wiaas_Order {
return $comment_data;
}
/**
* Assignees order to corresponding user organization when order is created.
*
* @param $order_id
*/
public static function assign_order_to_organization($order_id) {
$user = wp_get_current_user();
Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID);
}
/**
* Checks if current user has access to requested order/{orderId} via woocommerce REST API.
* Endpoint `/orders` is filtered correctly by groups, but endpoint `/orders/{orderId}` will return order even if
@@ -115,6 +361,8 @@ class Wiaas_Order {
$data = self::_append_order_process($data, $order, $request);
$data = self::_append_order_comments($data, $order, $request);
$data = self::_append_documents($data, $order, $request);
}
$response->set_data($data);
@@ -122,10 +370,80 @@ class Wiaas_Order {
return $response;
}
public static function set_order_vat($order_id, $vat_code) {
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
}
public static function get_order_vat($order_id) {
return get_post_meta($order_id, '_wiaas_vat_code', true);
}
public static function set_order_company($order_id, $company_name) {
add_post_meta($order_id, '_wiaas_company_name', $company_name);
}
public static function get_order_company($order_id) {
return get_post_meta($order_id, '_wiaas_company_name', true);
}
public static function set_order_reference($order_id, $reference) {
add_post_meta($order_id, '_wiaas_reference', $reference);
}
public static function get_order_reference($order_id) {
return get_post_meta($order_id, '_wiaas_reference', true);
}
public static function set_order_tender($order_id, $tender) {
add_post_meta($order_id, '_wiaas_tender', $tender);
}
public static function get_order_tender($order_id) {
return get_post_meta($order_id, '_wiaas_tender', true);
}
/**
* 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) . ' days', $earliest_installation_date);
}
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
$order->update_meta_data('_wiaas_final_estimated_delivery_date', $max_estimated_date);
$order->update_meta_data('_wiaas_earliest_installation_date', $earliest_installation_date);
}
/**
* Append specific wiaas order details, like reference
* @param $data
@@ -133,26 +451,47 @@ class Wiaas_Order {
* @param $request
*/
private static function _append_wiaas_order_details($data, $order, $request) {
$data['reference'] = get_post_meta($order->get_id(), '_wiaas_reference', true);
$data['reference'] = self::get_order_reference($order->get_id());
$data['tender'] = self::get_order_tender($order->get_id());
$data['vat'] = self::get_order_vat($order->get_id());
$data['company_name'] = self::get_order_company($order->get_id());
$data['project_name'] = Wiaas_Order_Project::get_project_name_for_order($order->get_id());
return $data;
}
/**
* Appends additional wiaas customer lead info to order json response
* @param $data
* @param $order
* @param WC_Order $order
* @param $request
*
* @return mixed
*/
private static function _append_commercial_lead_info($data, $order, $request) {
$data['commercial_lead'] = array(
'id' => 1,
'name' => 'Coor Service Management',
'phone' => '123456789',
'email' => 'rikard@co-ideation.com'
);
$commercial_lead_org_id = $order->get_meta('_wiaas_commercial_lead_id', true);
$commercial_lead_organization_info = $order->get_meta('_wiaas_commercial_lead_info', true);
if (! empty($commercial_lead_org_id) && empty($commercial_lead_organization_info)) {
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
$data['commercial_lead'] = array(
'id' => $commercial_lead_org_id,
'name' => $commercial_lead_organization_info['name'],
'phone' => $commercial_lead_organization_info['phone'],
'email' => $commercial_lead_organization_info['email']
);
}
if (!empty($commercial_lead_organization_info)) {
$commercial_lead_organization_info['id'] = $commercial_lead_organization_info;
$data['commercial_lead'] = $commercial_lead_organization_info;
}
return $data;
}
@@ -160,25 +499,34 @@ class Wiaas_Order {
/**
* Appends additional wiaas customer info to order json response
* @param $data
* @param $order
* @param WC_Order $order
* @param $request
*
* @return mixed
*/
private static function _append_customer_info($data, $order, $request) {
$current_user = wp_get_current_user();
$customer_organization_id = $order->get_meta('_wiaas_customer_id', true);
$customer_id = $data['customer_id'];
$customer_user_id = $order->get_customer_id();
$customer_user = get_user_by('id', $customer_id);
$data['customer'] = array(
'email' => $customer_user->user_email,
'name' => $customer_user->display_name,
'phone' => '+46 (10) 5595148'
);
if (empty($customer_organization_id)) {
$data['is_my_order'] = $customer_id === $current_user->ID;
$customer_organization_id = wiaas_get_user_organization_id($customer_user_id);
}
$customer_organization_info = $order->get_meta('_wiaas_customer_info', true);
if ( !empty($customer_organization_id) && empty($customer_organization_info) ) {
$customer_organization_info = wiaas_get_organization_info($customer_organization_id);
$customer_organization_info['id'] = $customer_organization_id;
}
$data['customer'] = $customer_organization_info;
$data['is_my_order'] = $customer_user_id === get_current_user_id();
return $data;
}
@@ -202,7 +550,6 @@ class Wiaas_Order {
// add only product lines that represent product bundles
if (isset($item['wiaas_standard_package'])) {
# get payment type info
$product_line['payment_type'] = $item['wiaas_payment_type'];
$product_line['service_price'] = floatval($item['wiaas_services_extra']);
@@ -249,6 +596,12 @@ class Wiaas_Order {
}
}
// installation date
if (! empty($item['wiaas_installation_date'])) {
$product_line['installation_date'] = $item['wiaas_installation_date'];
}
$line_items[] = $product_line;
}
}
@@ -311,6 +664,30 @@ class Wiaas_Order {
}
}
return $data;
}
/** Append downloadable documents from order products if single order is requested
* @param $data
* @param $order
* @param $request
*/
private static function _append_documents($data, $order, $request) {
// Go trough available line items and append documents for wiaas standard packages line items
foreach ($data['line_items'] as $index => $product_line) {
$order_item = $order->get_item($product_line['id']);
if (wiaas_is_order_item__standard_package($order_item)) {
$documents = wiaas_get_standard_package_order_item_documents($order, $product_line['id']);
$data['line_items'][$index] ['documents'] = $documents;
}
}
$data['documents'] = wiaas_get_order_other_documents($order->get_id());
return $data;
}
}

View File

@@ -12,6 +12,7 @@ class Wiaas_Package {
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-option-groups.php';
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-type.php';
require_once dirname( __FILE__ ) . '/package/class-wiaas-package-status.php';
require_once dirname( __FILE__ ) . '/package/wiaas-package-functions.php';
@@ -31,6 +32,9 @@ class Wiaas_Package {
$data = self::_append_country_info($data, $package, $request);
// append package reference field
$data['reference'] = ! empty($data['tags']) ? $data['tags'][0]['name'] : '';
if (isset($request['id'])) {
$data = self::_append_package_prices($data, $package, $request);
@@ -44,6 +48,10 @@ class Wiaas_Package {
return $response;
}
public static function get_earliest_installation_additional_days($package_id){
return get_post_meta($package_id, 'additional_days_prior_earliest_installation', true);
}
/**
* Append package documents
* @param $data
@@ -54,15 +62,11 @@ class Wiaas_Package {
*/
private static function _append_documents_info($data, $package, $request) {
unset($data['downloads']);
$data['documents'] = array_map(function($download) {
return array(
'id' => $download->get_id(),
'name' => $download->get_name(),
'extension' => $download->get_file_extension(),
);
}, array_values($package->get_downloads()));
$data['documents'] = array_map(function($doc) {
unset($doc['url']);
unset($doc['version']);
return $doc;
}, wiaas_get_standard_package_documents($package, true));
return $data;
}
@@ -96,6 +100,8 @@ class Wiaas_Package {
* @return array
*/
private static function _append_additional_packages($data, $package, $request) {
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id = absint($request['shop_id']);
$data['additional_packages'] = array();
$addons = Wiaas_Package_Addon::get_package_addons($package);
@@ -104,7 +110,7 @@ class Wiaas_Package {
'id' => $addon->get_id(),
'name' => $addon->get_name(),
'description' => $addon->get_description(),
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package),
'prices' => Wiaas_Pricing::get_addon_package_customer_price($addon, $package, $customer_id, $commercial_lead_id),
);
}
@@ -125,7 +131,7 @@ class Wiaas_Package {
'name' => $option_package->get_name(),
'description' => $option_package->get_description(),
'default' => $default_option_id === $option_package->get_id(),
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package),
'prices' => Wiaas_Pricing::get_option_package_customer_price($option_package, $package, $customer_id, $commercial_lead_id),
);
}
}
@@ -142,7 +148,10 @@ class Wiaas_Package {
* @return array
*/
private static function _append_package_prices($data, $package, $request) {
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package);
$customer_id = wiaas_get_current_user_organization_id();
$commercial_lead_id = absint($request['shop_id']);
$data['prices'] = Wiaas_Pricing::get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id);
return $data;
}

View File

@@ -1,7 +1,7 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit; // Exit if accessed directly
}
/**
@@ -9,233 +9,240 @@ if ( ! defined( 'ABSPATH' ) ) {
*/
class Wiaas_Pricing {
/**
* Wiaas interest rate
*/
const INTEREST_RATE = 0.58;
/**
* Wiaas interest rate
*/
const INTEREST_RATE = 0.58;
const COMMERCIAL_LEAD_NAME = 'Coor Service Management';
public static function init() {
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-cl-pricing.php';
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
}
public static function init() {
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-product-pricing.php';
require_once dirname( __FILE__ ) . '/pricing/class-wiaas-package-pricing.php';
require_once dirname( __FILE__ ) . '/pricing/wiaas-pricing-functions.php';
}
/**
* Calculates total cost for product
* @param WC_Product_Simple $product
*
* @return float
*/
public static function get_product_total_cost($product) {
$product_price = Wiaas_Product_Pricing::get_product_price($product);
/**
* Calculates total cost for product
* @param $product
*
* @return float
*/
public static function get_product_total_cost($product) {
$product_price = Wiaas_Product_Pricing::get_product_price($product);
return $product_price['is_recurring'] ?
$product_price['price'] * $product_price['pay_period'] :
$product_price['price'];
}
return $product_price['is_recurring'] ?
$product_price['price'] * $product_price['pay_period'] :
$product_price['price'];
}
/**
* Calculates total cost for package
* @param WC_Product_Bundle $package
*
* @return float
*/
public static function get_package_total_cost($package) {
/**
* Calculates total cost for package
* @param $package
*
* @return float
*/
public static function get_package_total_cost($package) {
$total_cost_per_category = array();
$total_cost_per_category = array();
$bundled_items = $package->get_bundled_items();
foreach ($bundled_items as $bundled_item) {
$bundled_items = $package->get_bundled_items();
foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product;
$product_cat = Wiaas_Product_Category::get_category($product);
$product = $bundled_item->product;
$product_cat = Wiaas_Product_Category::get_category($product);
if (!isset($total_cost_per_category[$product_cat])) {
$total_cost_per_category[$product_cat] = 0;
}
if (!isset($total_cost_per_category[$product_cat])) {
$total_cost_per_category[$product_cat] = 0;
}
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
if (Wiaas_Product_Category::is_installation($product)) {
$total_cost_per_category[$product_cat] = $total_cost_per_category[$product_cat] < $total_item_cost ?
$total_item_cost :
$total_cost_per_category[$product_cat];
} else {
$total_cost_per_category[$product_cat] += $total_item_cost;
}
}
if (Wiaas_Product_Category::is_installation($product)) {
$total_cost_per_category[$product_cat] += $total_cost_per_category[$product_cat] < $total_item_cost ?
$total_item_cost :
$total_cost_per_category[$product_cat];
} else {
$total_cost_per_category[$product_cat] += $total_item_cost;
}
}
return array_sum(array_values($total_cost_per_category));
}
return array_sum(array_values($total_cost_per_category));
}
/**
* Calculates customer prices for wiaas standard package
* @param WC_Product_Bundle $package
* @param int $customer_id
* @param int $commercial_lead_id
*
* @return array
*/
public static function get_standard_package_customer_prices($package, $customer_id, $commercial_lead_id) {
/**
* Calculates customer price for wiaas standard package
* @param $package
*
* @return array
*/
public static function get_standard_package_customer_prices($package) {
return self::_get_package_customer_prices(
$package,
(100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100, // commercial lead commission
self::get_package_total_cost($package), // total cost of package items
$customer_id,
$commercial_lead_id);
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
$cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($package)) / 100;
$total_cost = self::get_package_total_cost($package);
}
$customer_package_prices = array();
/**
* Calculates customer prices for wiaas addon package
*
* @param WC_Product_Bundle $addon_package
* @param WC_Product_Bundle $parent_package
* @param int $customer_id
* @param int $commercial_lead_id
*
* @return array
*/
public static function get_addon_package_customer_price($addon_package, $parent_package, $customer_id, $commercial_lead_id) {
foreach ($package_prices as $type => $package_price) {
$customer_package_prices[] = self::_get_package_customer_price(
$package_price,
$cl_commision,
$total_cost,
$is_same_company_as_cl);
}
$parent_total_cost = self::get_package_total_cost($parent_package);
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
return $customer_package_prices;
return self::_get_package_customer_prices(
$addon_package,
$parent_cl_commision, // commercial lead commission of parent package
$parent_total_cost, // total cost of parent package items
$customer_id,
$commercial_lead_id);
}
}
/**
* Calculates customer prices for wiaas option package
*
* @param WC_Product_Bundle $option_package
* @param WC_Product_Bundle $parent_package
* @param int $customer_id
* @param int $commercial_lead_id
*
* @return array
*/
public static function get_option_package_customer_price($option_package, $parent_package, $customer_id, $commercial_lead_id) {
/**
* Calculates customer price for wiaas addon package
* @param $addon_package
* @param $parent_package
*
* @return array
*/
public static function get_addon_package_customer_price($addon_package, $parent_package) {
$parent_total_cost = self::get_package_total_cost($parent_package);
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
$parent_total_cost = self::get_package_total_cost($parent_package);
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
$addon_package_prices = Wiaas_Package_Pricing::get_package_prices($addon_package);
return self::_get_package_customer_prices(
$option_package,
$parent_cl_commision, // commercial lead commission of parent package
$parent_total_cost, // total cost of parent package items
$customer_id,
$commercial_lead_id);
}
$customer_package_prices = array();
foreach ($addon_package_prices as $type => $addon_package_price) {
$customer_package_prices[] = self::_get_package_customer_price(
$addon_package_price,
$parent_cl_commision,
$parent_total_cost,
$is_same_company_as_cl);
}
return $customer_package_prices;
}
/**
* Calculates customer price for wiaas option package
* @param $option_package
* @param $parent_package
*
* @return array
*/
public static function get_option_package_customer_price($option_package, $parent_package) {
// PRIVATE SECTION
$is_same_company_as_cl = self::_is_customer_same_company_as_cl();
$parent_total_cost = self::get_package_total_cost($parent_package);
$parent_cl_commision = (100 - Wiaas_Package_Pricing::get_package_pricing_commission($parent_package)) / 100;
$option_package_prices = Wiaas_Package_Pricing::get_package_prices($option_package);
$customer_package_prices = array();
/**
* Calculates customer prices for all package payment types
*
* @param WC_Product_Bundle $package
* @param int $cl_commision
* @param int $total_cost
* @param int $customer_id
* @param int $commercial_lead_id
*
* @return array
*/
private static function _get_package_customer_prices($package, $cl_commision, $total_cost, $customer_id, $commercial_lead_id) {
$is_same_company_as_cl = $customer_id === $commercial_lead_id;
foreach ($option_package_prices as $type => $option_package_price) {
$customer_package_prices[] = self::_get_package_customer_price(
$option_package_price,
$parent_cl_commision,
$parent_total_cost,
$is_same_company_as_cl);
}
$package_prices = Wiaas_Package_Pricing::get_package_prices($package);
return $customer_package_prices;
}
$customer_package_prices = array();
// PRIVATE
foreach ($package_prices as $type => $package_price) {
$cl_package_extras = Wiaas_Package_CL_Pricing::get_extras_for_customer(
$commercial_lead_id,
$package_price['id'],
$package->get_id(),
$customer_id
);
/**
* Determines if customer and commercial lead are in the same company
* For now this is hardcoded and we have only one CL
*
* TODO: This should be changed after customer leads are handled
* @return bool
*/
private static function _is_customer_same_company_as_cl() {
$current_user = wp_get_current_user();
$user_organization = Wiaas_User_Organization::get_user_organization($current_user->ID);
$is_same_company_as_cl = $user_organization->name === self::COMMERCIAL_LEAD_NAME;
// commercial lead did not set prices for this payment type so it must not be visible for customer
if (empty($cl_package_extras)) {
continue;
}
return $is_same_company_as_cl;
}
$customer_package_prices[] = self::_get_package_customer_price(
$package_price,
$total_cost,
$cl_package_extras,
$cl_commision,
$is_same_company_as_cl);
}
/**
* Calculates customer price for wiaas package
* @param $package_price
* @param $cl_commision
* @param $total_cost
* @param $is_same_company_as_cl
*
* @return array
*/
private static function _get_package_customer_price($package_price, $cl_commision, $total_cost, $is_same_company_as_cl) {
return $customer_package_prices;
}
$package_total_margin = wiaas_get_price_margin(
$package_price['minimal_fixed_price'],
$package_price['principal_amount'],
$total_cost);
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
/**
* Calculates customer price for single package payment type
*
* @param array $package_price
* @param int $total_cost
* @param array $cl_package_extras
* @param int $cl_commision
* @param bool $is_same_company_as_cl
*
* @return array
*/
private static function _get_package_customer_price($package_price, $total_cost, $cl_package_extras, $cl_commision, $is_same_company_as_cl) {
$package_total_margin = wiaas_get_price_margin(
$package_price['minimal_fixed_price'],
$package_price['principal_amount'],
$total_cost);
$cl_margin = $package_total_margin > 0 ? $package_total_margin * $cl_commision : 0;
$cl_package_prices = array(
'fixed_extra' => 0,
'recurrent_extra' => 0,
'services_extra' => 0
);
$customer_package_price = array(
'id' => $package_price['id'],
'payment_type' => $package_price['payment_type'],
'max_contract_period' => $package_price['max_contract_period'],
'package_pay_period' => $package_price['package_pay_period'],
'period_unit' => $package_price['period_unit'],
'services_contract_period' => $package_price['services_contract_period'],
$interest_rate = self::INTEREST_RATE;
'fixed_extra' => 0,
'recurrent_extra' => 0,
'services_extra' => 0
);
$customer_price = array(
'id' => $package_price['id'],
'payment_type' => $package_price['payment_type'],
'max_contract_period' => $package_price['max_contract_period'],
'package_pay_period' => $package_price['package_pay_period'],
'period_unit' => $package_price['period_unit'],
'services_contract_period' => $package_price['services_contract_period'],
if ($is_same_company_as_cl) {
'fixed_extra' => 0,
'recurrent_extra' => 0,
'services_extra' => 0
);
if ($package_price['package_pay_period'] > 0) {
$customer_package_price['fixed_extra'] = $package_price['minimal_fixed_price'];
$customer_package_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
$package_price['principal_amount'],
$package_price['package_pay_period'],
$cl_margin,
self::INTEREST_RATE);
} else {
$customer_package_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
$customer_package_price['recurrent_extra'] = 0;
}
$customer_package_price['services_extra'] = $package_price['minimal_services_price'];
if ($is_same_company_as_cl) {
} else {
if ($package_price['package_pay_period'] > 0) {
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'];
$customer_price['recurrent_extra'] = wiaas_get_recurrent_price_mortage(
$package_price['principal_amount'],
$package_price['package_pay_period'],
$cl_margin,
$interest_rate);
} else {
$customer_price['fixed_extra'] = $package_price['minimal_fixed_price'] - $cl_margin;
$customer_price['recurrent_extra'] = 0;
}
$customer_price['services_extra'] = $package_price['minimal_services_price'];
$customer_package_price['fixed_extra'] = $cl_package_extras['fixed'] + $package_price['minimal_fixed_price'];
$customer_package_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
$cl_package_extras['recurrent'] + wiaas_get_recurrent_price_mortage(
$package_price['principal_amount'],
$package_price['package_pay_period'],
0,
self::INTEREST_RATE)
: 0;
$customer_package_price['services_extra'] = $cl_package_extras['services'] + $package_price['minimal_services_price'];
}
} else {
$customer_price['fixed_extra'] = $cl_package_prices['fixed_extra'] + $package_price['minimal_fixed_price'];
$customer_price['recurrent_extra'] = $package_price['package_pay_period'] > 0 ?
$cl_package_prices['recurrent_extra'] + wiaas_get_recurrent_price_mortage(
$package_price['principal_amount'],
$package_price['package_pay_period'],
0,
$interest_rate)
: 0;
$customer_price['services_extra'] = $cl_package_prices['services_extra'] + $package_price['minimal_services_price'];
}
return $customer_price;
}
return $customer_package_price;
}
}
Wiaas_Pricing::init();

View File

@@ -4,6 +4,75 @@ class Wiaas_Product {
public static function init() {
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'manage_product_settings'));
add_filter('woocommerce_taxonomy_args_product_tag', array(__CLASS__, 'manage_tags_as_references'));
}
/**
* Update product type settins before it is created:
* - Define capabilities for editing products so we can easily control read/edit/create access for them
* - Declare fields supported by product
*
* @param $args
*
* @return array
*/
public static function manage_product_settings($args) {
$args['capabilities'] = array(
'edit_post' => 'edit_product',
'read_post' => 'read_product',
'delete_post' => 'delete_product',
'edit_posts' => 'edit_products',
'edit_others_posts' => 'edit_others_products',
'publish_posts' => 'publish_products',
'read_private_posts' => 'read_private_products',
'create_posts' => 'create_products', // use `create_products` instead of default `edit_products`
);
$args['supports'] = array( 'title', 'thumbnail' );
return $args;
}
/**
* Hide default metabox for product tags
*
* @param $args
*
* @return array
*/
public static function manage_tags_as_references($args) {
// hide metabox
$args['meta_box_cb'] = false;
// update labels
$args['labels'] = array(
'name' => __( 'Product references', 'wiaas' ),
'singular_name' => __( 'Reference', 'wiaas' ),
'menu_name' => _x( 'References', 'Admin menu name', 'wiaas' ),
'search_items' => __( 'Search references', 'wiaas' ),
'all_items' => __( 'All references', 'wiaas' ),
'edit_item' => __( 'Edit reference', 'wiaas' ),
'update_item' => __( 'Update reference', 'wiaas' ),
'add_new_item' => __( 'Add new reference', 'wiaas' ),
'new_item_name' => __( 'New reference name', 'wiaas' ),
'popular_items' => __( 'Popular references', 'wiaas' ),
'separate_items_with_commas' => __( 'Separate references with commas', 'wiaas' ),
'add_or_remove_items' => __( 'Add or remove references', 'wiaas' ),
'choose_from_most_used' => __( 'Choose from the most used references', 'wiaas' ),
'not_found' => __( 'No references found', 'wiaas' ),
);
return $args;
}
public static function get_supplier_id($product_id){
return wp_get_post_terms($product_id, 'supplier', array('fields' => 'ids'))[0];
}
}

View File

@@ -0,0 +1,215 @@
<?php
/**
* Implements logic for multiple shops existing in one marketplace
*
* Every shop has its owner (organization that is commercial lead) and multiple customers (organizations)
* assigned to it.
*
* Class Wiaas_Shop
*/
class Wiaas_Shop {
public static function init() {
// registers special prices taxonomy that will enable package search based on
// set and visible price types (default and customer specific ones)
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_prices_taxonomy'));
// update prices search terms for package after prices extras have been updated
add_action('wiaas_package_prices_extras_set', array(__CLASS__, 'update_package_prices_search_terms'), 10, 4);
// remove customer shop relationships for all deactivated and removed shops
add_action('wiaas_organization_roles_updated', array(__CLASS__, 'remove_deactivated_shop'));
add_action('wiaas_organization_deleted', array(__CLASS__, 'remove_shop'));
}
public static function get_shop_customers($owner_id) {
return Wiaas_Shop_DB::get_shop_customers($owner_id);
}
/**
* Link customers to shop (this will enable them to search and order packages from this shop)
*
* @param int $owner_id
* @param array $customer_ids
*/
public static function set_shop_customers($owner_id, $customer_ids) {
$current_customer_ids = wp_list_pluck(
Wiaas_Shop_DB::get_shop_customers($owner_id),
'customer_id');
// delete removed customers
$removed_customer_ids = array_diff($current_customer_ids, $customer_ids);
Wiaas_Shop_DB::remove_shop_customers($owner_id, $removed_customer_ids);
// save added customers
$added_customer_ids = array_diff($customer_ids, $current_customer_ids);
Wiaas_Shop_DB::add_shop_customers($owner_id, $added_customer_ids);
}
/**
* Retrieve default order type for shop
*
* @param int $owner_id
*
* @return string
*/
public static function get_default_order_type($owner_id) {
$order_type = get_term_meta(
$owner_id,
'_wiaas_shop_default_order_type',
true);
return empty($order_type) ? 'commercial_lead' : $order_type;
}
/**
* Update default order type for shop
*
* @param int $owner_id
* @param string $order_type
*/
public static function update_default_order_type($owner_id, $order_type) {
if (in_array($order_type, array('commercial_lead', 'reseller'))) {
update_term_meta($owner_id, '_wiaas_shop_default_order_type', $order_type);
}
}
public static function update_shop_customer_order_type($owner_id, $customer_id, $order_type) {
Wiaas_Shop_DB::update_shop_customer_order_type(
$owner_id,
$customer_id,
$order_type);
}
/**
* Remove shop for organization that is no longer commercial lead
*
* @param int $owner_id
*/
public static function remove_deactivated_shop($owner_id) {
$roles = wiaas_get_organization_roles($owner_id);
if (! in_array('commercial_lead', $roles)) {
self::remove_shop($owner_id);
}
}
/**
* remove shop
* @param int $owner_id
*/
public static function remove_shop($owner_id) {
Wiaas_Shop_DB::remove_shop($owner_id);
}
/**
* Register special prices taxonomy to enable search of packages by prices inside every shop
*/
public static function register_prices_taxonomy() {
$args = array(
'hierarchical' => false,
'query_var' => true,
'rewrite' => false,
'public' => false,
'capabilities' => array(
'manage_terms' => 'manage_wiaas_package_price_terms',
'edit_terms' => 'edit_wiaas_package_price_terms',
'delete_terms' => 'delete_wiaas_package_price_terms',
'assign_terms' => 'assign_wiaas_package_price_terms',
),
);
register_taxonomy( '_wiaas_shop_prices', array( 'product' ), $args );
}
/**
* Relate pricing search terms to package so customer can retrieve packages with default or
* their own specific prices.
* (ex: Package which will be hidden fro Customer 1 because default price
* is hidden can be visible for Customer 2 because specific prices are set for that customer)
*
* @param int $owner_id
* @param int $package_id
* @param array $cl_extras {
* $extra_price_payment_type => {
* @type bool visible Indicates if payment type is visible to customer
* }
* }
* @param array $old_cl_extras {
* $extra_price_payment_type => {
* @type bool visible Indicates if payment type is visible to customer
* }
* }
*/
public static function update_package_prices_search_terms($owner_id, $package_id, $cl_extras, $old_cl_extras) {
// remove pricing terms for previous prices
if (! empty($old_cl_extras)) {
$old_terms = self::_get_search_terms_from_cl_extras($owner_id, $old_cl_extras);
wp_remove_object_terms($package_id, $old_terms, '_wiaas_shop_prices');
}
$new_terms = self::_get_search_terms_from_cl_extras($owner_id, $cl_extras);
// create term for every visible pricing type and link them to package so package can be queried
wp_add_object_terms($package_id, $new_terms, '_wiaas_shop_prices');
}
// PRIVATE
/**
* Generate search terms from cl extras
*
* For default prices search term
* `_{owner_id}_default` will be generated if all set prices are visible
*
* For every customer entry search term
* `_{owner_id}_customer_{customer_id}_visible` will be generated if any of the prices is visible or
* `_{owner_id}_customer_{customer_id}_hidden` if all prices are hidden`
*
* @param int $owner_id
* @param array $cl_extras
*
* @return array
*/
private static function _get_search_terms_from_cl_extras($owner_id, $cl_extras) {
// determine if extras are visible grouped by customer and default settings
$cl_extras_per_customer = array();
$cl_extra_default = false;
foreach ($cl_extras as $cl_extra_type => $cl_extra) {
// is default
if (strpos($cl_extra_type, '_default') !== false) {
// determine if default cl extra is visible
$cl_extra_default = $cl_extra_default || $cl_extra['visible'];
}
// is customer specific
if (strpos($cl_extra_type, '_customer_') !== false) {
$customer_id = absint(explode('_customer_', $cl_extra_type)[1]);
// determine if customer cl extra is visible
$cl_extras_per_customer[$customer_id] = $cl_extras_per_customer[$customer_id] || $cl_extra['visible'];
}
}
$terms = array();
if ($cl_extra_default) {
$terms[] = '_' . $owner_id . '_default';
}
foreach ($cl_extras_per_customer as $customer_id => $visible) {
$terms[] = '_' . $owner_id . '_customer_' . $customer_id . '_' .
($visible ? 'visible' : 'hidden');
}
return $terms;
}
}
Wiaas_Shop::init();

View File

@@ -8,13 +8,20 @@ defined( 'ABSPATH' ) || exit;
class Wiaas_User {
public static function init() {
include_once dirname( __FILE__ ) . '/class-wiaas-countries.php';
include_once dirname( __FILE__ ) . '/user/class-wiaas-customer.php';
add_action('init', array(__CLASS__, 'load_user_organization'));
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
add_filter('woocommerce_rest_prepare_customer', array(__CLASS__, 'transform_rest_customer'), 10, 3);
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'transform_jwt_token_response'), 999, 2);
}
public static function load_user_organization() {
if (class_exists('WP_User_Taxonomy')) {
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
require_once dirname( __FILE__ ) . '/user/wiaas-organization-functions.php';
new Wiaas_User_Organization();
}
@@ -24,6 +31,51 @@ class Wiaas_User {
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
}
/**
* Apply wiaas custom transformation on retrieved JSON customer object
*
* @param $response
* @param $order
* @param $request
*
* @return mixed
*/
public static function transform_rest_customer($response, $order, $request) {
$data = $response->get_data();
$user_id = $data['id'];
$customer_info = Wiaas_Customer::get_customer_info($user_id);
return new WP_REST_Response($customer_info);
}
/**
* Apply wiaas custom transformation on JWT token response
*
* @param $data
* @param $user
*
* @return mixed
*/
public static function transform_jwt_token_response($data, $user) {
if (is_wp_error($data)) {
return $data;
}
return new WP_REST_Response(array(
'token' => $data['token'],
'userInfo' => array(
'wiaas_id_user' => $user->ID,
'wiaas_is_company_admin' => 1, //TODO: don't hardcode this
'wiaas_user_full_name' => $user->first_name . ' ' . $user->last_name,
'wiaas_user_type' => $user->roles,
'wiaas_username' => $user->data->user_login
)
));
}
}
Wiaas_User::init();

View File

@@ -33,7 +33,9 @@ class Wiaas_CLI_Update_DB_Command {
$wpdb->hide_errors();
include_once WIAAS_DIR . '/includes/class-wiaas-db-update.php';
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-functions.php';
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-general.php';
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-roles.php';
include_once WIAAS_DIR . '/includes/db-updates/wiaas-db-update-ui-fields.php';
$pending_db_updates = Wiaas_DB_Update::get_pending_db_updates();

File diff suppressed because one or more lines are too long

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,103 @@
[
{
"key": "group_5bbf694106e34",
"title": "General",
"fields": [
{
"key": "field_5bceef4c9771c",
"label": "General",
"name": "_wiaas_product_general",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_5bc0965a35406",
"label": "Type",
"name": "_wiaas_product_type",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"simple": "Simple",
"bundle": "Bundle",
"wiaastemplate": "Template"
},
"default_value": [],
"allow_null": 0,
"multiple": 0,
"ui": 1,
"ajax": 0,
"return_format": "value",
"placeholder": ""
},
{
"key": "field_5bbf899bba1af",
"label": "Country",
"name": "_wiaas_product_country",
"type": "taxonomy",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5bc0965a35406",
"operator": "!=",
"value": "wiaastemplate"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "product_country",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
}
]
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "product"
},
{
"param": "post_status",
"operator": "==",
"value": "_wiaas_no_country"
}
]
],
"menu_order": 0,
"position": "acf_after_title",
"style": "seamless",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]

View File

@@ -0,0 +1,120 @@
[
{
"key": "group_5bbe558ba265c",
"title": "Organization Info",
"fields": [
{
"key": "field_5bbe5c0d1f1a7",
"label": "Phone",
"name": "_wiaas_organization_phone",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_5bbe5c291f1a8",
"label": "VAT Code",
"name": "_wiaas_organization_vat",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": ""
},
{
"key": "field_5bbe559d66d17",
"label": "Roles",
"name": "_wiaas_organization_roles",
"type": "select",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"administrator": "Administrator",
"supplier": "Supplier",
"commercial_lead": "Commercial Lead",
"customer": "Customer"
},
"default_value": [],
"allow_null": 0,
"multiple": 1,
"ui": 1,
"ajax": 1,
"return_format": "value",
"placeholder": ""
},
{
"key": "field_5bc49631c35a4",
"label": "Linked Customers",
"name": "_wiaas_organization_customers",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_5bbe559d66d17",
"operator": "==contains",
"value": "commercial_lead"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "wiaas-user-organization",
"field_type": "multi_select",
"allow_null": 0,
"add_term": 0,
"save_terms": 0,
"load_terms": 1,
"return_format": "id",
"multiple": 0
}
],
"location": [
[
{
"param": "taxonomy",
"operator": "==",
"value": "wiaas-user-organization"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "seamless",
"label_placement": "top",
"instruction_placement": "field",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]

View File

@@ -0,0 +1,140 @@
[
{
"key": "group_5bc864b78434b",
"title": "Product properties",
"fields": [
{
"key": "field_5bc8653baeafb",
"label": "Supplier",
"name": "supplier",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "supplier",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
},
{
"key": "field_5bc86761aeafc",
"label": "Unit",
"name": "unit",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "wiaas_units",
"field_type": "select",
"allow_null": 0,
"add_term": 1,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
},
{
"key": "field_5bc867c3aeafd",
"label": "Category",
"name": "category",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "product_cat",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
},
{
"key": "field_5bc8743b099a8",
"label": "Template category",
"name": "template_category",
"type": "taxonomy",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "template_category",
"field_type": "select",
"allow_null": 0,
"add_term": 1,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
},
{
"key": "field_5bcfcceffe617",
"label": "Country",
"name": "country",
"type": "taxonomy",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "product_country",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "product"
},
{
"param": "post_taxonomy",
"operator": "==",
"value": "product_type:simple"
}
]
],
"menu_order": 0,
"position": "acf_after_title",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]

View File

@@ -0,0 +1,52 @@
[
{
"key": "group_5bbce9f38f149",
"title": "User Organization",
"fields": [
{
"key": "field_5bbe54366aac1",
"label": "Organization",
"name": "_wiaas_organization_id",
"type": "taxonomy",
"instructions": "Select Organization for user",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"taxonomy": "wiaas-user-organization",
"field_type": "select",
"allow_null": 0,
"add_term": 0,
"save_terms": 1,
"load_terms": 1,
"return_format": "id",
"multiple": 0
}
],
"location": [
[
{
"param": "user_form",
"operator": "==",
"value": "edit"
},
{
"param": "current_user_role",
"operator": "==",
"value": "administrator"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "seamless",
"label_placement": "left",
"instruction_placement": "field",
"hide_on_screen": "",
"active": 1,
"description": ""
}
]

View File

@@ -1,128 +0,0 @@
<?php
/**
* Wiaas DB updates
*
* Functions for updating 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);
update_option( 'gform_enable_background_updates', false );
update_option('rg_gforms_enable_akismet', 0);
update_option('rg_gforms_currency', 'USD');
// Gravity Flow settings
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_setup_customer_capabilities() {
$customer_role = get_role('customer');
$customer_role->add_cap('read_private_shop_orders');
$customer_role->add_cap('read_private_products');
$customer_role->add_cap('read_shop_order');
$customer_role->add_cap('publish_shop_orders');
}
function wiaas_db_update_enable_orders_access_management() {
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
$post_types_option['shop_order'] = array(
'add_meta_box' => true
);
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',
),
'delete' => 0,
));
}
function wiaas_db_setup_default_cl() {
wp_insert_term(Wiaas_Pricing::COMMERCIAL_LEAD_NAME, Wiaas_User_Organization::TAXONOMY_NAME);
}

View File

@@ -0,0 +1,135 @@
<?php
/**
* General Wiaas DB updates
*
* General functions for updating wiaas database to latest version
*/
function wiaas_db_update_setup_gravity() {
// Gravity Form settings
update_option('gform_pending_installation', false);
update_option( 'gform_enable_background_updates', false );
update_option('rg_gforms_enable_akismet', 0);
update_option('rg_gforms_currency', 'USD');
// Gravity Flow settings
update_option('gravityflow_pending_installation', false);
}
function wiaas_db_update_enable_orders_access_management() {
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
$post_types_option['shop_order'] = array(
'add_meta_box' => true
);
Groups_Options::update_option(Groups_Post_Access::POST_TYPES, $post_types_option);
}
function wiaas_db_setup_exclusive_taxonomies() {
update_option('radio_button_for_taxonomies_options', array(
'taxonomies' => array(
'shop_order_project',
),
'delete' => 0,
));
}
function wiaas_db_setup_customer_capabilities() {
$customer_role = get_role('customer');
$customer_role->add_cap('read_private_shop_orders');
$customer_role->add_cap('read_private_products');
$customer_role->add_cap('read_shop_order');
$customer_role->add_cap('publish_shop_orders');
// user
$customer_role->add_cap('list_users');
$customer_role->add_cap('edit_users');
}
function wiaas_db_setup_create_customer_commercial_lead_table() {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$sql = "
CREATE TABLE {$wpdb->prefix}wiaas_shop_customer_relationships (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` bigint(20) unsigned NOT NULL,
`shop_owner_id` bigint(20) unsigned NOT NULL,
`order_type` varchar(44) NOT NULL default '',
PRIMARY KEY (`ID`),
KEY `relationship` (`customer_id`, `shop_owner_id`),
KEY `order_type` (`order_type`)
) COLLATE {$wpdb->collate};
";
dbDelta( $sql );
}
function wiaas_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) ));
}

View File

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

View File

@@ -0,0 +1,129 @@
<?php
function wiaas_db_update_add_organization_info_ui_fields() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-organization-info.json' );
$ui_json = json_decode( $ui_json, true );
_wiaas_import_field_group($ui_json);
}
function wiaas_db_update_add_user_organization_ui_fields() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-user-organization.json' );
$ui_json = json_decode( $ui_json, true );
_wiaas_import_field_group($ui_json);
}
function wiaas_db_update_add_bundle_properties_ui_field() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-bundle-properties.json' );
$ui_json = json_decode( $ui_json, true );
_wiaas_import_field_group($ui_json);
}
function wiaas_db_update_add_general_ui_fields() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-general.json' );
$ui_json = json_decode( $ui_json, true );
_wiaas_import_field_group($ui_json);
}
function wiaas_db_update_add_product_properties_ui_fields() {
$ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-product-properties.json' );
$ui_json = json_decode( $ui_json, true );
_wiaas_import_field_group($ui_json);
}
// private helper function
function _wiaas_import_field_group($json) {
// vars
$ids = array();
$keys = array();
// populate keys
foreach( $json as $field_group ) {
// append key
$keys[] = $field_group['key'];
}
// look for existing ids
foreach( $keys as $key ) {
// attempt find ID
$field_group = _acf_get_field_group_by_key( $key );
// bail early if no field group
if( !$field_group ) continue;
// append
$ids[ $key ] = $field_group['ID'];
}
// enable local
acf_enable_local();
// reset local (JSON class has already included .json field groups which may conflict)
acf_reset_local();
// add local field groups
foreach( $json as $field_group ) {
// add field group
acf_add_local_field_group( $field_group );
}
// loop over keys
foreach( $keys as $key ) {
// vars
$field_group = acf_get_local_field_group( $key );
// attempt get id
$id = acf_maybe_get( $ids, $key );
if( $id ) {
$field_group['ID'] = $id;
}
// append fields
if( acf_have_local_fields($key) ) {
$field_group['fields'] = acf_get_local_fields( $key );
}
// import
acf_import_field_group( $field_group );
}
}

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