feat: Add quantity support for product modules, multiply prices in order snapshot and pdf
Some checks failed
Staging Build / build (push) Has been cancelled

This commit is contained in:
DanielS
2026-06-25 13:04:37 +02:00
parent fe05e13d3f
commit 9e189f331a
8 changed files with 159 additions and 66 deletions

View File

@@ -50,6 +50,7 @@ function hashOrderSnapshot(snapshot: object): string {
*/
export async function submitOrder(params: {
selections: WizardSelections
moduleQuantities?: Record<string, number>
products?: Product[]
categories?: Category[]
customerProfile: Partial<Profile>
@@ -57,7 +58,7 @@ export async function submitOrder(params: {
endCustomer?: EndCustomer | null
billingInterval?: 'one_time' | 'monthly'
}): Promise<Order> {
const { selections, customerProfile, endCustomerId, endCustomer, billingInterval } = params
const { selections, moduleQuantities, customerProfile, endCustomerId, endCustomer, billingInterval } = params
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
@@ -106,7 +107,7 @@ export async function submitOrder(params: {
// 1. Snapshots aufbauen
// Wenn Endkunde vorhanden: dessen Daten einfrieren; sonst Partner-Profil (Fallback)
const customerSnapshot = buildCustomerSnapshot(customerProfile, endCustomer ?? null)
const orderSnapshot = buildOrderSnapshot(selections, dbProducts, dbCategories, billingInterval)
const orderSnapshot = buildOrderSnapshot(selections, dbProducts, dbCategories, billingInterval, moduleQuantities)
// 2. Idempotenz-Guard: Prüfen ob identische Bestellung in den letzten 30s existiert
const orderHash = hashOrderSnapshot(orderSnapshot)

View File

@@ -89,6 +89,7 @@ export async function createProduct(
price: m.price,
requirements: m.requirements || [],
exclusions: m.exclusions || [],
has_quantity: m.has_quantity ?? false,
}))
const { error: modulesError } = await supabase
.from('product_modules')
@@ -125,6 +126,7 @@ export async function updateProduct(id: string, product: Partial<Product>, modul
price: m.price,
requirements: m.requirements || [],
exclusions: m.exclusions || [],
has_quantity: m.has_quantity ?? false,
}))
const { error: modulesError } = await supabase
.from('product_modules')