This commit is contained in:
Priec
2026-06-25 12:12:50 +02:00
parent d3d1c0d157
commit f51875d5f4
14 changed files with 225 additions and 17 deletions

View File

@@ -22,6 +22,14 @@ pub fn product_card(
category_name: Option<String>,
cur: &Currency,
) -> Value {
// Whole-percent discount for the card's sale badge (e.g. "15 %"). Only
// meaningful when the resolved price is actually reduced below the regular.
let percent_off = if priced.is_reduced() && priced.regular_cents > priced.price_cents {
(((priced.regular_cents - priced.price_cents) as f64 / priced.regular_cents as f64) * 100.0)
.round() as i64
} else {
0
};
json!({
"id": product.id,
"variant_id": representative.id,
@@ -31,6 +39,7 @@ pub fn product_card(
"short_description": product.short_description,
"price": cur.format(priced.price_cents),
"on_sale": priced.is_reduced(),
"percent_off": percent_off,
"is_business": priced.is_business,
"regular_price": cur.format(priced.regular_cents),
"sku": representative.sku,