Skip to content

Add an order summary with discount and tax - #4

Open
marginsystems wants to merge 1 commit into
taxfrom
order-summary
Open

marginsystems wants to merge 1 commit into
taxfrom
order-summary

Conversation

@marginsystems

Copy link
Copy Markdown
Contributor

Builds on the sales tax PR: items total, discount, tax and grand total for checkout.

@mergestorm-vortex mergestorm-vortex Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vortex: 1 issue to fix at a6bdd72 · 2/2 files reviewed

Actionable comment posted: 1

  • 🟠 Important · `applyDiscount(itemsTotal, discountPercent)` returns `Math.round(amount * (100 - percent)) / 100`... · src/summary.js:6
🤖 Prompt for AI agents (1 finding)
Pull request mergestorm/sample-app#4: https://github.com/mergestorm/sample-app/pull/4 (head branch `order-summary`)

Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.

Findings to address:
1. In `@src/summary.js` (line 6, Important):
   `applyDiscount(itemsTotal, discountPercent)` returns `Math.round(amount * (100 - percent)) / 100`, which is not an integer cent value when the product is not a multiple of 100. For example, an items total of 2001 cents with a 10% discount gives `discounted` = 1800.9, and `total` becomes fractional (1980.9) as well. This happens for any cart whose total times (100 - percent) is not divisible by 100, so it is common. Since the README uses integer cents, either round to whole cents here or fix `applyDiscount` to round after dividing (`Math.round(amount * (100 - percent) / 100)`). The added test only covers a round-number case and would not catch this.

Auto land this PR in Mergestorm


Mergestorm: 30 free reviews a month

Comment thread src/summary.js

export function orderSummary(items, { discountPercent = 0, taxRatePercent = 0 } = {}) {
const itemsTotal = subtotal(items);
const discounted = applyDiscount(itemsTotal, discountPercent);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Important

applyDiscount(itemsTotal, discountPercent) returns Math.round(amount * (100 - percent)) / 100...

applyDiscount(itemsTotal, discountPercent) returns Math.round(amount * (100 - percent)) / 100, which is not an integer cent value when the product is not a multiple of 100. For example, an items total of 2001 cents with a 10% discount gives discounted = 1800.9, and total becomes fractional (1980.9) as well. This happens for any cart whose total times (100 - percent) is not divisible by 100, so it is common. Since the README uses integer cents, either round to whole cents here or fix applyDiscount to round after dividing (Math.round(amount * (100 - percent) / 100)). The added test only covers a round-number case and would not catch this.

🤖 Prompt for AI agents
Pull request mergestorm/sample-app#4: https://github.com/mergestorm/sample-app/pull/4 (head branch `order-summary`)

Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.

In `@src/summary.js` (line 6, Important):
`applyDiscount(itemsTotal, discountPercent)` returns `Math.round(amount * (100 - percent)) / 100`, which is not an integer cent value when the product is not a multiple of 100. For example, an items total of 2001 cents with a 10% discount gives `discounted` = 1800.9, and `total` becomes fractional (1980.9) as well. This happens for any cart whose total times (100 - percent) is not divisible by 100, so it is common. Since the README uses integer cents, either round to whole cents here or fix `applyDiscount` to round after dividing (`Math.round(amount * (100 - percent) / 100)`). The added test only covers a round-number case and would not catch this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant