@unchainedshop/core-products 2.7.0 → 2.7.2
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/lib/director/ProductPricingSheet.js +9 -15
- package/lib/director/ProductPricingSheet.js.map +1 -1
- package/lib/products-index.d.ts +1 -0
- package/lib/products-index.js.map +1 -1
- package/package.json +5 -5
- package/src/director/ProductPricingSheet.test.ts +0 -24
- package/src/director/ProductPricingSheet.ts +9 -17
- package/src/products-index.ts +1 -0
|
@@ -23,9 +23,11 @@ export const ProductPricingSheet = (params) => {
|
|
|
23
23
|
meta,
|
|
24
24
|
});
|
|
25
25
|
},
|
|
26
|
-
addTax({ amount, rate, meta }) {
|
|
26
|
+
addTax({ amount, baseCategory, rate, meta, discountId }) {
|
|
27
27
|
basePricingSheet.calculation.push({
|
|
28
28
|
category: ProductPricingRowCategory.Tax,
|
|
29
|
+
baseCategory,
|
|
30
|
+
discountId,
|
|
29
31
|
amount,
|
|
30
32
|
isTaxable: false,
|
|
31
33
|
isNetPrice: false,
|
|
@@ -33,15 +35,10 @@ export const ProductPricingSheet = (params) => {
|
|
|
33
35
|
meta,
|
|
34
36
|
});
|
|
35
37
|
},
|
|
36
|
-
taxSum() {
|
|
38
|
+
taxSum(filter) {
|
|
37
39
|
return basePricingSheet.sum({
|
|
38
40
|
category: ProductPricingRowCategory.Tax,
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
discountSum(discountId) {
|
|
42
|
-
return basePricingSheet.sum({
|
|
43
|
-
category: ProductPricingRowCategory.Discount,
|
|
44
|
-
discountId,
|
|
41
|
+
...(filter || {}),
|
|
45
42
|
});
|
|
46
43
|
},
|
|
47
44
|
unitPrice(unitPriceParams) {
|
|
@@ -53,7 +50,10 @@ export const ProductPricingSheet = (params) => {
|
|
|
53
50
|
},
|
|
54
51
|
discountPrices(explicitDiscountId) {
|
|
55
52
|
const discountIds = pricingSheet
|
|
56
|
-
.
|
|
53
|
+
.filterBy({
|
|
54
|
+
category: ProductPricingRowCategory.Discount,
|
|
55
|
+
discountId: explicitDiscountId,
|
|
56
|
+
})
|
|
57
57
|
.map(({ discountId }) => discountId);
|
|
58
58
|
return [...new Set(discountIds)]
|
|
59
59
|
.map((discountId) => {
|
|
@@ -72,12 +72,6 @@ export const ProductPricingSheet = (params) => {
|
|
|
72
72
|
})
|
|
73
73
|
.filter(Boolean);
|
|
74
74
|
},
|
|
75
|
-
getDiscountRows(discountId) {
|
|
76
|
-
return basePricingSheet.filterBy({
|
|
77
|
-
category: ProductPricingRowCategory.Discount,
|
|
78
|
-
discountId,
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
75
|
};
|
|
82
76
|
return pricingSheet;
|
|
83
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductPricingSheet.js","sourceRoot":"","sources":["../../src/director/ProductPricingSheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAEL,yBAAyB,GAE1B,MAAM,0CAA0C,CAAC;AAGlD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAqD,EAC/B,EAAE;IACxB,MAAM,gBAAgB,GAAG,gBAAgB,CAA4B,MAAM,CAAC,CAAC;IAE7E,MAAM,YAAY,GAAyB;QACzC,GAAG,gBAAgB;QAEnB,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE;YAC7D,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC;gBAChC,QAAQ,EAAE,yBAAyB,CAAC,QAAQ;gBAC5C,MAAM;gBACN,SAAS;gBACT,UAAU;gBACV,UAAU;gBACV,IAAI;aACL,CAAC,CAAC;QACL,CAAC;QAED,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE;YAC7C,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC;gBA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oBAC1B,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;iBACpC,CAAC;YACJ,CAAC,CAAC;iBACD,MAAM,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC;KACF,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
|
package/lib/products-index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export { productServices } from './service/productServices.js';
|
|
|
3
3
|
export { productsSettings } from './products-settings.js';
|
|
4
4
|
export { ProductPricingAdapter } from './director/ProductPricingAdapter.js';
|
|
5
5
|
export { ProductPricingDirector } from './director/ProductPricingDirector.js';
|
|
6
|
+
export { ProductDiscountConfiguration } from './director/ProductDiscountConfiguration.js';
|
|
6
7
|
export { ProductStatus } from './db/ProductStatus.js';
|
|
7
8
|
export { ProductTypes } from './db/ProductsSchema.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"products-index.js","sourceRoot":"","sources":["../src/products-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"products-index.js","sourceRoot":"","sources":["../src/products-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAG9E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-products",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"main": "lib/products-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/products-index.js",
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^2.7.
|
|
35
|
-
"@unchainedshop/file-upload": "^2.7.
|
|
36
|
-
"@unchainedshop/utils": "^2.7.
|
|
34
|
+
"@unchainedshop/events": "^2.7.2",
|
|
35
|
+
"@unchainedshop/file-upload": "^2.7.2",
|
|
36
|
+
"@unchainedshop/utils": "^2.7.2",
|
|
37
37
|
"locale": "^0.1.0",
|
|
38
38
|
"simpl-schema": "=3.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/locale": "^0.1.4",
|
|
42
42
|
"@types/node": "^20.11.17",
|
|
43
|
-
"@unchainedshop/types": "^2.7.
|
|
43
|
+
"@unchainedshop/types": "^2.7.2",
|
|
44
44
|
"jest": "^29.7.0",
|
|
45
45
|
"ts-jest": "^29.1.2",
|
|
46
46
|
"typescript": "^5.3.3"
|
|
@@ -30,10 +30,8 @@ describe('ProductPricingSheet', () => {
|
|
|
30
30
|
expect(typeof pricingSheet.addDiscount).toBe('function');
|
|
31
31
|
expect(typeof pricingSheet.addTax).toBe('function');
|
|
32
32
|
expect(typeof pricingSheet.taxSum).toBe('function');
|
|
33
|
-
expect(typeof pricingSheet.discountSum).toBe('function');
|
|
34
33
|
expect(typeof pricingSheet.unitPrice).toBe('function');
|
|
35
34
|
expect(typeof pricingSheet.discountPrices).toBe('function');
|
|
36
|
-
expect(typeof pricingSheet.getDiscountRows).toBe('function');
|
|
37
35
|
});
|
|
38
36
|
|
|
39
37
|
it('gross() should return the GROSS sum of all ProductPricingCalculation', () => {
|
|
@@ -82,13 +80,6 @@ describe('ProductPricingSheet', () => {
|
|
|
82
80
|
})
|
|
83
81
|
|
|
84
82
|
|
|
85
|
-
describe('getDiscountRows', () => {
|
|
86
|
-
it('should return all the DISCOUNTS registered on the ProductPricingSheet', () => {
|
|
87
|
-
expect(pricingSheet.getDiscountRows('for-all')).toEqual([DISCOUNT, DISCOUNT2])
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
})
|
|
91
|
-
|
|
92
83
|
describe('taxSum', () => {
|
|
93
84
|
it('should return the sum of TAX calculation registered on the adapter', () => {
|
|
94
85
|
expect(pricingSheet.taxSum()).toEqual(75)
|
|
@@ -96,13 +87,6 @@ describe('ProductPricingSheet', () => {
|
|
|
96
87
|
|
|
97
88
|
})
|
|
98
89
|
|
|
99
|
-
describe('discountSum', () => {
|
|
100
|
-
it('should return the sum of DISCOUNT calculation registered on the adapter', () => {
|
|
101
|
-
expect(pricingSheet.discountSum()).toEqual(60)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
})
|
|
105
|
-
|
|
106
90
|
describe('unitPrice', () => {
|
|
107
91
|
it('should return the GROSS sum for a product price useNetPrice:false', () => {
|
|
108
92
|
expect(pricingSheet.unitPrice({useNetPrice: false})).toEqual({"amount": 268, "currency": "CHF" })
|
|
@@ -124,14 +108,6 @@ describe('ProductPricingSheet', () => {
|
|
|
124
108
|
})
|
|
125
109
|
|
|
126
110
|
})
|
|
127
|
-
|
|
128
|
-
describe('addDiscount', () => {
|
|
129
|
-
it('should add ProductPricingCalculation DISCOUNT category successfully', () => {
|
|
130
|
-
expect(pricingSheet.getDiscountRows('new')).toEqual([])
|
|
131
|
-
pricingSheet.addDiscount({amount: 300, isNetPrice: true, isTaxable: true, discountId: 'new'})
|
|
132
|
-
expect(pricingSheet.getDiscountRows('new')).toEqual([{amount: 300, isNetPrice: true, isTaxable: true, category: 'DISCOUNT', meta: undefined, discountId: 'new'}])
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
111
|
})
|
|
136
112
|
|
|
137
113
|
|
|
@@ -35,9 +35,11 @@ export const ProductPricingSheet = (
|
|
|
35
35
|
});
|
|
36
36
|
},
|
|
37
37
|
|
|
38
|
-
addTax({ amount, rate, meta }) {
|
|
38
|
+
addTax({ amount, baseCategory, rate, meta, discountId }) {
|
|
39
39
|
basePricingSheet.calculation.push({
|
|
40
40
|
category: ProductPricingRowCategory.Tax,
|
|
41
|
+
baseCategory,
|
|
42
|
+
discountId,
|
|
41
43
|
amount,
|
|
42
44
|
isTaxable: false,
|
|
43
45
|
isNetPrice: false,
|
|
@@ -46,16 +48,10 @@ export const ProductPricingSheet = (
|
|
|
46
48
|
});
|
|
47
49
|
},
|
|
48
50
|
|
|
49
|
-
taxSum() {
|
|
51
|
+
taxSum(filter) {
|
|
50
52
|
return basePricingSheet.sum({
|
|
51
53
|
category: ProductPricingRowCategory.Tax,
|
|
52
|
-
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
discountSum(discountId) {
|
|
56
|
-
return basePricingSheet.sum({
|
|
57
|
-
category: ProductPricingRowCategory.Discount,
|
|
58
|
-
discountId,
|
|
54
|
+
...(filter || {}),
|
|
59
55
|
});
|
|
60
56
|
},
|
|
61
57
|
|
|
@@ -69,7 +65,10 @@ export const ProductPricingSheet = (
|
|
|
69
65
|
|
|
70
66
|
discountPrices(explicitDiscountId) {
|
|
71
67
|
const discountIds = pricingSheet
|
|
72
|
-
.
|
|
68
|
+
.filterBy({
|
|
69
|
+
category: ProductPricingRowCategory.Discount,
|
|
70
|
+
discountId: explicitDiscountId,
|
|
71
|
+
})
|
|
73
72
|
.map(({ discountId }) => discountId);
|
|
74
73
|
|
|
75
74
|
return [...new Set(discountIds)]
|
|
@@ -89,13 +88,6 @@ export const ProductPricingSheet = (
|
|
|
89
88
|
})
|
|
90
89
|
.filter(Boolean);
|
|
91
90
|
},
|
|
92
|
-
|
|
93
|
-
getDiscountRows(discountId: string) {
|
|
94
|
-
return basePricingSheet.filterBy({
|
|
95
|
-
category: ProductPricingRowCategory.Discount,
|
|
96
|
-
discountId,
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
91
|
};
|
|
100
92
|
|
|
101
93
|
return pricingSheet;
|
package/src/products-index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { productsSettings } from './products-settings.js';
|
|
|
5
5
|
|
|
6
6
|
export { ProductPricingAdapter } from './director/ProductPricingAdapter.js';
|
|
7
7
|
export { ProductPricingDirector } from './director/ProductPricingDirector.js';
|
|
8
|
+
export { ProductDiscountConfiguration } from './director/ProductDiscountConfiguration.js';
|
|
8
9
|
|
|
9
10
|
export { ProductStatus } from './db/ProductStatus.js';
|
|
10
11
|
export { ProductTypes } from './db/ProductsSchema.js';
|