kupos-ui-components-lib 10.4.71 → 10.4.73
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.
|
@@ -107,24 +107,37 @@ function addOperatorLogo(card, service) {
|
|
|
107
107
|
{ url, name: service.operator_name || ((_f = service.operator_details) === null || _f === void 0 ? void 0 : _f[2]) },
|
|
108
108
|
];
|
|
109
109
|
}
|
|
110
|
+
// savings_percent may be missing or sent as a string; fall back to the deal's prices so
|
|
111
|
+
// Remate still sorts by its real discount instead of dropping to 0%
|
|
112
|
+
function getWowDealPercent(wowDealData) {
|
|
113
|
+
const savings = Number(wowDealData.savings_percent);
|
|
114
|
+
if (savings > 0)
|
|
115
|
+
return savings;
|
|
116
|
+
const original = Number(wowDealData.original_price);
|
|
117
|
+
const final = Number(wowDealData.final_price);
|
|
118
|
+
return original > 0 && final >= 0 && final < original
|
|
119
|
+
? ((original - final) / original) * 100
|
|
120
|
+
: 0;
|
|
121
|
+
}
|
|
110
122
|
function toDiscountLabel(discount, currencySign) {
|
|
111
123
|
if (discount.type === "fixed") {
|
|
112
124
|
return `${CommonService.currencyRounded(discount.amount, currencySign)} de dcto`;
|
|
113
125
|
}
|
|
114
126
|
return `${Math.round(discount.amount)}% de dcto`;
|
|
115
127
|
}
|
|
116
|
-
// Groups services into one card per discount category
|
|
128
|
+
// Groups services into one card per discount category, ordered from highest to lowest discount.
|
|
117
129
|
export function deriveDiscountCards(services = [], wowDealData, currencySign = "$") {
|
|
118
130
|
var _a, _b, _c, _d, _e;
|
|
119
131
|
const cards = new Map();
|
|
120
132
|
const wowServices = wowDealData === null || wowDealData === void 0 ? void 0 : wowDealData.services;
|
|
133
|
+
const wowDealPercent = wowDealData ? getWowDealPercent(wowDealData) : 0;
|
|
121
134
|
const hasWowDeal = !!wowDealData &&
|
|
122
135
|
((Array.isArray(wowServices) && wowServices.length > 0) ||
|
|
123
|
-
|
|
136
|
+
wowDealPercent > 0);
|
|
124
137
|
if (hasWowDeal) {
|
|
125
138
|
const remateDiscount = {
|
|
126
139
|
type: "percentage",
|
|
127
|
-
amount: Math.round(
|
|
140
|
+
amount: Math.round(wowDealPercent),
|
|
128
141
|
};
|
|
129
142
|
cards.set(REMATE_KEY, {
|
|
130
143
|
key: REMATE_KEY,
|
|
@@ -217,5 +230,13 @@ export function deriveDiscountCards(services = [], wowDealData, currencySign = "
|
|
|
217
230
|
return a.name.localeCompare(b.name, "es", { sensitivity: "base" });
|
|
218
231
|
});
|
|
219
232
|
}
|
|
220
|
-
|
|
233
|
+
// Highest discount first, Remate included — it takes its place by its percent rather than
|
|
234
|
+
// always leading. Percentages and fixed amounts can't be compared, so percentages lead.
|
|
235
|
+
// The sort is stable, so on a tie Remate stays ahead and the rest keep service order.
|
|
236
|
+
return Array.from(cards.values()).sort((a, b) => {
|
|
237
|
+
if (a.discountType !== b.discountType) {
|
|
238
|
+
return a.discountType === "percentage" ? -1 : 1;
|
|
239
|
+
}
|
|
240
|
+
return b.amount - a.amount;
|
|
241
|
+
});
|
|
221
242
|
}
|
package/package.json
CHANGED
|
@@ -148,6 +148,18 @@ function addOperatorLogo(
|
|
|
148
148
|
];
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
// savings_percent may be missing or sent as a string; fall back to the deal's prices so
|
|
152
|
+
// Remate still sorts by its real discount instead of dropping to 0%
|
|
153
|
+
function getWowDealPercent(wowDealData: WowDealData): number {
|
|
154
|
+
const savings = Number(wowDealData.savings_percent);
|
|
155
|
+
if (savings > 0) return savings;
|
|
156
|
+
const original = Number(wowDealData.original_price);
|
|
157
|
+
const final = Number(wowDealData.final_price);
|
|
158
|
+
return original > 0 && final >= 0 && final < original
|
|
159
|
+
? ((original - final) / original) * 100
|
|
160
|
+
: 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
151
163
|
function toDiscountLabel(
|
|
152
164
|
discount: ServiceDiscount,
|
|
153
165
|
currencySign: string,
|
|
@@ -158,7 +170,7 @@ function toDiscountLabel(
|
|
|
158
170
|
return `${Math.round(discount.amount)}% de dcto`;
|
|
159
171
|
}
|
|
160
172
|
|
|
161
|
-
// Groups services into one card per discount category
|
|
173
|
+
// Groups services into one card per discount category, ordered from highest to lowest discount.
|
|
162
174
|
export function deriveDiscountCards(
|
|
163
175
|
services: DiscountBannerServiceItem[] = [],
|
|
164
176
|
wowDealData?: WowDealData,
|
|
@@ -167,15 +179,16 @@ export function deriveDiscountCards(
|
|
|
167
179
|
const cards = new Map<string, DiscountBannerCard>();
|
|
168
180
|
|
|
169
181
|
const wowServices = wowDealData?.services;
|
|
182
|
+
const wowDealPercent = wowDealData ? getWowDealPercent(wowDealData) : 0;
|
|
170
183
|
const hasWowDeal =
|
|
171
184
|
!!wowDealData &&
|
|
172
185
|
((Array.isArray(wowServices) && wowServices.length > 0) ||
|
|
173
|
-
|
|
186
|
+
wowDealPercent > 0);
|
|
174
187
|
|
|
175
188
|
if (hasWowDeal) {
|
|
176
189
|
const remateDiscount: ServiceDiscount = {
|
|
177
190
|
type: "percentage",
|
|
178
|
-
amount: Math.round(
|
|
191
|
+
amount: Math.round(wowDealPercent),
|
|
179
192
|
};
|
|
180
193
|
cards.set(REMATE_KEY, {
|
|
181
194
|
key: REMATE_KEY,
|
|
@@ -276,5 +289,13 @@ export function deriveDiscountCards(
|
|
|
276
289
|
});
|
|
277
290
|
}
|
|
278
291
|
|
|
279
|
-
|
|
292
|
+
// Highest discount first, Remate included — it takes its place by its percent rather than
|
|
293
|
+
// always leading. Percentages and fixed amounts can't be compared, so percentages lead.
|
|
294
|
+
// The sort is stable, so on a tie Remate stays ahead and the rest keep service order.
|
|
295
|
+
return Array.from(cards.values()).sort((a, b) => {
|
|
296
|
+
if (a.discountType !== b.discountType) {
|
|
297
|
+
return a.discountType === "percentage" ? -1 : 1;
|
|
298
|
+
}
|
|
299
|
+
return b.amount - a.amount;
|
|
300
|
+
});
|
|
280
301
|
}
|