By Markus “Traumflug” Hitter
One might think that displaying and calculating prices is of stellar importance for e-commerce. Selling goods is all about finding the right price for the customer, displaying it nicely next to the product and adding it up correctly for the cart an the invoice, after all. And then a bug report came in which made me scratch my head a bit. A matured e-commerce software like thirty bees, but rounding in the cart was plain wrong. Total of the product didn’t even match the cart total.
Long story short, this report triggered an audit of all the price rounding done throughout the code. Result is not only rounding fixed, but all the nice features around price display, like displaying 3 or 4 digits after the decimal, like displaying prices without any decimals, actually working. Let’s see what we have, and feel invited to try this in other e-commerce solutions.
Rounding per item
- Go to Back office -> Preferences -> General, set Round mode to “Round up away from zero” and Round type to “Round on each item”.
- In the same place, set Number of decimals to 2.
- Edit a product to have a pre-tax retail price of 9.55 and apply a tax rule with 22%.
- Go to Customers -> Groups and give group Visitor a general discount of 5%
- Visit the shop as a customer and add 24 items of said product to the cart.
- View the cart.
One should see this:
No surprise? That’s correct, after all. Well, earlier one might well have seen this.
Here’s another experiment. The graphics below is a compilation of cropped screenshots.
- Number of decimals can be found in back office -> Preferences -> General.
- Decimals can be found in back office -> Localization -> Currency, then clicking on of a currency. Which means, it’s a per-currency setting and can vary between currencies.
- Right column are screenshots from front office.
Again, while such an outcome should be a matter of course, this wasn’t always the case. Take the liberty to try with your current installation, or with PrestaShop.
Price display in back office
Price display in back office was audited as well. Some fields were always cropped to two digits after the decimal, others always to 6 digits, having a lot of trailing zeros.
New strategy is to show at least the configured number of digits, but to allow more. As this series of cropped screenshots shows:
Number of decimals was set to 2, then prices of 10, 10.1, 10.12, 10.123 … 10.123456, 10.1234567 were inserted. As one can see, exceeding the maximum number of 6 digits after the decimal gets rounded.
Happy trading with thirty bees, now with precise prices!