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

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

Closed
ashleyfae opened this issue Nov 3, 2020 · 0 comments · Fixed by #8185 or #8184
Assignees
Labels
Milestone

Comments

@ashleyfae
Copy link
Contributor

Bug Report

Expected behavior

I should not be able to save a non-numeric discount code amount, such as 50b.

Actual behavior

When I create a discount code with the amount 50b, then use this discount on checkout, the following notice is logged:

[03-Nov-2020 13:11:31 UTC] PHP Notice:  A non well formed numeric value encountered in /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/class-edd-discount.php on line 1892
[03-Nov-2020 13:11:31 UTC] PHP Stack trace:
[03-Nov-2020 13:11:31 UTC] PHP   1. {main}() /var/www/edd/wp-admin/admin-ajax.php:0
[03-Nov-2020 13:11:31 UTC] PHP   2. require_once() /var/www/edd/wp-admin/admin-ajax.php:22
[03-Nov-2020 13:11:31 UTC] PHP   3. require_once() /var/www/edd/wp-load.php:37
[03-Nov-2020 13:11:31 UTC] PHP   4. require_once() /var/www/edd/wp-config.php:103
[03-Nov-2020 13:11:31 UTC] PHP   5. do_action() /var/www/edd/wp-settings.php:546
[03-Nov-2020 13:11:31 UTC] PHP   6. WP_Hook->do_action() /var/www/edd/wp-includes/plugin.php:478
[03-Nov-2020 13:11:31 UTC] PHP   7. WP_Hook->apply_filters() /var/www/edd/wp-includes/class-wp-hook.php:311
[03-Nov-2020 13:11:31 UTC] PHP   8. edd_stripe_setup_billing_address_fields() /var/www/edd/wp-includes/class-wp-hook.php:287
[03-Nov-2020 13:11:31 UTC] PHP   9. edd_get_cart_total() /var/www/edd/wp-content/plugins/edd-stripe/includes/template-functions.php:773
[03-Nov-2020 13:11:31 UTC] PHP  10. EDD_Cart->get_total() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/cart/functions.php:307
[03-Nov-2020 13:11:31 UTC] PHP  11. EDD_Cart->get_tax() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/cart/class-edd-cart.php:1121
[03-Nov-2020 13:11:31 UTC] PHP  12. EDD_Cart->get_subtotal() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/cart/class-edd-cart.php:1250
[03-Nov-2020 13:11:31 UTC] PHP  13. EDD_Cart->get_contents_details() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/cart/class-edd-cart.php:1093
[03-Nov-2020 13:11:31 UTC] PHP  14. EDD_Cart->get_item_discount_amount() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/cart/class-edd-cart.php:233
[03-Nov-2020 13:11:31 UTC] PHP  15. edd_get_discounted_amount() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/cart/class-edd-cart.php:702
[03-Nov-2020 13:11:31 UTC] PHP  16. EDD_Discount->get_discounted_amount() /var/www/edd/wp-content/plugins/easy-digital-downloads/includes/discount-functions.php:631

Steps to reproduce the behavior

  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. PHP notice is logged.

Information (if a specific version is affected):

PHP Version:

EDD Version (or branch): 2.9.x

WordPress Version:

Any other relevant information:

I have confirmed that in EDD3 you are unable to save a non-numeric discount code amount. So that part of the issue is fixed. However, we can patch this part in EDD 2.9.x, and when we do amount calculations in the EDD_Discount::get_discounted_amount() method we can cast the values to floats to avoid this notice.

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