I can see the product with different options
Some checks failed
CI / Check Style (push) Has been cancelled
CI / Run Clippy (push) Has been cancelled
CI / Run Tests (push) Has been cancelled

This commit is contained in:
Priec
2026-06-22 16:14:04 +02:00
parent 3f798432a0
commit 3a1ea7cdb4
5 changed files with 34 additions and 37 deletions

View File

@@ -104,13 +104,12 @@ struct VariantInput {
sku: Option<String>,
stock: i32,
price_cents: i64,
sale_cents: Option<i64>,
business_sale_cents: Option<i64>,
position: i32,
}
/// An optional price field on a variant row (sale / business sale): blank means
/// "no quick-sale", a value must parse and be below the regular price.
/// The optional business-sale price field on a variant row: blank means "no
/// business quick-sale", a value must parse and be below the regular price.
fn parse_optional_sale(
form: &MultipartForm,
i: usize,
@@ -161,8 +160,7 @@ fn parse_variants(form: &MultipartForm) -> Result<Vec<VariantInput>> {
.text(&format!("variants[{i}][stock]"))
.and_then(|s| s.parse::<i32>().ok())
.filter(|n| *n >= 0)
.unwrap_or(0);
let sale_cents = parse_optional_sale(form, i, "sale", price_cents)?;
.ok_or_else(|| Error::BadRequest("each option needs a stock quantity".to_string()))?;
let business_sale_cents = parse_optional_sale(form, i, "business_sale", price_cents)?;
let id = form
.text(&format!("variants[{i}][id]"))
@@ -174,7 +172,6 @@ fn parse_variants(form: &MultipartForm) -> Result<Vec<VariantInput>> {
sku,
stock,
price_cents,
sale_cents,
business_sale_cents,
position: out.len() as i32,
});
@@ -193,7 +190,8 @@ fn apply_variant(active: &mut product_variants::ActiveModel, input: &VariantInpu
active.sku = Set(input.sku.clone());
active.stock = Set(input.stock);
active.price_cents = Set(input.price_cents);
active.sale_price_cents = Set(input.sale_cents);
// The per-variant public sale price was removed from the UI; keep it cleared.
active.sale_price_cents = Set(None);
active.business_sale_price_cents = Set(input.business_sale_cents);
active.position = Set(input.position);
}
@@ -252,7 +250,6 @@ fn variant_form_json(variant: &product_variants::Model) -> serde_json::Value {
"sku": variant.sku,
"stock": variant.stock,
"price": format_price(variant.price_cents),
"sale": variant.sale_price_cents.map(format_price),
"business_sale": variant.business_sale_price_cents.map(format_price),
})
}