Skip to content
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

Fix an issue where the AmountOff percentage is cast to an int, even t… #2004

Merged

Conversation

tvlokven
Copy link
Contributor

@tvlokven tvlokven commented Oct 25, 2024

The admin panel allows you to enter a decimal value when creating an AmountOff Discount with a percentage discount. However, it gets cast to an int in the AmountOff class, which results in the percentage being rounded and the discount amount being slightly off.

You could argue that usually percentage discounts are given as whole numbers, but since the admin panel already supports decimal values, I think this should be changed.

Fixes #2003

Copy link

vercel bot commented Oct 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 9:36am

@alecritson
Copy link
Collaborator

Thanks @tvlokven I think this is valid, although I'm curious why you overrode the 10% discount test instead of adding to it? Maybe this is a good use case for Pest datasets? https://pestphp.com/docs/datasets

…a test for 10.25% since this is an interesting case where some rounding happens.
@tvlokven
Copy link
Contributor Author

@alecritson thanks for having a look. I thought that having both a test for 10.5% and 10% would be redundant, I didn't want to copy-paste the entire test with some different values. Your suggestion of using a Pest dataset sounds like a good idea, I've added a new commit where I did this. I was struggling a little bit with how best to pass the parameters to the test (using arrays, making quantities dynamic maybe instead of hardcoding 1 and 2, etc). But in the end I stuck with the easiest approach, which I thought was the most clear.

@alecritson alecritson merged commit 0b2d76e into lunarphp:1.x Nov 5, 2024
22 checks passed
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.

AmountOff percentage is cast to an int, even though it could contain a decimal value
3 participants