@pisell/private-materials 6.3.139 → 6.3.140

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 (47) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/index.js +1 -1
  5. package/build/lowcode/meta.js +1 -1
  6. package/build/lowcode/preview.js +5 -5
  7. package/build/lowcode/render/default/view.css +1 -1
  8. package/build/lowcode/render/default/view.js +7 -7
  9. package/build/lowcode/view.css +1 -1
  10. package/build/lowcode/view.js +6 -6
  11. package/es/components/scanOrder/components/Cart/index.js +127 -56
  12. package/es/components/scanOrder/components/Cart/index.less +11 -5
  13. package/es/components/scanOrder/components/Check/index.js +85 -80
  14. package/es/components/scanOrder/components/Content/index.js +345 -162
  15. package/es/components/scanOrder/components/Menu/index.d.ts +11 -0
  16. package/es/components/scanOrder/components/Menu/index.js +140 -169
  17. package/es/components/scanOrder/components/Voucher/index.d.ts +8 -0
  18. package/es/components/scanOrder/components/Voucher/index.js +250 -0
  19. package/es/components/scanOrder/context.js +38 -13
  20. package/es/components/scanOrder/hooks.js +4 -1
  21. package/es/components/scanOrder/locales.d.ts +65 -0
  22. package/es/components/scanOrder/locales.js +65 -0
  23. package/es/components/scanOrder/types.d.ts +10 -0
  24. package/es/components/scanOrder/utils/toShoppingCartProducts.d.ts +1 -0
  25. package/es/components/scanOrder/utils/toShoppingCartProducts.js +137 -9
  26. package/es/components/scanOrder/utils/transformProductDetail.js +21 -4
  27. package/es/components/venueBooking/components/Addons/index.js +42 -33
  28. package/es/components/venueBooking/components/Cart/index.js +26 -14
  29. package/lib/components/scanOrder/components/Cart/index.js +79 -24
  30. package/lib/components/scanOrder/components/Cart/index.less +11 -5
  31. package/lib/components/scanOrder/components/Check/index.js +28 -23
  32. package/lib/components/scanOrder/components/Content/index.js +132 -42
  33. package/lib/components/scanOrder/components/Menu/index.d.ts +11 -0
  34. package/lib/components/scanOrder/components/Menu/index.js +23 -36
  35. package/lib/components/scanOrder/components/Voucher/index.d.ts +8 -0
  36. package/lib/components/scanOrder/components/Voucher/index.js +162 -0
  37. package/lib/components/scanOrder/context.js +21 -10
  38. package/lib/components/scanOrder/hooks.js +4 -1
  39. package/lib/components/scanOrder/locales.d.ts +65 -0
  40. package/lib/components/scanOrder/locales.js +65 -0
  41. package/lib/components/scanOrder/types.d.ts +10 -0
  42. package/lib/components/scanOrder/utils/toShoppingCartProducts.d.ts +1 -0
  43. package/lib/components/scanOrder/utils/toShoppingCartProducts.js +88 -6
  44. package/lib/components/scanOrder/utils/transformProductDetail.js +10 -3
  45. package/lib/components/venueBooking/components/Addons/index.js +15 -8
  46. package/lib/components/venueBooking/components/Cart/index.js +8 -2
  47. package/package.json +1 -1
@@ -73,6 +73,76 @@ function normalizeOptions(product) {
73
73
  };
74
74
  });
75
75
  }
76
+ function getProductOriginRich(product) {
77
+ var _a, _b, _c;
78
+ return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.origin) || ((_c = (_b = product == null ? void 0 : product._origin) == null ? void 0 : _b.callbackData) == null ? void 0 : _c.origin) || {};
79
+ }
80
+ function findVariantGroupById(groups, groupId) {
81
+ return groups.find((g) => Number(g == null ? void 0 : g.id) === Number(groupId));
82
+ }
83
+ function findVariantItemDisplayName(variantGroup, variantItemId) {
84
+ const items = Array.isArray(variantGroup == null ? void 0 : variantGroup.variant_item) ? variantGroup.variant_item : [];
85
+ const found = items.find(
86
+ (it) => Number(it == null ? void 0 : it.id) === Number(variantItemId)
87
+ );
88
+ const raw = (found == null ? void 0 : found.name) ?? (typeof (found == null ? void 0 : found.title) === "string" ? found.title : found == null ? void 0 : found.title) ?? "";
89
+ return String(raw ?? "").trim();
90
+ }
91
+ function buildVariantStringFromSkuIds(origin, skuIdsRaw) {
92
+ const groups = Array.isArray(origin == null ? void 0 : origin.variant_group) ? origin.variant_group : [];
93
+ const parts = [];
94
+ const segments = String(skuIdsRaw || "").split("_").map((s) => s.trim()).filter(Boolean);
95
+ for (const seg of segments) {
96
+ const colonIdx = seg.indexOf(":");
97
+ if (colonIdx <= 0) continue;
98
+ const groupId = Number(seg.slice(0, colonIdx));
99
+ const itemId = Number(seg.slice(colonIdx + 1));
100
+ if (Number.isNaN(groupId) || Number.isNaN(itemId)) continue;
101
+ const vg = findVariantGroupById(groups, groupId);
102
+ if (!vg) continue;
103
+ const groupName = String((vg == null ? void 0 : vg.name) ?? "").trim();
104
+ const itemName = findVariantItemDisplayName(vg, itemId);
105
+ if (groupName && itemName) parts.push(`${groupName}: ${itemName}`);
106
+ else if (itemName) parts.push(itemName);
107
+ else if (groupName) parts.push(groupName);
108
+ }
109
+ return parts.join(", ");
110
+ }
111
+ function fallbackVariantLabelFromTitles(origin, variantRow) {
112
+ const groups = Array.isArray(origin == null ? void 0 : origin.variant_group) ? origin.variant_group : [];
113
+ const nameObj = (variantRow == null ? void 0 : variantRow.name) || (variantRow == null ? void 0 : variantRow.title);
114
+ if (!nameObj || typeof nameObj !== "object") return "";
115
+ const parts = [];
116
+ for (const g of groups) {
117
+ const pid = g == null ? void 0 : g.position_id;
118
+ if (pid == null) continue;
119
+ const val = nameObj[String(pid)] ?? nameObj[pid];
120
+ if (val == null || val === "") continue;
121
+ const groupName = String((g == null ? void 0 : g.name) ?? "").trim();
122
+ const itemLabel = String(val).trim();
123
+ if (groupName && itemLabel) parts.push(`${groupName}: ${itemLabel}`);
124
+ else if (itemLabel) parts.push(itemLabel);
125
+ }
126
+ if (parts.length) return parts.join(", ");
127
+ const vals = Object.values(nameObj).filter(
128
+ (v) => v != null && String(v).trim() !== ""
129
+ );
130
+ return vals.map((v) => String(v).trim()).join(" / ");
131
+ }
132
+ function getVariantProductOptionString(product) {
133
+ const variantId = product == null ? void 0 : product.product_variant_id;
134
+ if (variantId == null || variantId === "" || Number(variantId) <= 0) return "";
135
+ const origin = getProductOriginRich(product);
136
+ const variants = Array.isArray(origin == null ? void 0 : origin.variant) ? origin.variant : [];
137
+ const matched = variants.find((v) => Number(v == null ? void 0 : v.id) === Number(variantId));
138
+ if (!matched) return "";
139
+ const skuIds = matched == null ? void 0 : matched.sku_ids;
140
+ if (skuIds != null && String(skuIds).trim() !== "") {
141
+ const fromSku = buildVariantStringFromSkuIds(origin, String(skuIds));
142
+ if (fromSku) return fromSku;
143
+ }
144
+ return fallbackVariantLabelFromTitles(origin, matched);
145
+ }
76
146
  function normalizeBundles(product) {
77
147
  var _a;
78
148
  const callbackData = ((_a = product == null ? void 0 : product._origin) == null ? void 0 : _a.callbackData) || {};
@@ -112,17 +182,22 @@ function toShoppingCartProducts(params) {
112
182
  const { orderProducts, amountSymbol = "$" } = params;
113
183
  if (!Array.isArray(orderProducts)) return [];
114
184
  return orderProducts.map((productItem, index) => {
115
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
185
+ var _a, _b, _c, _d;
116
186
  const productNum = toSafeNum(productItem == null ? void 0 : productItem.num);
117
187
  const unitPrice = getUnitPrice(productItem);
118
- const rowKey = ((_b = (_a = productItem == null ? void 0 : productItem._origin) == null ? void 0 : _a.callbackData) == null ? void 0 : _b.rowKey) || ((_d = (_c = productItem == null ? void 0 : productItem._origin) == null ? void 0 : _c.callbackData) == null ? void 0 : _d.key) || ((_f = (_e = productItem == null ? void 0 : productItem._origin) == null ? void 0 : _e.callbackData) == null ? void 0 : _f.unique) || (productItem == null ? void 0 : productItem.identity_key) || `${productItem.product_id ?? "p"}_${productItem.product_variant_id}_${index}`;
188
+ const callbackData = ((_a = productItem == null ? void 0 : productItem._origin) == null ? void 0 : _a.callbackData) || {};
189
+ const identityKey = typeof (productItem == null ? void 0 : productItem.identity_key) === "string" && productItem.identity_key.length > 0 ? productItem.identity_key : void 0;
190
+ const rowKey = identityKey ?? `${productItem.product_id ?? "p"}_${productItem.product_variant_id}_${index}`;
191
+ const fromCallbackOptionString = typeof (callbackData == null ? void 0 : callbackData.product_option_string) === "string" ? callbackData.product_option_string.trim() : "";
192
+ const productOptionString = fromCallbackOptionString || getVariantProductOptionString(productItem) || void 0;
119
193
  const base = {
120
194
  _id: rowKey,
121
195
  rowKey,
122
- identity_key: (productItem == null ? void 0 : productItem.identity_key) || void 0,
196
+ identity_key: identityKey,
123
197
  id: productItem.product_id,
124
198
  product_id: productItem.product_id,
125
199
  product_variant_id: productItem.product_variant_id,
200
+ note: (productItem == null ? void 0 : productItem.note) != null ? String(productItem.note) : "",
126
201
  name: getDisplayName(productItem),
127
202
  image: getDisplayImage(productItem),
128
203
  num: productNum,
@@ -133,9 +208,16 @@ function toShoppingCartProducts(params) {
133
208
  options: normalizeOptions(productItem),
134
209
  bundle: normalizeBundles(productItem),
135
210
  _origin: productItem == null ? void 0 : productItem._origin,
136
- isNormalProduct: true
211
+ isNormalProduct: true,
212
+ ...productOptionString ? { product_option_string: productOptionString } : {}
137
213
  };
138
- if ((_g = productItem == null ? void 0 : productItem.metadata) == null ? void 0 : _g.venue_booking) {
214
+ if (Array.isArray(productItem.product_option_item) && productItem.product_option_item.length) {
215
+ base.product_option_item = productItem.product_option_item;
216
+ }
217
+ if (Array.isArray(productItem.product_bundle) && productItem.product_bundle.length) {
218
+ base.product_bundle = productItem.product_bundle;
219
+ }
220
+ if ((_b = productItem == null ? void 0 : productItem.metadata) == null ? void 0 : _b.venue_booking) {
139
221
  const origin = productItem._origin || {};
140
222
  const meta = productItem.metadata || {};
141
223
  const startDate = origin.start_date;
@@ -148,7 +230,7 @@ function toShoppingCartProducts(params) {
148
230
  base.end_time = endTime || "";
149
231
  base.duration_type = origin.sub_type || "minutes";
150
232
  base.resource_id = meta.resource_id;
151
- base.relation_form_name = meta.resource_name || ((_i = (_h = origin.resources) == null ? void 0 : _h[0]) == null ? void 0 : _i.main_field) || "";
233
+ base.relation_form_name = meta.resource_name || ((_d = (_c = origin.resources) == null ? void 0 : _c[0]) == null ? void 0 : _d.main_field) || "";
152
234
  if (Array.isArray(origin.resources)) base.resources = origin.resources;
153
235
  }
154
236
  return base;
@@ -66,6 +66,12 @@ function normalizeBundleItems(bundleItems) {
66
66
  };
67
67
  });
68
68
  }
69
+ function findVariantById(origin, variantId) {
70
+ if (!origin || !variantId || variantId <= 0) return null;
71
+ const variants = Array.isArray(origin == null ? void 0 : origin.variant) ? origin.variant : [];
72
+ const matched = variants.find((v) => Number(v == null ? void 0 : v.id) === variantId);
73
+ return matched || null;
74
+ }
69
75
  function transformProductDetailToOrderProduct(params) {
70
76
  var _a;
71
77
  const { payload, fallbackProductId = null, sourceItem = {} } = params;
@@ -79,17 +85,18 @@ function transformProductDetailToOrderProduct(params) {
79
85
  0
80
86
  );
81
87
  const callbackOrigin = (payload == null ? void 0 : payload.origin) || ((_a = payload == null ? void 0 : payload._origin) == null ? void 0 : _a.sourceItem) || (payload == null ? void 0 : payload._origin) || {};
88
+ const matchedVariant = findVariantById(callbackOrigin, productVariantId) ?? findVariantById(sourceItem, productVariantId);
82
89
  const sellingPrice = toPriceString(
83
- (payload == null ? void 0 : payload.price) ?? (payload == null ? void 0 : payload.selling_price) ?? (callbackOrigin == null ? void 0 : callbackOrigin.price) ?? (sourceItem == null ? void 0 : sourceItem.price) ?? (sourceItem == null ? void 0 : sourceItem.selling_price) ?? (sourceItem == null ? void 0 : sourceItem.base_price),
90
+ (payload == null ? void 0 : payload.price) ?? (payload == null ? void 0 : payload.selling_price) ?? (matchedVariant == null ? void 0 : matchedVariant.price) ?? (matchedVariant == null ? void 0 : matchedVariant.base_price) ?? (callbackOrigin == null ? void 0 : callbackOrigin.price) ?? (sourceItem == null ? void 0 : sourceItem.price) ?? (sourceItem == null ? void 0 : sourceItem.selling_price) ?? (sourceItem == null ? void 0 : sourceItem.base_price),
84
91
  "0.00"
85
92
  );
86
93
  const originalPrice = sellingPrice;
87
94
  const taxFee = toPriceString(
88
- (payload == null ? void 0 : payload.tax_fee) ?? (callbackOrigin == null ? void 0 : callbackOrigin.tax_fee) ?? (sourceItem == null ? void 0 : sourceItem.tax_fee),
95
+ (payload == null ? void 0 : payload.tax_fee) ?? (matchedVariant == null ? void 0 : matchedVariant.tax_fee) ?? (callbackOrigin == null ? void 0 : callbackOrigin.tax_fee) ?? (sourceItem == null ? void 0 : sourceItem.tax_fee),
89
96
  "0.00"
90
97
  );
91
98
  const isChargeTax = toNumber(
92
- (payload == null ? void 0 : payload.is_charge_tax) ?? (callbackOrigin == null ? void 0 : callbackOrigin.is_charge_tax) ?? (sourceItem == null ? void 0 : sourceItem.is_charge_tax),
99
+ (payload == null ? void 0 : payload.is_charge_tax) ?? (matchedVariant == null ? void 0 : matchedVariant.is_charge_tax) ?? (callbackOrigin == null ? void 0 : callbackOrigin.is_charge_tax) ?? (sourceItem == null ? void 0 : sourceItem.is_charge_tax),
93
100
  0
94
101
  );
95
102
  return {
@@ -93,11 +93,12 @@ function Addons() {
93
93
  }
94
94
  };
95
95
  const removeOrderProduct = async (params) => {
96
- const { product_id, product_variant_id, sourceData } = params;
96
+ const { product_id, product_variant_id, identity_key, sourceData } = params;
97
97
  try {
98
98
  await runModuleAction("removeProductFromOrder", {
99
99
  product_id,
100
- product_variant_id
100
+ product_variant_id,
101
+ ...identity_key ? { identity_key } : {}
101
102
  });
102
103
  await refreshViewModel();
103
104
  } catch (error) {
@@ -105,16 +106,18 @@ function Addons() {
105
106
  error,
106
107
  sourceData,
107
108
  product_id,
108
- product_variant_id
109
+ product_variant_id,
110
+ identity_key
109
111
  });
110
112
  }
111
113
  };
112
114
  const updateOrderProduct = async (params) => {
113
- const { product_id, product_variant_id, updates, sourceData } = params;
115
+ const { product_id, product_variant_id, identity_key, updates, sourceData } = params;
114
116
  try {
115
117
  await runModuleAction("updateProductInOrder", {
116
118
  product_id,
117
119
  product_variant_id,
120
+ ...identity_key ? { identity_key } : {},
118
121
  updates
119
122
  });
120
123
  await refreshViewModel();
@@ -124,6 +127,7 @@ function Addons() {
124
127
  sourceData,
125
128
  product_id,
126
129
  product_variant_id,
130
+ identity_key,
127
131
  updates
128
132
  });
129
133
  }
@@ -158,18 +162,20 @@ function Addons() {
158
162
  return;
159
163
  }
160
164
  const normalizedQuantity = Number.isNaN(nextQuantity) ? 0 : Math.max(0, Math.floor(nextQuantity));
165
+ const cartItems = Array.isArray(viewModel == null ? void 0 : viewModel.cartItems) ? viewModel.cartItems : [];
166
+ const existedCartItem = cartItems.find((cartItem) => {
167
+ return String((cartItem == null ? void 0 : cartItem.product_id) ?? null) === String((orderProduct == null ? void 0 : orderProduct.product_id) ?? null) && Number((cartItem == null ? void 0 : cartItem.product_variant_id) ?? 0) === productVariantId;
168
+ });
169
+ const existedIdentityKey = typeof (existedCartItem == null ? void 0 : existedCartItem.identity_key) === "string" && existedCartItem.identity_key.length > 0 ? existedCartItem.identity_key : void 0;
161
170
  if (normalizedQuantity <= 0) {
162
171
  await removeOrderProduct({
163
172
  product_id: (orderProduct == null ? void 0 : orderProduct.product_id) ?? null,
164
173
  product_variant_id: productVariantId,
174
+ identity_key: existedIdentityKey,
165
175
  sourceData: quantityData
166
176
  });
167
177
  return;
168
178
  }
169
- const cartItems = Array.isArray(viewModel == null ? void 0 : viewModel.cartItems) ? viewModel.cartItems : [];
170
- const existedCartItem = cartItems.find((cartItem) => {
171
- return String((cartItem == null ? void 0 : cartItem.product_id) ?? null) === String((orderProduct == null ? void 0 : orderProduct.product_id) ?? null) && Number((cartItem == null ? void 0 : cartItem.product_variant_id) ?? 0) === productVariantId;
172
- });
173
179
  if (!existedCartItem) {
174
180
  await addOrderProduct({
175
181
  orderProduct: { ...orderProduct, num: normalizedQuantity },
@@ -180,6 +186,7 @@ function Addons() {
180
186
  await updateOrderProduct({
181
187
  product_id: (orderProduct == null ? void 0 : orderProduct.product_id) ?? null,
182
188
  product_variant_id: productVariantId,
189
+ identity_key: existedIdentityKey,
183
190
  updates: {
184
191
  num: normalizedQuantity,
185
192
  _origin: orderProduct == null ? void 0 : orderProduct._origin
@@ -139,7 +139,7 @@ function Cart(props) {
139
139
  const isVenueBookingCartItem = (target) => {
140
140
  if (!target || typeof target !== "object") return false;
141
141
  if ((target == null ? void 0 : target.start_date) && (target == null ? void 0 : target.end_date)) return true;
142
- const identity = String((target == null ? void 0 : target.identity_key) || (target == null ? void 0 : target.rowKey) || (target == null ? void 0 : target._id) || "");
142
+ const identity = String((target == null ? void 0 : target.identity_key) || "");
143
143
  if (identity.startsWith("venue:")) return true;
144
144
  return false;
145
145
  };
@@ -157,8 +157,14 @@ function Cart(props) {
157
157
  }
158
158
  const productId = (targetItem == null ? void 0 : targetItem.product_id) ?? (targetItem == null ? void 0 : targetItem.id) ?? null;
159
159
  const productVariantId = Number((targetItem == null ? void 0 : targetItem.product_variant_id) ?? 0);
160
- const identityKey = (targetItem == null ? void 0 : targetItem.identity_key) || (targetItem == null ? void 0 : targetItem.rowKey) || void 0;
160
+ const identityKey = targetItem == null ? void 0 : targetItem.identity_key;
161
161
  if (productId === null && Number.isNaN(productVariantId)) return;
162
+ if (typeof identityKey !== "string" || identityKey.length === 0) {
163
+ console.error("[venueBooking] removeProductFromOrder skipped: missing identity_key", {
164
+ item: targetItem
165
+ });
166
+ return;
167
+ }
162
168
  try {
163
169
  await runModuleAction("removeProductFromOrder", {
164
170
  product_id: productId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.3.139",
3
+ "version": "6.3.140",
4
4
  "scripts": {
5
5
  "dev": "father dev",
6
6
  "build": "father build",