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

When period used as thousands separator, the total is wrong and minimum amount alert triggers #1849

Closed
mathetos opened this issue Jul 11, 2017 · 5 comments
Assignees
Milestone

Comments

@mathetos
Copy link
Member

mathetos commented Jul 11, 2017

Issue Overview

When period used as thousands separator, the total is wrong and minimum amount alert triggers

Current Behavior

Some countries use a period as the thousands separator. Currently, when that is set it makes the total amount incorrect and triggers the minimum donation alert falsely.

Expected Behavior

Periods should be supported as thousands separators correctly.

Steps to Reproduce (for bugs)

  1. Go to "Donations > Settings > General > Currency" and set the thousands separator to a period (.). The decimal seperator and the number of decimals won't matter.
  2. On your form, set a minimum $20 donation.
  3. Test a donation by donating over $1,000 (in order to trigger a thousand separator). The totla will be reflected as $1 instead of $1,000. You should then see a message like this:
    image

Customers reporting this issue:

@ravinderk ravinderk added the bug label Jul 11, 2017
@ravinderk ravinderk added this to the 1.8.12 milestone Jul 11, 2017
@DevinWalker DevinWalker assigned DevinWalker and unassigned mehul0810 Jul 11, 2017
@DevinWalker DevinWalker modified the milestones: 1.8.11, 1.8.12 Jul 11, 2017
@DevinWalker DevinWalker assigned ravinderk and unassigned DevinWalker Jul 11, 2017
@DevinWalker
Copy link
Member

It looks like give_sanitize_amount() is not properly sanitizing when the donation amount is more than $1000 and decimals are used for the thousands separator.

@mathetos
Copy link
Member Author

As a reference, here's a list of currencies and their formatting:

http://www.thefinancials.com/Default.aspx?SubSectionID=curformat

@DevinWalker DevinWalker modified the milestones: 1.8.11, 1.8.12 Jul 11, 2017
@ravinderk
Copy link
Collaborator

@DevinWalker @mathetos @kevinwhoffman @mehul0810 Currently we are using number_format function for formatting number. It does not respect currency, that reason behind we do not have correct number formatting for INR currency. Same thing happens in Woocommerce (check screenshot).

screen shot 2017-07-12 at 12 28 12 pm

Check Indian number system

We currently have the options in core settings to set decimal, thousand separator, number of decimal for number formatting. I think it will be useful if number formatting becomes currency aware.

I found a library which does it. Let me know what do you guys think about this.
https://github.com/gerardojbaez/money

@ravinderk
Copy link
Collaborator

ravinderk commented Jul 12, 2017

@DevinWalker @mathetos @kevinwhoffman @mehul0810 I reviewed my solution and I think we do not need this. I can achieve this just by simple code because except India most of the country has similar number system means only separators changes but logic remain same.

@ravinderk
Copy link
Collaborator

ravinderk commented Jul 13, 2017

@mathetos @DevinWalker This problem is a little bit complicated.

Problem
As @mathetos said some countries have decimal separator as thousand separators, we can fix this, but then the problem started occurring with database values because we are storing already sanitized values in the database.
for example, if we store 1 with 3 decimal precision then 1.000 will store in the database. If we format this value then it's value will become 1000.
The reason behind this is we are imposing sanitization to each value even for database value which is already sanitized.
for ref:
https://github.com/WordImpress/Give/blob/master/includes/formatting.php#L145
https://github.com/WordImpress/Give/blob/master/includes/formatting.php#L210

Solution
To solve this problem we can take out give_sanitize_amount function from amount formatting function and let start use them where they need. We can handle this change in core but this will also affect all add-ons, but it will help us to solve future problems. Instead of removing give_sanitize_amount function we can add the third param to formatting function $is_sanitize by default it is set to true and we only need to set it to false for already sanitizing value like database value. We have to cross check addons in this condition also but this will save us from updating lots of code and I think it is smart way also.
And I also want to suggest you store 6 decimal precision value in the database, it should not depend upon decimal precision setting.

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

No branches or pull requests

4 participants