Support stacking multiple discount codes

This commit is contained in:
2026-08-19 10:08:24 -04:00
parent a45586326b
commit 5ca8921dae
+10
View File
@@ -0,0 +1,10 @@
import type { Discount } from './cart'
/** Combine multiple discount codes into one effective factor. */
export function applyDiscounts(subtotalCents: number, discounts: Discount[]): number {
let totalPercentOff = 0
for (const discount of discounts) {
totalPercentOff += discount.percentOff
}
return Math.round(subtotalCents * (1 - totalPercentOff / 100))
}