@subiz/widget-v4 4.1.122 → 4.1.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/assets/less/form.less +1 -1
  2. package/assets/less/message.less +7 -0
  3. package/assets/less/widget_header.less +5 -3
  4. package/compiled_src/chatbox/Event.js +15 -11
  5. package/compiled_src/chatbox/TextMessage.js +6 -2
  6. package/compiled_src/chatbox/Widget.js +4 -6
  7. package/compiled_src/plugin.js +1 -0
  8. package/compiled_src/store/api.js +5 -2
  9. package/compiled_src/store/api_fake.js +0 -1
  10. package/compiled_src/store/chain.js +228 -0
  11. package/compiled_src/store/inmem_localstorage.js +33 -0
  12. package/compiled_src/store/kv.js +86 -0
  13. package/compiled_src/store/lsdb.js +68 -0
  14. package/compiled_src/store/store.js +27 -20
  15. package/dist/132.js +6433 -2574
  16. package/dist/178.js +406 -0
  17. package/dist/18a02a9c54e.132.js +1 -0
  18. package/dist/18a02a9c54e.178.js +1 -0
  19. package/dist/18a02a9c54e.213.js +1 -0
  20. package/dist/18a02a9c54e.335.js +1 -0
  21. package/dist/18a02a9c54e.362.js +1 -0
  22. package/dist/18a02a9c54e.441.js +1 -0
  23. package/dist/18a02a9c54e.605.js +1 -0
  24. package/dist/18a02a9c54e.678.js +1 -0
  25. package/dist/18a02a9c54e.782.js +1 -0
  26. package/dist/18a02a9c54e.app.js +1 -0
  27. package/dist/{19643345ab6.index.html → 18a02a9c54e.index.html} +4 -28
  28. package/dist/{19643345ab6.library.html → 18a02a9c54e.library.html} +4 -28
  29. package/dist/18a02a9c54e.library.js +1 -0
  30. package/dist/{19643345ab6.preview.html → 18a02a9c54e.preview.html} +1 -1
  31. package/dist/18a02a9c54e.preview.js +1 -0
  32. package/dist/18a02a9c54e.screenshoot.js +1 -0
  33. package/dist/18a02a9c54e.webview.js +1 -0
  34. package/dist/213.js +2780 -0
  35. package/dist/{74.js → 335.js} +35 -35
  36. package/dist/362.js +107 -0
  37. package/dist/441.js +2855 -0
  38. package/dist/{490.js → 605.js} +82 -82
  39. package/dist/{997.js → 678.js} +6 -6
  40. package/dist/782.js +107 -0
  41. package/dist/HASH +1 -1
  42. package/dist/assets/img/{subiz-mono.8fbc067.svg → subiz-mono.877e9f5.svg} +1 -1
  43. package/dist/malicious-app.js +4 -6
  44. package/dist/screenshoot.html +1 -1
  45. package/dist/screenshoot.js +4849 -9583
  46. package/package.json +1 -2
  47. package/src/chatbox/Event.js +5 -3
  48. package/src/chatbox/TextMessage.js +6 -2
  49. package/src/chatbox/Widget.js +3 -4
  50. package/src/chatbox/main.js +1 -0
  51. package/src/plugin.js +2 -0
  52. package/src/store/api.js +5 -2
  53. package/src/store/api_fake.js +0 -1
  54. package/src/store/chain.js +255 -0
  55. package/src/store/inmem_localstorage.js +40 -0
  56. package/src/store/kv.js +103 -0
  57. package/src/store/lsdb.js +74 -0
  58. package/src/store/store.js +27 -22
  59. package/dist/127.js +0 -273
  60. package/dist/185.js +0 -1885
  61. package/dist/19643345ab6.127.js +0 -1
  62. package/dist/19643345ab6.132.js +0 -1
  63. package/dist/19643345ab6.185.js +0 -1
  64. package/dist/19643345ab6.27.js +0 -1
  65. package/dist/19643345ab6.278.js +0 -1
  66. package/dist/19643345ab6.459.js +0 -1
  67. package/dist/19643345ab6.490.js +0 -1
  68. package/dist/19643345ab6.74.js +0 -1
  69. package/dist/19643345ab6.997.js +0 -1
  70. package/dist/19643345ab6.app.js +0 -1
  71. package/dist/19643345ab6.library.js +0 -1
  72. package/dist/19643345ab6.preview.js +0 -1
  73. package/dist/19643345ab6.webview.js +0 -1
  74. package/dist/27.js +0 -107
  75. package/dist/278.js +0 -406
  76. package/dist/459.js +0 -107
@@ -1,7 +1,9 @@
1
1
  import sb from '../util/index.js'
2
2
  var flow = require('@subiz/flow')
3
- import stor8 from '@subiz/storage'
4
3
  import API from './api.js'
4
+ import LSDB from './lsdb.js'
5
+ import Chain from './chain.js'
6
+ import KV from './kv.js'
5
7
  import APIFake from './api_fake.js'
6
8
  import RealtimeFake from './realtime_fake.js'
7
9
  var Realtime = require('@subiz/wsclient')
@@ -51,9 +53,9 @@ export default class Store {
51
53
 
52
54
  cleanLocalStorage()
53
55
  this.pubsub = new sb.Pubsub()
54
- this.kv = new stor8.kv(new stor8.lsdb('sbz2023', this.inmem), 'kv')
55
- this.cache = new stor8.kv(new stor8.lsdb('sbz2023', true), 'kv')
56
- this.chain = new stor8.chain(new stor8.lsdb('cbz2023', true), 'ch')
56
+ this.kv = new KV(new LSDB('sbz2023', this.inmem), 'kv')
57
+ this.cache = new KV(new LSDB('sbz2023', true), 'kv')
58
+ this.chain = new Chain(new LSDB('cbz2023', true), 'ch')
57
59
  this.getLocaleContent = this.api.getLocaleContent
58
60
 
59
61
  // dont dupplicate seen
@@ -175,14 +177,12 @@ export default class Store {
175
177
  async overrideAcc(acc) {
176
178
  this.forceAcc = sb.cloneDeep(acc)
177
179
  await this.readyGate.entry()
178
- this.disconnect('account')
179
180
  this.reconnect()
180
181
  }
181
182
 
182
183
  async overrideChatbox(chatbox) {
183
184
  this.forceChatbox = chatbox
184
185
  await this.readyGate.entry()
185
- this.disconnect('account')
186
186
  await this.reconnect()
187
187
  sb.setTimeout(this.pubsub.publish('resetCSS'), 10)
188
188
  }
@@ -492,10 +492,13 @@ export default class Store {
492
492
  this.realtime = new Realtime(this.RealtimeURL, {account_id: accid, user_ref: userRef, user_mask: mask}, xhrsend)
493
493
 
494
494
  this.realtime.onEvent(this.onWs.bind(this))
495
- this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id))
495
+ this.realtime.onInterrupted(async () => {
496
+ await this.reconnectWs(accid, user.id)
497
+ this.reconnect()
498
+ })
496
499
 
497
500
  this.seenLoop()
498
- await this.reconnect()
501
+ await this.reconnect({user: user}) // already fetched
499
502
  this.readyGate.open()
500
503
  this.reconnectWs(accid, user.id)
501
504
  return user
@@ -518,7 +521,10 @@ export default class Store {
518
521
  else this.realtime = new Realtime(this.RealtimeURL, {getAccessToken: () => this.api.token_generator()})
519
522
 
520
523
  this.realtime.onEvent(this.onWs.bind(this))
521
- this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id))
524
+ this.realtime.onInterrupted(async () => {
525
+ await this.reconnectWs(accid, user.id)
526
+ this.reconnect()
527
+ })
522
528
 
523
529
  this.seenLoop()
524
530
  await this.reconnect()
@@ -592,32 +598,30 @@ export default class Store {
592
598
  `conversation_joined.account.${accid}.user.${userid}`,
593
599
  `conversation_typing.account.${accid}.user.${userid}`,
594
600
  `message_sent.account.${accid}.user.${userid}`,
595
- `conversation_pending.account.${accid}.user.${userid}`,
596
- `user_info_updated.account.${accid}.user.${userid}`,
601
+ // `conversation_pending.account.${accid}.user.${userid}`,
602
+ // `user_info_updated.account.${accid}.user.${userid}`,
597
603
  `message_pong.account.${accid}.user.${userid}`,
598
604
  `conversation_rating_requested.account.${accid}.user.${userid}`,
599
605
  `conversation_rated.account.${accid}.user.${userid}`,
600
606
  ])
601
607
  await this.readyGate.entry()
602
- this.disconnect('account')
603
- return this.reconnect()
604
608
  }
605
609
 
606
- async reconnect() {
610
+ async reconnect(p) {
607
611
  if (this._die) return
608
612
  // make sure we only run reconnect once in a time
609
-
610
613
  await this.reconnectGate.entry(undefined, true)
611
614
  // do nothing when account is synced
612
- if (this.isInsync('account')) return this.reconnectGate.open()
615
+ // if (this.isInsync('account')) return this.reconnectGate.open()
613
616
  this.markSync('account')
614
617
 
615
- let outs = await Promise.all([this.api.getUser(), this.api.getAccountSetting(), this.api.getIsOnline()])
618
+ let fetchuser = p && p.user ? Promise.resolve({body: p.user}) : this.api.getUser()
619
+ let outs = await Promise.all([fetchuser, this.api.getAccountSetting()])
616
620
 
617
621
  let error = sb.find(outs, (out) => out.error)
618
622
  if (error) return console.error(error)
619
623
 
620
- let set = Object.assign(outs[1].body, outs[2].body)
624
+ let set = outs[1].body
621
625
  set.user = outs[0].body
622
626
  await this._setSetting(set)
623
627
  // refetch convo
@@ -781,6 +785,7 @@ export default class Store {
781
785
  if (!ev || !ev.type) return
782
786
  ev.created = sb.getMs(ev.created)
783
787
  if (ev.type === 'user_info_updated') {
788
+ return
784
789
  let user = sb.cloneDeep(this.cache.match('user'))
785
790
  let attrs = sb.get(ev, 'data.user.attributes') || []
786
791
  sb.map(attrs, (attr) => sb.setUserAttr(user, attr))
@@ -808,8 +813,8 @@ export default class Store {
808
813
  if (!convo) return
809
814
 
810
815
  // ignore wrong channel
811
- let channel = sb.get(ev, 'touchpoint.channel', '')
812
- if (channel && channel != 'subiz') return
816
+ // let channel = sb.get(ev, 'touchpoint.channel', '')
817
+ // if (channel && channel != 'subiz') return
813
818
 
814
819
  this.pubsub.publish('events', ev)
815
820
 
@@ -1213,9 +1218,9 @@ export default class Store {
1213
1218
  if ((k || '').startsWith('__sb')) this.cookie.remove(k)
1214
1219
  })
1215
1220
  this.kv.destroy()
1216
- this.kv = new stor8.kv(new stor8.lsdb('sbz2023', this.inmem), 'kv')
1221
+ this.kv = new KV(new LSDB('sbz2023', this.inmem), 'kv')
1217
1222
  this.chain.destroy()
1218
- this.chain = new stor8.chain(new stor8.lsdb('cbz2023', true), 'ch')
1223
+ this.chain = new Chain(new LSDB('cbz2023', true), 'ch')
1219
1224
  }
1220
1225
 
1221
1226
  destroy() {
package/dist/127.js DELETED
@@ -1,273 +0,0 @@
1
- "use strict";
2
- (self["webpackChunk_subiz_widget_v4"] = self["webpackChunk_subiz_widget_v4"] || []).push([[127],{
3
-
4
- /***/ 6127:
5
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
6
-
7
- __webpack_require__.r(__webpack_exports__);
8
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
- /* harmony export */ "default": () => (/* binding */ ProductAttachments)
10
- /* harmony export */ });
11
- /* harmony import */ var _util_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8150);
12
- /* harmony import */ var _common_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2840);
13
- /* harmony import */ var preact__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(172);
14
-
15
-
16
-
17
- class ProductAttachments extends _common_js__WEBPACK_IMPORTED_MODULE_1__/* .Com */ .Mw {
18
- render() {
19
- let byType = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(this.props.ev, 'by.type');
20
- if (byType === 'user') return null;
21
- let acc = this.props.store.matchAccount();
22
- var attachments = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(this.props.ev, 'data.message.attachments', []);
23
- let orders = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.filter(attachments, att => att.type === 'order' && att.order).map(att => att.order);
24
- if (orders.length === 0) return null;
25
- let $orders = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.map(orders, (order, index) => {
26
- calcOrderTotal(order);
27
- let $note = null;
28
- if (order.note) {
29
- $note = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
30
- class: "order_attachment__label"
31
- }, this.props.t('note')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
32
- class: "order_attachment__note",
33
- title: order.note
34
- }, order.note));
35
- }
36
- let $products = null;
37
- if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.size(order.items) > 0) {
38
- $products = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
39
- class: "order_attachment__label"
40
- }, this.props.t('product')), _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.map(order.items, item => {
41
- let product = item.product || {};
42
- return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
43
- class: "order_attachment__product"
44
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("img", {
45
- class: "order_attachment__product_img",
46
- alt: '' + _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(product, 'id'),
47
- src: _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(product, 'image', __webpack_require__(2876))
48
- }), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
49
- style: "overflow: hidden !important;"
50
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
51
- class: "order_attachment__product_name",
52
- title: this.props.t.i18n(product.i18n_name) || product.name
53
- }, this.props.t.i18n(product.i18n_name) || product.name), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
54
- class: "order_attachment__product_desc"
55
- }, getProductPropName(product, ' / ')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
56
- class: "order_attachment__product_desc"
57
- }, this.props.t('qty'), " ", item.quantity, "\xA0\xB7\xA0", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(product.price))));
58
- }));
59
- }
60
- let $total = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
61
- class: "order_attachment__footer"
62
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
63
- class: "d-flex align-items-center justify-content-between"
64
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, this.props.t('total')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("b", {
65
- class: "order_attachment__total"
66
- }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.total)))));
67
- let phoneattr = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.find(_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'user.attributes', []), attr => attr.key === 'phones') || {
68
- key: 'phones',
69
- text: ''
70
- };
71
- let phone = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.address.phone', '').trim();
72
- phone = phone || _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.trim(phoneattr.text);
73
- if (phone) phone = this.props.t('phn') + ': ' + phone;
74
- let $shipto = null;
75
- if (displayOrderShippingAddress(order) || phone) {
76
- $shipto = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
77
- class: "order_attachment__label"
78
- }, this.props.t('ship_to')), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, displayOrderShippingAddress(order)), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
79
- class: "order_attachment__text_truncate"
80
- }, phone));
81
- }
82
- let $beforeTax = null;
83
- if (order._discount_before_tax) {
84
- $beforeTax = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
85
- class: "order_attachment__footer"
86
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
87
- class: "d-flex align-items-center justify-content-between"
88
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
89
- class: "order_attachment__label no_margin"
90
- }, this.props.t('subtotal_before_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._order_value))), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
91
- class: "d-flex align-items-center justify-content-between"
92
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
93
- class: "order_attachment__label no_margin"
94
- }, this.props.t('discount_before_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", null, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._discount_before_tax))));
95
- }
96
- let $subtotal = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
97
- class: "d-flex align-items-center justify-content-between"
98
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
99
- class: "order_attachment__label no_margin"
100
- }, this.props.t('subtotal')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
101
- style: ""
102
- }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.subtotal)));
103
- let $tax = null;
104
- if (order.total_tax) {
105
- let taxname = '';
106
- if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.size(order._taxM) === 1) {
107
- let tax = _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order._taxM, '0.tax', {});
108
- if (tax.name && tax.percentage) taxname = `(${tax.name} ${Math.round(tax.percentage || 0) / 100}%)`;
109
- }
110
- $tax = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
111
- class: "d-flex align-items-center justify-content-between"
112
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
113
- class: "order_attachment__label no_margin"
114
- }, this.props.t('tax'), " ", taxname), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
115
- style: ""
116
- }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.total_tax)));
117
- }
118
- let $discount = null;
119
- if (order.discount_type === 'percentage' && order.discount_percentage) {
120
- $discount = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
121
- class: "d-flex align-items-center justify-content-between"
122
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
123
- class: "order_attachment__label no_margin"
124
- }, this.props.t('discount_after_tax'), " (", Math.round(order.discount_percentage / 100), "%)"), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
125
- style: ""
126
- }, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._computed_discount)));
127
- }
128
- if (order.discount_type === 'amount' && order.discount_amount) {
129
- $discount = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
130
- class: "d-flex align-items-center justify-content-between"
131
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
132
- class: "order_attachment__label no_margin"
133
- }, this.props.t('discount_after_tax')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
134
- class: "no-shrink"
135
- }, "-", _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order._computed_discount)));
136
- }
137
- let $shipping = null;
138
- if (_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.nominal_fee')) {
139
- $shipping = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
140
- class: "d-flex align-items-center justify-content-between"
141
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
142
- class: "order_attachment__label no_margin"
143
- }, this.props.t('shipping_fee')), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
144
- style: ""
145
- }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(_util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.get(order, 'shipping.nominal_fee', 0))));
146
- }
147
- let $adjustment = null;
148
- if (order.adjustment) {
149
- $adjustment = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
150
- class: "d-flex align-items-center justify-content-between"
151
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
152
- class: "order_attachment__label no_margin"
153
- }, order.adjustment_description), ' ', (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
154
- class: "no-shrink"
155
- }, _util_index_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .A.formatCurrency(order.adjustment)));
156
- }
157
- $subtotal = (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
158
- class: "order_attachment__footer"
159
- }, $subtotal, $tax, $shipping, $discount, $adjustment);
160
- if (!$shipping && !$adjustment && !$discount && !$tax) {
161
- $subtotal = null;
162
- }
163
- return (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
164
- class: `order_attachment order_attachment__${byType}`
165
- }, (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("div", {
166
- class: "order_attachment__header"
167
- }, this.props.t('order'), (0,preact__WEBPACK_IMPORTED_MODULE_2__.h)("span", {
168
- class: "order_attachment__text_muted order_attachment__text_sm"
169
- }, getOrderDisplayName(order))), $products, $shipto, $note, $beforeTax, $subtotal, $total);
170
- });
171
- return $orders;
172
- }
173
- }
174
- function getProductPropName(product, seperator = ' - ') {
175
- let options = op.get(product, 'options', []);
176
- let props = op.get(product, 'props', []);
177
- let multiPropsOptions = op.filter(options, option => op.size(option.values) > 1);
178
- let names = [];
179
- op.each(multiPropsOptions, option => {
180
- let prop = op.find(props, prop => prop.key === option.key) || {};
181
- if (prop.value) names.push(prop.value);
182
- });
183
- return names.join(seperator);
184
- }
185
- function getOrderDisplayName(order = {}) {
186
- return order.number || order.id || '';
187
- }
188
- function displayOrderShippingAddress(order, isShorten) {
189
- let addr = op.get(order, 'shipping.address', {});
190
- let fulladdr = [addr.address, addr.ward, addr.district, addr.province].filter(a => a).join(', ').trim();
191
- if (isShorten) fulladdr = shortenAddr(fulladdr);
192
- return fulladdr;
193
- }
194
- function shortenAddr(str) {
195
- str = str || '';
196
- str = str.replace(/Hà Nội/gi, 'HN');
197
- str = str.replace(/Hồ Chí Minh/gi, 'HCM');
198
- str = str.replace(/Thành Phố/gi, 'TP');
199
- return str;
200
- }
201
- function calcOrderTotal(order) {
202
- let subtotal = 0;
203
- let beforeTaxDiscount = 0;
204
- let ordervalue = 0;
205
- op.map(order.items, item => {
206
- if (!item.product) return 0;
207
- let price = op.get(item, 'product.price', 0) * (item.quantity || 0);
208
- ordervalue += price;
209
- if (item.discount_type == 'percentage') {
210
- if (item.discount_percentage > 0) {
211
- beforeTaxDiscount += price * item.discount_percentage / 10000;
212
- price = price * (1 - (item.discount_percentage || 0) / 10000);
213
- }
214
- } else if (item.discount_type == 'amount') {
215
- if (item.discount_amount > 0) {
216
- beforeTaxDiscount += item.discount_amount;
217
- price = price - (item.discount_amount || 0);
218
- if (price <= 0) price = 0;
219
- }
220
- }
221
- item.total = price;
222
- subtotal += price;
223
- });
224
- let taxM = {};
225
- op.map(order.items, (item, i) => {
226
- if (!item.product) return;
227
- let tax = item.product.tax;
228
- if (!tax) return;
229
- if (!tax.id) return;
230
- let taxprice = item.total * tax.percentage / 10000;
231
- item.total_tax = taxprice;
232
- taxM[i] = {
233
- tax: tax,
234
- taxprice: taxprice
235
- };
236
- });
237
- let totaltax = 0;
238
- op.map(taxM, t => totaltax += t.taxprice);
239
- let computed_discount = 0;
240
- if (order.discount_type == 'percentage' && order.discount_percentage > 0) {
241
- computed_discount = (subtotal + totaltax) * order.discount_percentage / 10000;
242
- } else if (order.discount_type == 'amount') {
243
- computed_discount = order.discount_amount || 0;
244
- }
245
- let shippingfee = op.get(order, 'shipping.nominal_fee', 0);
246
- if (shippingfee > 0) {
247
- if (op.get(order, 'shipping.tax.id')) {
248
- let tax = order.shipping.tax;
249
- let taxprice = shippingfee * (tax.percentage / 10000);
250
- taxM['ship'] = {
251
- tax: tax,
252
- taxprice: taxprice
253
- };
254
- order.shipping.total_tax = taxprice;
255
- }
256
- }
257
- totaltax = 0;
258
- op.map(taxM, t => totaltax += t.taxprice);
259
- let total = subtotal + totaltax - computed_discount + shippingfee;
260
- total += order.adjustment || 0;
261
- if (total < 0) total = 0;
262
- order.subtotal = subtotal;
263
- order._computed_discount = computed_discount;
264
- order._taxM = taxM;
265
- order.total = total;
266
- order.total_tax = totaltax;
267
- order._discount_before_tax = beforeTaxDiscount;
268
- order._order_value = ordervalue;
269
- }
270
-
271
- /***/ })
272
-
273
- }]);