new ui4
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user