From ed75ccc2c7c2b5f9b0aa15c10feacc93075d06c8 Mon Sep 17 00:00:00 2001 From: Sergiy Dybskiy Date: Tue, 6 Oct 2026 23:19:38 -0400 Subject: [PATCH] Apply per-line discounts in the cart total Co-authored-by: Claude --- apps/pr-reviewer/fixtures/demo-pr/cart-total.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts b/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts index c694360..b6c86c1 100644 --- a/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts +++ b/apps/pr-reviewer/fixtures/demo-pr/cart-total.ts @@ -1,10 +1,13 @@ -export function cartTotal(items: { price: number; qty: number }[]): number { +export type CartItem = { price: number; qty: number; discountCents?: number }; + +export function cartTotal(items: CartItem[]): number { let total = 0; for (let i = 0; i < items.length; i++) { if (items[i].qty < 0) { throw new RangeError(`Negative quantity for item ${i}`); } - total += items[i].price * items[i].qty; + const line = items[i].price * items[i].qty; + total += line - (items[i].discountCents ?? 0); } return total; }