@ancon/wildcat-utils 1.45.0 → 1.46.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.45.0",
3
+ "version": "1.46.0",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -1,3 +1,3 @@
1
- import { ProductDetailsAddonGroup } from '@ancon/wildcat-types';
1
+ import { PurchaseProductDetailsAddonGroup } from '@ancon/wildcat-types';
2
2
  import { ConfigureAddonGroupFormState } from './types';
3
- export default function calculateAddonGroupsCost(addonGroups: ProductDetailsAddonGroup[], addonsFormState: ConfigureAddonGroupFormState[]): number;
3
+ export default function calculateAddonGroupsCost(addonGroups: PurchaseProductDetailsAddonGroup[], addonsFormState: ConfigureAddonGroupFormState[]): number;
@@ -1 +1 @@
1
- "use strict";function P(I,g){return g.reduce((o,m)=>{const{ingredients:c,addonId:F,selectedIngredientId:l,selectedCount:f}=m,a=I.find(e=>e.addOnGroupId===F);if(a){const{ingredients:e,addOnSettings:A}=a;if(l){const n=e==null?void 0:e.find(t=>t.id===l);if(n){const t=c.some(i=>i.freeAmount===1),{price:d}=n;return o+(t?0:d)}}const{afterFreePrice:p,freeAmount:s}=A,O=s!==null&&p!==null&&s>0&&f>s,D=c.reduce((n,t)=>{const{selectedCount:d,freeAmount:i}=t;if(f>0){const u=d-i;if(u===0)return n;if(O){const r=u*p.amount;return n+r}const C=e==null?void 0:e.find(r=>r.id===t.id);if(C){const{price:r}=C,G=r*u;return n+G}}return n},0);return o+D}return o},0)}module.exports=P;
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(I, g) {
2
- return g.reduce((o, m) => {
1
+ function j(b, D) {
2
+ return D.reduce((c, O) => {
3
3
  const {
4
- ingredients: c,
5
- addonId: F,
6
- selectedIngredientId: l,
7
- selectedCount: a
8
- } = m, f = I.find((e) => e.addOnGroupId === F);
9
- if (f) {
10
- const { ingredients: e, addOnSettings: A } = f;
11
- if (l) {
12
- const n = e == null ? void 0 : e.find(
13
- (t) => t.id === l
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 (n) {
16
- const t = c.some(
16
+ if (e) {
17
+ const t = p.some(
17
18
  (i) => i.freeAmount === 1
18
- ), { price: s } = n;
19
- return o + (t ? 0 : s);
19
+ ), { price: d } = e;
20
+ return c + (t ? 0 : d);
20
21
  }
21
22
  }
22
- const { afterFreePrice: p, freeAmount: d } = A, O = d !== null && p !== null && d > 0 && a > d, D = c.reduce(
23
- (n, t) => {
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: s,
26
+ selectedCount: d,
26
27
  freeAmount: i
27
28
  } = t;
28
- if (a > 0) {
29
- const u = s - i;
29
+ if (l > 0) {
30
+ const u = d - i;
30
31
  if (u === 0)
31
- return n;
32
- if (O) {
33
- const r = u * p.amount;
34
- return n + r;
32
+ return e;
33
+ if (F) {
34
+ const o = u * a.amount;
35
+ return e + o;
35
36
  }
36
- const C = e == null ? void 0 : e.find(
37
- (r) => r.id === t.id
37
+ const s = r == null ? void 0 : r.find(
38
+ (o) => o.id === t.id
38
39
  );
39
- if (C) {
40
- const { price: r } = C, G = r * u;
41
- return n + G;
40
+ if (s) {
41
+ const { price: o } = s, n = o * u;
42
+ return e + n;
42
43
  }
43
44
  }
44
- return n;
45
+ return e;
45
46
  },
46
47
  0
47
- );
48
- return o + D;
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 o;
77
+ return c;
51
78
  }, 0);
52
79
  }
53
80
  export {
54
- b as default
81
+ j as default
55
82
  };
@@ -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;