-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Make rounding more accurate when prices are entered more than 2dp #29318
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
Conversation
fc72bd8 to
0c46b71
Compare
jonathansadowski
left a comment
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.
Tested this, and went through the tests you added / updated to make sure that they made sense to me, and everything works well. Nice job.
I added a question about the changes that remove wc_format_decimal from the WC_Cart methods that were changed. It seems like a breaking change to me. I'm not sure if we should introduce new methods without the rounding, or if perhaps that change isn't breaking in some way I'm missing at first glance.
includes/class-wc-cart.php
Outdated
| */ | ||
| public function set_subtotal( $value ) { | ||
| $this->totals['subtotal'] = wc_format_decimal( $value, wc_get_price_decimals() ); | ||
| $this->totals['subtotal'] = $value; |
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.
What would happen if somebody was relying on the wc_format_decimal behavior up until now?
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.
Nice catch. We did a similar change sometime back, and while no issues have been reported so far because of it, there could have been.
For now, I have restored the formatting changes, but have removed rounding, so it's backward compatible.
Rounding here conflicts with round at subtotal settings becase we would round at line item level irrespective of settings.
…ding upon settings.
…xes. We round up or round down depending upon if prices are entered inclusive or exclusive taxes, however since shipping and fees are always entered exclusive of taxes, they should always be rounded down.
We have special method to round taxes which may round up or round down depending upon settings. This method should be used instead of default rounding in formatting funtions.
|
@jonathansadowski sorry for the delay here, this is ready for another round. I have restored the compatibility changes but without rounding in b487e36. |
jonathansadowski
left a comment
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.
Thanks for updating this. Tests well for me. Just noting that the inclusive/exclusive setting appears to be backward in the test-plan as it's written, but I figured it out from looking at the issues you linked to. Nice work!
All Submissions:
Changes proposed in this Pull Request:
This PR introduces the following changes:
Closes #24184 #28292.
How to test the changes in this Pull Request:
I have tried to cover most things via unit tests but some example configurations to verify
From 24184 first comment
From #28292
0from WooCommerce > Settings > GeneralEdit: Updated testing instruction with correct configuration of inclusive/exclusive setting.
Other information:
Changelog entry