@managesome/eposmatic-toolkit 0.2.373 → 0.2.374
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.
|
@@ -2032,10 +2032,34 @@ function getSyncedOrderDiscountDetailsWithCaps({ orderDiscountDetails, appliedCu
|
|
|
2032
2032
|
}
|
|
2033
2033
|
const discountValue = matchedOrderDiscount.value[platform] ?? matchedOrderDiscount.value.BASE_PRICE;
|
|
2034
2034
|
let recalculatedDiscount;
|
|
2035
|
+
let isSpecialDiscountPercentage = matchedOrderDiscount.is_percentage;
|
|
2035
2036
|
if (matchedOrderDiscount.is_percentage) {
|
|
2036
|
-
//
|
|
2037
|
-
|
|
2038
|
-
|
|
2037
|
+
// Clamp percentage to 100% to match apply-time logic in CustomDiscountItem.tsx
|
|
2038
|
+
let discountPercentage = discountValue;
|
|
2039
|
+
if (discountPercentage > 100)
|
|
2040
|
+
discountPercentage = 100;
|
|
2041
|
+
const maxAmount = matchedOrderDiscount.max_amount
|
|
2042
|
+
? (matchedOrderDiscount.max_amount[platform] ?? matchedOrderDiscount.max_amount.BASE_PRICE)
|
|
2043
|
+
: null;
|
|
2044
|
+
const hasCap = maxAmount != null && Number.isFinite(maxAmount) && maxAmount > 0;
|
|
2045
|
+
if (hasCap) {
|
|
2046
|
+
const computedDiscount = (discountPercentage / 100) * currentSubtotal;
|
|
2047
|
+
if (computedDiscount > maxAmount && maxAmount <= currentSubtotal) {
|
|
2048
|
+
// Cap exceeded — store as fixed amount equal to the cap
|
|
2049
|
+
recalculatedDiscount = maxAmount;
|
|
2050
|
+
isSpecialDiscountPercentage = false;
|
|
2051
|
+
}
|
|
2052
|
+
else {
|
|
2053
|
+
// Within cap — keep as percentage
|
|
2054
|
+
recalculatedDiscount = discountPercentage;
|
|
2055
|
+
isSpecialDiscountPercentage = true;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
else {
|
|
2059
|
+
// No cap configured — keep as percentage
|
|
2060
|
+
recalculatedDiscount = discountPercentage;
|
|
2061
|
+
isSpecialDiscountPercentage = true;
|
|
2062
|
+
}
|
|
2039
2063
|
}
|
|
2040
2064
|
else {
|
|
2041
2065
|
// Fixed discount — amount stays as-is, but still subject to max_amount cap
|
|
@@ -2053,7 +2077,7 @@ function getSyncedOrderDiscountDetailsWithCaps({ orderDiscountDetails, appliedCu
|
|
|
2053
2077
|
return {
|
|
2054
2078
|
...orderDiscountDetails,
|
|
2055
2079
|
special_discount: (0, utils_1.parseNum)(recalculatedDiscount),
|
|
2056
|
-
is_special_discount_percentage:
|
|
2080
|
+
is_special_discount_percentage: isSpecialDiscountPercentage,
|
|
2057
2081
|
total_discount: 0,
|
|
2058
2082
|
};
|
|
2059
2083
|
}
|
|
@@ -2087,10 +2111,34 @@ function getUpdateItemInCartData(data, payload, courses, listnerSettings, applie
|
|
|
2087
2111
|
const platform = data.platform;
|
|
2088
2112
|
const discountValue = matchedDiscount.value[platform] ?? matchedDiscount.value.BASE_PRICE;
|
|
2089
2113
|
let recalculatedSpecialDiscount;
|
|
2114
|
+
let isItemDiscountPercentage = matchedDiscount.is_percentage;
|
|
2090
2115
|
if (matchedDiscount.is_percentage) {
|
|
2091
|
-
//
|
|
2092
|
-
|
|
2093
|
-
|
|
2116
|
+
// Clamp percentage to 100% to match apply-time logic in CustomDiscountItem.tsx
|
|
2117
|
+
let discountPercentage = discountValue;
|
|
2118
|
+
if (discountPercentage > 100)
|
|
2119
|
+
discountPercentage = 100;
|
|
2120
|
+
const maxAmount = matchedDiscount.max_amount
|
|
2121
|
+
? (matchedDiscount.max_amount[platform] ?? matchedDiscount.max_amount.BASE_PRICE)
|
|
2122
|
+
: null;
|
|
2123
|
+
const hasCap = maxAmount != null && Number.isFinite(maxAmount) && maxAmount > 0;
|
|
2124
|
+
if (hasCap) {
|
|
2125
|
+
const computedDiscount = (discountPercentage / 100) * itemTotalWithoutTax;
|
|
2126
|
+
if (computedDiscount > maxAmount && maxAmount <= itemTotalWithoutTax) {
|
|
2127
|
+
// Cap exceeded — store as fixed amount equal to the cap
|
|
2128
|
+
recalculatedSpecialDiscount = maxAmount;
|
|
2129
|
+
isItemDiscountPercentage = false;
|
|
2130
|
+
}
|
|
2131
|
+
else {
|
|
2132
|
+
// Within cap — keep as percentage
|
|
2133
|
+
recalculatedSpecialDiscount = discountPercentage;
|
|
2134
|
+
isItemDiscountPercentage = true;
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
else {
|
|
2138
|
+
// No cap configured — keep as percentage
|
|
2139
|
+
recalculatedSpecialDiscount = discountPercentage;
|
|
2140
|
+
isItemDiscountPercentage = true;
|
|
2141
|
+
}
|
|
2094
2142
|
}
|
|
2095
2143
|
else {
|
|
2096
2144
|
// Fixed discount — the amount should NOT scale with quantity.
|
|
@@ -2110,7 +2158,7 @@ function getUpdateItemInCartData(data, payload, courses, listnerSettings, applie
|
|
|
2110
2158
|
item_discount_details: {
|
|
2111
2159
|
...newItem.item_discount_details,
|
|
2112
2160
|
special_discount: (0, utils_1.parseNum)(recalculatedSpecialDiscount),
|
|
2113
|
-
is_special_discount_percentage:
|
|
2161
|
+
is_special_discount_percentage: isItemDiscountPercentage,
|
|
2114
2162
|
total_discount: 0,
|
|
2115
2163
|
},
|
|
2116
2164
|
};
|