• Resolved Thomas Endersen

    (@thehinesgaphideaway)


    Seems that latest changes are now causing a DivByZero Error, and thus disrupting checkout.

    Fatal Error: Uncaught DivisionByZeroError: Division by zero in /home/site/public_html/wp-content/plugins/wholesalex/includes/menu/class-wholesalex-dynamic-rules.php:6658

    This:

    $get_discount = abs($sale_price - $regular_price) / $regular_price;

    $regular_price returns 0 on “free” custom products, so Does div by zero error happens. Code should check if $regular_price is 0 and use the value 1. This is a critical error on our site because we have custom products at 0 regular price. For now, because it disrupts our checkout, I have corrected this to:

    $get_discount = $regular_price == 0 ? 1 : abs($sale_price - $regular_price) / $regular_price;

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi there,

    Thanks for bring this to our attention.

    We are going to release a new update today addressing this issue.

    Thread Starter Thomas Endersen

    (@thehinesgaphideaway)

    Cool, thanks!

    Owadud

    (@owadud655)

    Hi there,

    We’ve released a new update fixing this. Kindly update the plugin.

    Thread Starter Thomas Endersen

    (@thehinesgaphideaway)

    Beautiful! Thank you! Confirmed fixed.

    Thread Starter Thomas Endersen

    (@thehinesgaphideaway)

    Hello,

    This bug has been re-introduced with the latest update. Div by zero is now due strict comparison which does not take into account the fact that $regular_price holds a float:

    $regular_price = floatval(get_post_meta($id, '_regular_price', true)) + $woo_custom_price;

    This (BUG):

    $regular_price = 0 === $regular_price ? 1 : $regular_price;

    Will return 0 because $regular_price is (float) type, and strict comparison is checking 0 (int) against it. So, then (Crash):

    $get_discount = abs($sale_price - $regular_price) / $regular_price;

    Div by Zero.

    I’ve fixed it on my end because it causes a crash.

    Thats sad to know. This will be fixed in our upcoming update. Good to know that you have fixed on your end. Thanks for your cooperation

    Thread Starter Thomas Endersen

    (@thehinesgaphideaway)

    Awesome, thank you!

    BTW, my original suggestion used loose equality on 0 ($regular_price == 0) which does type coercion, this solution would work on 0 (int) and 0 (float). However, using strict equality on 0 ($regular_price === 0) does not perform type coercion which results in the error (0 (int) is not 0 (float)).

    As a suggestion, I believe the developer can use empty() instead of loose or strict equality, such that $regular_price = empty($regular_price) ? 1 : $regular_price; Will handle 0 (int), 0 (float), “”, null and false…which is more robust.

    But, considering we are always dealing with numbers (prices), empty would be doing too much. The fix that is currently live on our site simply replaces === with ==.

    Thread Starter Thomas Endersen

    (@thehinesgaphideaway)

    Hello, marking this resolved for now in version 2.0.5

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.