@ancon/wildcat-utils 1.45.0 → 1.46.1
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.
- package/checkout/getCheckoutRequestItemFromCheckoutItem.js +1 -1
- package/checkout/getCheckoutRequestItemFromCheckoutItem.mjs +9 -8
- package/package.json +1 -1
- package/product/calculateAddonGroupCost.d.ts +2 -2
- package/product/calculateAddonGroupCost.js +1 -1
- package/product/calculateAddonGroupCost.mjs +62 -35
- package/product/types.d.ts +7 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const l=require("./isWalletTopUpCheckoutItem.js"),c=require("./isGiftCardCheckoutItem.js");require("@ancon/wildcat-types");function I(u,a){const{product:r,quantity:s,modifications:p,upsellGroupId:d,totalPriceInclTax:n}=u;if(l(u)){let e=null;if(a){const t=a;e=JSON.stringify({id:t.id,prepaidWalletNumber:t.prepaidWalletNumber})}return{productType:r.productType,variantType:r.variantType,price:{unitPrice:n.amount},metaData:e,quantity:s,modifications:[]}}if(c(u)){let e=null;if(a){const t=a;e=JSON.stringify({draftGiftCardId:t.draftGiftCardId,amount:t.amount,email:t.email,greetingMessage:t.greetingMessage,id:t.id,receivedBy:t.receivedBy,senderEmail:t.senderEmail,sendingBy:t.sendingBy,sms:t.sms})}return{productType:r.productType,variantType:r.variantType,price:{unitPrice:n.amount},metaData:e,quantity:s,modifications:[]}}return{variantId:r.variantId,quantity:s,modifications:p.map(e=>({modification:e.modification,ingredientId:e.ingredientId,quantity:e==null?void 0:e.quantity,freeAmount:e==null?void 0:e.freeAmount,addOnGroupId:(e==null?void 0:e.groupId)||void 0,replaceId:e.replaceId||void 0,description:e==null?void 0:e.description})),upsellGroupId:d}}module.exports=I;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import l from "./isWalletTopUpCheckoutItem.mjs";
|
|
2
|
+
import I from "./isGiftCardCheckoutItem.mjs";
|
|
3
3
|
import "@ancon/wildcat-types";
|
|
4
|
-
function
|
|
5
|
-
const { product: r, quantity: p, modifications: s, upsellGroupId:
|
|
6
|
-
if (
|
|
4
|
+
function i(u, a) {
|
|
5
|
+
const { product: r, quantity: p, modifications: s, upsellGroupId: d, totalPriceInclTax: n } = u;
|
|
6
|
+
if (l(u)) {
|
|
7
7
|
let e = null;
|
|
8
8
|
if (a) {
|
|
9
9
|
const t = a;
|
|
@@ -21,11 +21,12 @@ function v(u, a) {
|
|
|
21
21
|
modifications: []
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
if (
|
|
24
|
+
if (I(u)) {
|
|
25
25
|
let e = null;
|
|
26
26
|
if (a) {
|
|
27
27
|
const t = a;
|
|
28
28
|
e = JSON.stringify({
|
|
29
|
+
draftGiftCardId: t.draftGiftCardId,
|
|
29
30
|
amount: t.amount,
|
|
30
31
|
email: t.email,
|
|
31
32
|
greetingMessage: t.greetingMessage,
|
|
@@ -57,9 +58,9 @@ function v(u, a) {
|
|
|
57
58
|
replaceId: e.replaceId || void 0,
|
|
58
59
|
description: e == null ? void 0 : e.description
|
|
59
60
|
})),
|
|
60
|
-
upsellGroupId:
|
|
61
|
+
upsellGroupId: d
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
export {
|
|
64
|
-
|
|
65
|
+
i as default
|
|
65
66
|
};
|
package/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PurchaseProductDetailsAddonGroup } from '@ancon/wildcat-types';
|
|
2
2
|
import { ConfigureAddonGroupFormState } from './types';
|
|
3
|
-
export default function calculateAddonGroupsCost(addonGroups:
|
|
3
|
+
export default function calculateAddonGroupsCost(addonGroups: PurchaseProductDetailsAddonGroup[], addonsFormState: ConfigureAddonGroupFormState[]): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function S(b,D){return D.reduce((c,O)=>{const{ingredients:p,addonId:A,selectedIngredientId:m,selectedCount:l,products:G}=O,I=b.find(r=>r.addOnGroupId===A);if(I){const{ingredients:r,addOnSettings:h,products:f}=I;if(m){const e=r==null?void 0:r.find(t=>t.id===m);if(e){const t=p.some(i=>i.freeAmount===1),{price:d}=e;return c+(t?0:d)}}const{afterFreePrice:a,freeAmount:C}=h,F=C!==null&&a!==null&&C>0&&l>C,y=p.reduce((e,t)=>{const{selectedCount:d,freeAmount:i}=t;if(l>0){const u=d-i;if(u===0)return e;if(F){const o=u*a.amount;return e+o}const s=r==null?void 0:r.find(o=>o.id===t.id);if(s){const{price:o}=s,n=o*u;return e+n}}return e},0),V=G.reduce((e,t)=>{const{selectedCount:d,freeAmount:i,selectedVariantId:u}=t;if(l>0){const s=d-i;if(s===0)return e;if(F){const n=s*a.amount;return e+n}const o=f==null?void 0:f.find(n=>n.id===t.id);if(o){const{variants:n}=o,P=n==null?void 0:n.find(g=>g.id===u);if(P){const x=P.price.unitPrice*s;return e+x}}}return e},0);return c+y+V}return c},0)}module.exports=S;
|
|
@@ -1,55 +1,82 @@
|
|
|
1
|
-
function b
|
|
2
|
-
return
|
|
1
|
+
function j(b, D) {
|
|
2
|
+
return D.reduce((c, O) => {
|
|
3
3
|
const {
|
|
4
|
-
ingredients:
|
|
5
|
-
addonId:
|
|
6
|
-
selectedIngredientId:
|
|
7
|
-
selectedCount:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
ingredients: p,
|
|
5
|
+
addonId: A,
|
|
6
|
+
selectedIngredientId: m,
|
|
7
|
+
selectedCount: l,
|
|
8
|
+
products: G
|
|
9
|
+
} = O, I = b.find((r) => r.addOnGroupId === A);
|
|
10
|
+
if (I) {
|
|
11
|
+
const { ingredients: r, addOnSettings: h, products: f } = I;
|
|
12
|
+
if (m) {
|
|
13
|
+
const e = r == null ? void 0 : r.find(
|
|
14
|
+
(t) => t.id === m
|
|
14
15
|
);
|
|
15
|
-
if (
|
|
16
|
-
const t =
|
|
16
|
+
if (e) {
|
|
17
|
+
const t = p.some(
|
|
17
18
|
(i) => i.freeAmount === 1
|
|
18
|
-
), { price:
|
|
19
|
-
return
|
|
19
|
+
), { price: d } = e;
|
|
20
|
+
return c + (t ? 0 : d);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
const { afterFreePrice:
|
|
23
|
-
(
|
|
23
|
+
const { afterFreePrice: a, freeAmount: C } = h, F = C !== null && a !== null && C > 0 && l > C, y = p.reduce(
|
|
24
|
+
(e, t) => {
|
|
24
25
|
const {
|
|
25
|
-
selectedCount:
|
|
26
|
+
selectedCount: d,
|
|
26
27
|
freeAmount: i
|
|
27
28
|
} = t;
|
|
28
|
-
if (
|
|
29
|
-
const u =
|
|
29
|
+
if (l > 0) {
|
|
30
|
+
const u = d - i;
|
|
30
31
|
if (u === 0)
|
|
31
|
-
return
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
return
|
|
32
|
+
return e;
|
|
33
|
+
if (F) {
|
|
34
|
+
const o = u * a.amount;
|
|
35
|
+
return e + o;
|
|
35
36
|
}
|
|
36
|
-
const
|
|
37
|
-
(
|
|
37
|
+
const s = r == null ? void 0 : r.find(
|
|
38
|
+
(o) => o.id === t.id
|
|
38
39
|
);
|
|
39
|
-
if (
|
|
40
|
-
const { price:
|
|
41
|
-
return
|
|
40
|
+
if (s) {
|
|
41
|
+
const { price: o } = s, n = o * u;
|
|
42
|
+
return e + n;
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
return
|
|
45
|
+
return e;
|
|
45
46
|
},
|
|
46
47
|
0
|
|
47
|
-
)
|
|
48
|
-
|
|
48
|
+
), V = G.reduce((e, t) => {
|
|
49
|
+
const {
|
|
50
|
+
selectedCount: d,
|
|
51
|
+
freeAmount: i,
|
|
52
|
+
selectedVariantId: u
|
|
53
|
+
} = t;
|
|
54
|
+
if (l > 0) {
|
|
55
|
+
const s = d - i;
|
|
56
|
+
if (s === 0)
|
|
57
|
+
return e;
|
|
58
|
+
if (F) {
|
|
59
|
+
const n = s * a.amount;
|
|
60
|
+
return e + n;
|
|
61
|
+
}
|
|
62
|
+
const o = f == null ? void 0 : f.find((n) => n.id === t.id);
|
|
63
|
+
if (o) {
|
|
64
|
+
const { variants: n } = o, P = n == null ? void 0 : n.find(
|
|
65
|
+
(g) => g.id === u
|
|
66
|
+
);
|
|
67
|
+
if (P) {
|
|
68
|
+
const x = P.price.unitPrice * s;
|
|
69
|
+
return e + x;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return e;
|
|
74
|
+
}, 0);
|
|
75
|
+
return c + y + V;
|
|
49
76
|
}
|
|
50
|
-
return
|
|
77
|
+
return c;
|
|
51
78
|
}, 0);
|
|
52
79
|
}
|
|
53
80
|
export {
|
|
54
|
-
|
|
81
|
+
j as default
|
|
55
82
|
};
|
package/product/types.d.ts
CHANGED
|
@@ -10,9 +10,16 @@ export declare type ConfigureAddonIngredientFormState = {
|
|
|
10
10
|
selectedCount: number;
|
|
11
11
|
freeAmount: number;
|
|
12
12
|
};
|
|
13
|
+
export declare type ConfigureAddonProductFormState = {
|
|
14
|
+
id: string;
|
|
15
|
+
selectedCount: number;
|
|
16
|
+
freeAmount: number;
|
|
17
|
+
selectedVariantId: string;
|
|
18
|
+
};
|
|
13
19
|
export declare type ConfigureAddonGroupFormState = {
|
|
14
20
|
addonId: string;
|
|
15
21
|
ingredients: ConfigureAddonIngredientFormState[];
|
|
22
|
+
products: ConfigureAddonProductFormState[];
|
|
16
23
|
selectedIngredientId: string | null;
|
|
17
24
|
selectedCount: number;
|
|
18
25
|
addOnSettings: AddonSettings;
|