The function commerce_order_calculate_total() does not round the amount. Since this function is called in the save workflow, it's easy to miss this. The next time the order is loaded, the total will be rounded. However, if you try to do anything with the order on the same request after saving it, you still have the unrounded total. This seems undesirable.

The attached patch modifies commerce_order_calculate_total() to round the amount, though I can't say I know whether this is the best way to deal with the issue.

CommentFileSizeAuthor
round-order-total.patch485 bytesserialjaywalker
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rszrama’s picture

Status: Active » Fixed

Hmm, I think the problem goes a little deeper here. The way the order total is calculated is by adding up price components, and we have been intentionally not rounding these components so you can have things like unrounded taxes that get added together and rounded in aggregate (i.e. for U.S. sales taxes). I wonder if we might need to introduce rounding at the price component type level.

However, for the short term, your fix will at least preserve the existing rounding behavior in components while imitating the results of the write to database (into an integer column) and subsequent load. Committing as is and will keep an eye out for any issues with the current price component rounding strategy.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.