Jump to content
thirty bees forum
  • 0

Rounding issue in shopping cart


Question

Posted

I can't seem to get rounding correct in the cart, very frustrating. As you can see in my screen shot my first line item should = $81.54 ($27.18 x 3) and then the 2 lines together should = $99.53. I can't and do not want to round in this way. The round should not go past 2 decimal places. This would be not different than buying clothing in a brick-and-mortar retail store, they would not round in this way. I have tried 4 decimal places in preferences-->General as well as every option under 'Round mode.' I have also tried 'Round on each item' and 'Round on each line'. 0_1531856792572_shopping cart rounding issue.PNG0_1531856893547_current setting for rounding.PNG

12 answers to this question

Recommended Posts

  • 0
Posted

Admin note: it looks like you tried to post three times, landing in the moderation queue each time. I'll remove the other two postings. If one of them has something which is missing here, please add it here as well.

  • 0
Posted

27.18 x 3 = 81.54 81.54 + 17.98 = 99.52

Looks like rounding is right, just the total of the first line displays one cent too high. It displays $81.55, while it calculates with $81.54.

I've recorded a Github issue to not forget this: https://github.com/thirtybees/thirtybees/issues/553

  • 0
Posted

This is caused by the CartCore class' getProducts. There is a switch-case over Configuration::get('PS_ROUND_TYPE') which in the default case calls the Tools::ps_round function. The second parameter is _TBPRICEDATABASEPRECISION_ which is in the config set to 6 on default installation. It should use _PSPRICEDISPLAYPRECISION_ or _PSPRICECOMPUTE_PRECISION_ which are both set from (int) Configuration::get('PS_PRICE_DISPLAY_PRECISION').

Until there is a fix, you could use an override for the CartCore class which puts _PSPRICECOMPUTEPRECISION_ instead of _TBPRICEDATABASEPRECISION_ in that spot. Not pretty, but at least it'll work.

  • 0
Posted

I just modified /config/settings.inc and add this line at the bottom for a quick fix :

define('TBPRICEDATABASEPRECISION_','2');

2 decimals is what i needed, that fixed a lot of problems on cart amounts.

  • 0
Posted (edited)

Ahm I tested the define statement but this didn't help me at all, probably also because the define variable is just written wrong. Who knows how it might be?

_TBPRICEDATABASEPRECISION_ย  OR even _TB_PRICE_DATABASE_PRECISION_ ?? I tried it all.

I have a product in my cart which is 19.50 Euro. I have it twice so the total price of this line should be 39, but instead it's 39.10.ย  I don't know why the rounding is being done again on the total when you already have it calculating/showing the unit price. Why not take the unit price and calculate the total from there? This way you won't have to deal with any more decimals that could negatively lead to a wrong total and you get what everyone would actually expect. Wouldn't this make sense for all currencies (didnt think this through for crypto, but I don't need to as there's no module yet for bitcoins)? What do I have to do to get this rounding correct? We round to 0.10. So 0.95 is going to be 1 and 0.94 is going to be 0.90. This works for all products perfectly, but as soon as I add more than one of the same product I have wrong totals displayed in checkout for each line and of course the total in the end as well.

I tried to transfer my own rounding code from an old prestashop and it worked in the front end (i finally had the correct line totals), but when editing a product the price tab stays empty and the products edit page can never be fully loaded... Maybe someone who knows the TB code better can help me at least to get this code to work:

classes/tools.php - function ps_round()

in switch statement I added the following case on top:

case PS_ROUND_CHF_10CTS:
	return round(10 * $value) / 10;

js/tools.js - function ps_round()

after else if (method===2) I added:

else if (method == 6)
{
  tmp_value = Math.round(10 * value) / 10;
  return tmp_value;
}

config/defines.inc.php - line 181:

define('PS_ROUND_CHF_10CTS', 6);

controllers/admin/AdminPreferencesController.php - __construct():

added following array values into $roundMode:

[
  'value' => PS_ROUND_CHF_10CTS,
  'name' => $this->l('Round to nearest 10cts')
],

Thanks for clarification and help on this ๐Ÿ™‚

And btw: the amount of decimals to display that can be defined in admin isn't doing anything. I can set it to 1, i can set it to 3, but the amount of decimals is always 2. Doesn't also seem to have no impact on the rounding. I'm still on 1.0.8. I have deleted all prestashop modules and replaced them with thirty bees ones. The shop should be clean, without overrides that would have an impact.

All the best,

Oli

Edited by oliiiix
  • 0
Posted

@oliiiix Have you tried to set your rounding rule to "per article" instead of "per line"? If it is set to per line, it will round each position after adding the amounts per article, that is useful for shops selling, for example, ropes in feet or something. If you only set articles by piece instead of per foot or per lbs, then you should set the rounding rule to "per article".

  • Like 1
  • 0
Posted (edited)

That's great! Thanks a lot, I'll try that tomorrow. Didn't upgrade because of our own tools that are also retrieving stuff from the TB database ๐Ÿ˜‰ But if the changes are not that big, I'll certainly be able to upgrade without problems! Thanks for this information ๐Ÿ™‚

EDIT: Today morning I got the update to work and the price rounding issue is gone! Thanks a lot!!!

Edited by oliiiix
  • 0
Posted

Hallo Markus

Thanks a lot! I did that, but was using 1.0.8 as said by Petr from Datakick the problem was fixed by making the upgrad to 1.1.0.
But as I mentioned in my previous post, the amount of displayed numbers is always two, no matter what I'm setting the decimal amount to. It's already set to 1, but still displays two decimals (which I like). I'm pretty sure I have no code in place at all that would do that... But if this works for you then it's probably my shop even though since TB I trust my shop again completely ๐Ÿ˜‰

Thanks so much! Guess I'm also going to support ThirtyBees very soon with a small amount, I'm already thinking about transferring all our prestashops to thirty bees as TB is just a blessing after prestashop ๐Ÿ˜‰

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
ร—
ร—
  • Create New...