Prices displayed in email order and order history might have a one unit difference from products prices in shop
Describe the bug On some orders, product prices, subtotal and total might be different from actual prices in shop at order time due to each product 'final_price' saved rounded in database.
Version Zen Cart version: 1.5.8a
To Reproduce Steps to reproduce/demonstrate the behavior:
- In shop using currencies with no decimal but products prices saved with decimals, place an order (better with quantity > 1).
- Check prices in order email and in admin order page.
- Compare with checkout page and/or product page. Prices have +/- 1 currency unit differences.
See zencart forum discussion for more details: https://www.zen-cart.com/showthread.php?229752-Different-Total-Displayed
The fix is simple, just saving 'final_price' (product price after discount and other) in database not rounded. But before doing a PR, I would like to know if somebody knows why this value is saved rounded? Using this rounded value and multiplying by quantity or adding tax just multiply the error from rounding. I did some test with both displaying price including tax or without tax.
@piloujp, I've been working on this and (unfortunately) it's not as simple as you describe. The underlying issue has to do with pricing calculations that need to be different when a store uses "prices including taxes" and a store that doesn't.
Do you, by any chance, use any attribute-related pricing on your site? I'm guessing that those calculations need to be different as well.
@lat9 I checked with product that has attributes pricing and there was no difference (display tax or not and fixed or not fixed code cases). It is expected has 'final_price' rounding is done after applying discount or attribute prices. I can not find any other problems whether option to display tax is on or off. When you say that 'pricing calculations'... 'need to be different when a store uses "prices including taxes" and a store that doesn't', is it not because you plan to do 'wholesaler' usable cart that can do invoices without tax? In this case lots of things need to be re-written. But the actual option to disable displaying prices with tax seems to work as intended. Tax is just added at the end and final total price includes tax correctly.
@piloujp, I'll go ahead and push my current changes up as a draft PR so that you can see the calculation differences between stores that include tax in their prices and those that don't.
For what it's worth, now that I found this conversation, I recalled that we have been using this non-rounding final-price change for years in live environment and our store has taxed product / order prices.
Though, there still have been some rounding problems on taxed attributes. Sometimes prices are shown .01 over or under the wanted price, even if you play with the 4 decimals net price. This might be related to this issue or not. Also there might be that, where 4 digits precision is just not enough in rare cases.
We have lots of customizations in Zen Cart's core files, so this info might not be so "valid".