@unchainedshop/plugins 2.7.2 → 2.7.3
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.
|
@@ -36,11 +36,15 @@ export const OrderDiscount = {
|
|
|
36
36
|
let amountLeft = totalAmountOfPaymentAndDelivery + totalAmountOfItems;
|
|
37
37
|
params.discounts.forEach(({ configuration, discountId }) => {
|
|
38
38
|
// First, we deduce the discount from the items
|
|
39
|
-
const leftInDiscountToSplit = calcUtils.calculateAmountToSplit({ ...configuration }, totalAmountOfItems);
|
|
39
|
+
const leftInDiscountToSplit = calcUtils.calculateAmountToSplit({ ...configuration }, Math.min(totalAmountOfItems, amountLeft));
|
|
40
40
|
const [itemsDiscountAmount, itemsTaxAmount] = calcUtils.applyDiscountToMultipleShares(itemShares, Math.max(0, Math.min(amountLeft, leftInDiscountToSplit)));
|
|
41
41
|
amountLeft -= itemsDiscountAmount;
|
|
42
|
-
//
|
|
43
|
-
|
|
42
|
+
// If it's a fixed rate we need to deduct the already deducted amount from the fixed rate
|
|
43
|
+
// before we hand it over to the split calculation
|
|
44
|
+
const fixedRate = configuration.fixedRate > 0
|
|
45
|
+
? Math.max(0, configuration.fixedRate - itemsDiscountAmount)
|
|
46
|
+
: undefined;
|
|
47
|
+
const leftInFeesToSplit = calcUtils.calculateAmountToSplit({ ...configuration, fixedRate }, Math.min(totalAmountOfPaymentAndDelivery, amountLeft));
|
|
44
48
|
const [deliveryAndPaymentDiscountAmount, deliveryAndPaymentTaxAmount] = calcUtils.applyDiscountToMultipleShares([deliveryShare, paymentShare], Math.max(0, Math.min(amountLeft, leftInFeesToSplit)));
|
|
45
49
|
amountLeft -= deliveryAndPaymentDiscountAmount;
|
|
46
50
|
const discountAmount = (itemsDiscountAmount + deliveryAndPaymentDiscountAmount) * -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-discount.js","sourceRoot":"","sources":["../../src/pricing/order-discount.ts"],"names":[],"mappings":"AA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": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -88,22 +88,22 @@
|
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@redis/client": "^1.5.14",
|
|
90
90
|
"@types/node": "^20.11.17",
|
|
91
|
-
"@unchainedshop/api": "^2.7.
|
|
92
|
-
"@unchainedshop/core-delivery": "^2.7.
|
|
93
|
-
"@unchainedshop/core-enrollments": "^2.7.
|
|
94
|
-
"@unchainedshop/core-filters": "^2.7.
|
|
95
|
-
"@unchainedshop/core-messaging": "^2.7.
|
|
96
|
-
"@unchainedshop/core-orders": "^2.7.
|
|
97
|
-
"@unchainedshop/core-payment": "^2.7.
|
|
98
|
-
"@unchainedshop/core-products": "^2.7.
|
|
99
|
-
"@unchainedshop/core-quotations": "^2.7.
|
|
100
|
-
"@unchainedshop/core-warehousing": "^2.7.
|
|
101
|
-
"@unchainedshop/core-worker": "^2.7.
|
|
102
|
-
"@unchainedshop/events": "^2.7.
|
|
103
|
-
"@unchainedshop/file-upload": "^2.7.
|
|
104
|
-
"@unchainedshop/logger": "^2.7.
|
|
105
|
-
"@unchainedshop/types": "^2.7.
|
|
106
|
-
"@unchainedshop/utils": "^2.7.
|
|
91
|
+
"@unchainedshop/api": "^2.7.3",
|
|
92
|
+
"@unchainedshop/core-delivery": "^2.7.3",
|
|
93
|
+
"@unchainedshop/core-enrollments": "^2.7.3",
|
|
94
|
+
"@unchainedshop/core-filters": "^2.7.3",
|
|
95
|
+
"@unchainedshop/core-messaging": "^2.7.3",
|
|
96
|
+
"@unchainedshop/core-orders": "^2.7.3",
|
|
97
|
+
"@unchainedshop/core-payment": "^2.7.3",
|
|
98
|
+
"@unchainedshop/core-products": "^2.7.3",
|
|
99
|
+
"@unchainedshop/core-quotations": "^2.7.3",
|
|
100
|
+
"@unchainedshop/core-warehousing": "^2.7.3",
|
|
101
|
+
"@unchainedshop/core-worker": "^2.7.3",
|
|
102
|
+
"@unchainedshop/events": "^2.7.3",
|
|
103
|
+
"@unchainedshop/file-upload": "^2.7.3",
|
|
104
|
+
"@unchainedshop/logger": "^2.7.3",
|
|
105
|
+
"@unchainedshop/types": "^2.7.3",
|
|
106
|
+
"@unchainedshop/utils": "^2.7.3",
|
|
107
107
|
"bluebird": "^3.7.2",
|
|
108
108
|
"event-iterator": "^2.0.0",
|
|
109
109
|
"express": "^4.18.2",
|
|
@@ -39,14 +39,12 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
39
39
|
category: OrderPricingRowCategory.Delivery,
|
|
40
40
|
useNetPrice: false,
|
|
41
41
|
}).amount;
|
|
42
|
-
|
|
43
42
|
const itemShares = orderPositions.map((orderPosition) =>
|
|
44
43
|
calcUtils.resolveRatioAndTaxDivisorForPricingSheet(
|
|
45
44
|
modules.orders.positions.pricingSheet(orderPosition, order.currency, params.context),
|
|
46
45
|
totalAmountOfItems,
|
|
47
46
|
),
|
|
48
47
|
);
|
|
49
|
-
|
|
50
48
|
const deliveryShare = calcUtils.resolveRatioAndTaxDivisorForPricingSheet(
|
|
51
49
|
orderDelivery &&
|
|
52
50
|
modules.orders.deliveries.pricingSheet(orderDelivery, order.currency, params.context),
|
|
@@ -57,14 +55,12 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
57
55
|
modules.orders.payments.pricingSheet(orderPayment, order.currency, params.context),
|
|
58
56
|
totalAmountOfPaymentAndDelivery,
|
|
59
57
|
);
|
|
60
|
-
|
|
61
58
|
let amountLeft = totalAmountOfPaymentAndDelivery + totalAmountOfItems;
|
|
62
|
-
|
|
63
59
|
params.discounts.forEach(({ configuration, discountId }) => {
|
|
64
60
|
// First, we deduce the discount from the items
|
|
65
61
|
const leftInDiscountToSplit = calcUtils.calculateAmountToSplit(
|
|
66
62
|
{ ...configuration },
|
|
67
|
-
totalAmountOfItems,
|
|
63
|
+
Math.min(totalAmountOfItems, amountLeft),
|
|
68
64
|
);
|
|
69
65
|
const [itemsDiscountAmount, itemsTaxAmount] = calcUtils.applyDiscountToMultipleShares(
|
|
70
66
|
itemShares,
|
|
@@ -72,10 +68,15 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
72
68
|
);
|
|
73
69
|
amountLeft -= itemsDiscountAmount;
|
|
74
70
|
|
|
75
|
-
//
|
|
71
|
+
// If it's a fixed rate we need to deduct the already deducted amount from the fixed rate
|
|
72
|
+
// before we hand it over to the split calculation
|
|
73
|
+
const fixedRate =
|
|
74
|
+
configuration.fixedRate > 0
|
|
75
|
+
? Math.max(0, configuration.fixedRate - itemsDiscountAmount)
|
|
76
|
+
: undefined;
|
|
76
77
|
const leftInFeesToSplit = calcUtils.calculateAmountToSplit(
|
|
77
|
-
{ ...configuration },
|
|
78
|
-
totalAmountOfPaymentAndDelivery,
|
|
78
|
+
{ ...configuration, fixedRate },
|
|
79
|
+
Math.min(totalAmountOfPaymentAndDelivery, amountLeft),
|
|
79
80
|
);
|
|
80
81
|
const [deliveryAndPaymentDiscountAmount, deliveryAndPaymentTaxAmount] =
|
|
81
82
|
calcUtils.applyDiscountToMultipleShares(
|
|
@@ -83,10 +84,8 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
83
84
|
Math.max(0, Math.min(amountLeft, leftInFeesToSplit)),
|
|
84
85
|
);
|
|
85
86
|
amountLeft -= deliveryAndPaymentDiscountAmount;
|
|
86
|
-
|
|
87
87
|
const discountAmount = (itemsDiscountAmount + deliveryAndPaymentDiscountAmount) * -1;
|
|
88
88
|
const taxAmount = (itemsTaxAmount + deliveryAndPaymentTaxAmount) * -1;
|
|
89
|
-
|
|
90
89
|
if (discountAmount) {
|
|
91
90
|
pricingAdapter.resultSheet().addDiscount({
|
|
92
91
|
amount: discountAmount,
|
|
@@ -98,7 +97,6 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
98
97
|
});
|
|
99
98
|
}
|
|
100
99
|
});
|
|
101
|
-
|
|
102
100
|
return pricingAdapter.calculate();
|
|
103
101
|
},
|
|
104
102
|
};
|