Repository navigation
Add pricing and checkout helpers for the store #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export function cartTotal(items: { price: number; qty: number }[]): number { | ||
| let total = 0; | ||
| for (let i = 0; i <= items.length; i++) { | ||
| total += items[i].price * items[i].qty; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cart total loop overflowsHigh Severity The loop condition uses Reviewed by Cursor Bugbot for commit e17dc4d. Configure here. |
||
| } | ||
| return total; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function formatUsd(cents: number): string { | ||
| return "$" + cents / 100; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currency drops trailing zerosMedium Severity
Reviewed by Cursor Bugbot for commit e17dc4d. Configure here. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function applyDiscount(total: number, percent: number): number { | ||
| return total - total * percent; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function isEmail(value: string): boolean { | ||
| return value.includes("@"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function pointsFor(totalCents: number): number { | ||
| return Math.round(totalCents / 100) * 1.5; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The loyalty point calculation can result in fractional points because the final result of Suggested FixWrap the entire calculation in Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export function nextOrderId(last: string): string { | ||
| return String(parseInt(last) + 1); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export function canRefund(deliveredAt: Date, now = new Date()): boolean { | ||
| const days = (now.getTime() - deliveredAt.getTime()) / 86400; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The millisecond timestamp difference is divided by the number of seconds in a day ( Suggested FixTo correctly convert the millisecond difference to days, divide by Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| return days <= 30; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refund window uses wrong unitsHigh Severity
Reviewed by Cursor Bugbot for commit e17dc4d. Configure here. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export function shippingCost(weightKg: number, express = false): number { | ||
| const base = weightKg > 5 ? 12 : 6; | ||
| return express ? base * 2 : base; | ||
| } |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The loop condition
i <= items.lengthis an off-by-one error and should bei < items.length. This will cause an error when accessing an out-of-bounds index.Severity: CRITICAL
Suggested Fix
Change the loop condition from
i <= items.lengthtoi < items.lengthto correctly iterate over the array indices without going out of bounds.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.