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

Ensure values are floats before doing calculations #8183 #8184

Merged
merged 3 commits into from
Nov 6, 2020

Conversation

ashleyfae
Copy link
Contributor

@ashleyfae ashleyfae commented Nov 3, 2020

Fixes #8183

Proposed Changes:

  1. Convert values to floats before doing calculations.

Note: For ease of testing, I'm doing this PR in two parts. This first part only fixes the calculations. This is to ensure you can still save a non-numeric discount for testing purposes. After this has been tested, I'll follow up with sanitizing amounts before saving.

To test:

  1. Create a new discount code. Type = percentage; amount = 50b. (Or any random letter thrown in.) Save.
  2. After saving, it will appear in the UI as just 50, but in the database it's actually saved as 50b.
  3. Add an item to your cart, proceed to checkout, and apply this discount code.
  4. Ensure you don't get any PHP notices.
  5. Ensure discount amount is correctly displayed on checkout.

Copy link
Contributor

@robincornett robincornett left a comment

Choose a reason for hiding this comment

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

Confirmed that an improperly formatted discount amount is saved to the database, but the calculation on checkout matches what the discount appears to be.

Copy link
Contributor

@spencerfinnell spencerfinnell left a comment

Choose a reason for hiding this comment

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

Confirmed a percentage discount saves as 50b but still applies 50% off at Checkout.

Copy link
Contributor

@LisaCee LisaCee left a comment

Choose a reason for hiding this comment

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

I'm not sure what table the discounts live in, but I was able to create a non-numeric discount code and use it with no PHP errors.

Validate discount amount is numeric before saving #8183
@ashleyfae ashleyfae merged commit 5978e87 into release/2.10 Nov 6, 2020
@ashleyfae ashleyfae deleted the issue/8183 branch November 6, 2020 12:57
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.

Possible to save non-numeric discounts which results in "A non well formed numeric value encountered" notices
4 participants