divide by zero in OrderTotalCalculationService UpdateOrderTotals

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
1. nopCommerce version
3.80  (also checked in 4.00 and did not see any code preventing divide by zero in this case)

2. Expected behavior
be able to update product qty from admin backend.

3. Actual behavior
system crashings with divide by zero error

4. Steps to reproduce the problem
Make sure AutoUpdateOrderTotalsOnEditingOrder = true

Create an order and add 1 product (regular product that has a cost e.g 10$ item). Also add another product that does not have a cost (e.g 0$)

Once order is placed, if admin goes to edit qty on an order item on that order, the code will error out when trying to calculate the taxRate since its dividng by itemSubTotalExclTax which is zero.

5. Any private modifications you made to your nopCommerce

I overrode IOrderTotalCalculationService and just checked if itemSubTotalExclTax > 0 before dividing.

if (itemSubTotalExclTax > 0
      taxRate = Math.Round((100 * (itemSubTotalInclTax - itemSubTotalExclTax)) / itemSubTotalExclTax, 3);
5 years ago
Done. Please see these commit.
https://github.com/nopSolutions/nopCommerce/commit/afce7e1db94b332f0ab70f0a99e23977317853cb
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.