Compare commits

..

2 Commits

Author SHA1 Message Date
DanielS
a3c5a66d3f feat: check category eligibility for update discount in frontend and backend
Some checks failed
Staging Build / build (push) Has been cancelled
2026-07-10 00:18:23 +02:00
DanielS
2038c4df3e db: add allow_update_discount column to categories table 2026-07-10 00:18:18 +02:00
3 changed files with 15 additions and 7 deletions

View File

@@ -353,16 +353,14 @@ export function OrderWizard({
})
const totalItem = base + modulesSum
if (prod.billing_interval === 'one_time') {
oneTime += totalItem
const allowDiscount = (cat as any).allow_update_discount !== false
const finalItemTotal = allowDiscount ? (totalItem * updatePriceModifier.multiplier) : totalItem
oneTime += finalItemTotal
} else {
monthly += totalItem
}
})
}
// Apply update modifier to oneTime total
if (updatePriceModifier.multiplier !== 1) {
oneTime = oneTime * updatePriceModifier.multiplier
}
return { monthlyTotal: monthly, oneTimeTotal: oneTime }
}, [selections, products, categories, moduleQuantities, updatePriceModifier])

View File

@@ -183,10 +183,14 @@ export function buildOrderSnapshot(
multiplier = 0.90
}
// Multiply only one_time item totals by multiplier
// Multiply only one_time item totals by multiplier if category allows it
items.forEach(item => {
if (item.billing_interval === 'one_time') {
item.item_total = item.item_total * multiplier
const cat = categories.find(c => c.id === item.category_id);
const allowDiscount = cat ? (cat as any).allow_update_discount !== false : true;
if (allowDiscount) {
item.item_total = item.item_total * multiplier;
}
}
})
subtotal = items.reduce((acc, item) => acc + item.item_total, 0)

View File

@@ -0,0 +1,6 @@
-- Migration: Add allow_update_discount to categories
-- Purpose: Add a boolean flag to categories to control if their products are eligible for the update discount.
ALTER TABLE public.categories ADD COLUMN IF NOT EXISTS allow_update_discount BOOLEAN DEFAULT true NOT NULL;
NOTIFY pgrst, 'reload schema';