Jump to content

[solved] Incorrect rounding on product page for Switzerland


Recommended Posts

I have a Swiss store and have added the code below to round all percentage discounted sale prices to the nearest 5 centimes (there are no 1,2,3 or 4 centimes in Switzerland).  This seems to be working fine throughout the store apart from on the product page where the price is being shown to the nearest single centime.

 

I have looked at the product.tpl, but haven't been able to work out how to change the code to correct for this.  Any suggestions greatly appreciated.  Thanks!

 

See: http://www.teddyandflu.ch/boys/20-robot-t-shirt.html as an example of the rounding discrepancy.

	public static function ps_round($value, $precision = 0)
	{
		static $method = null;

		if ($method == null)
			$method = (int)Configuration::get('PS_PRICE_ROUND_MODE');

		if ($method == PS_ROUND_UP)
			return Tools::ceilf($value, $precision);
		elseif ($method == PS_ROUND_DOWN)
			return Tools::floorf($value, $precision);
		/*return round($value, $precision);*/
		return Tools::ps_chf($value);;
	}

	public static function ps_chf($value) 
 	{
 		$tmp=(100*round($value,2)) % 5;
 		if ($tmp == 0) {
 		$chf=$value; 
		} elseif ($tmp <= 2) {
 		$chf=($value-$tmp/100); 
 		} else { 
 		$chf=($value+(5-$tmp)/100);
 		} 
 		return number_format((round(20*$chf))/20,2);
 	} /* added by AMS for CHF rounding */
Link to comment
Share on other sites

Looks like I have managed to solve my own problem.  For anyone with a similar problem this is the code you will need to change in order to round to the nearest 5 rappen in Swiss Francs: http://forge.prestashop.com/secure/attachment/10309/100913_mod_prestashop_arrondi_5cts.pdf

 

The suggested code I was using in the post above came from http://www.prestashop.com/forums/topic/240908-chf-runden-auf-5-rappen-erfolglos-gesucht/ but it doesn't work across the whole site and causes problems with other areas like manual orders.

 

Happy Days  :)

  • Like 1
Link to comment
Share on other sites

Looks like I have managed to solve my own problem.  For anyone with a similar problem this is the code you will need to change in order to round to the nearest 5 rappen in Swiss Francs: http://forge.prestashop.com/secure/attachment/10309/100913_mod_prestashop_arrondi_5cts.pdf

 

The suggested code I was using in the post above came from http://www.prestashop.com/forums/topic/240908-chf-runden-auf-5-rappen-erfolglos-gesucht/ but it doesn't work across the whole site and causes problems with other areas like manual orders.

 

Happy Days  :)

 

Thanks for this. I tried it with 1.6.0.9. I think this is still working, but I need to test it more deeply.

 

For people who want to use this with 1.6: The tools.js file is not exact like in the pdf file above. You need to find: 

else if (method === 1)
		return floorf(value, precision);

after this code

you add this:

/* wdx : arrondi 5cts : start */
else if (method == 3)
return Math.round(20 * value) / 20;
/* wdx : arrondi 5cts : start */
Link to comment
Share on other sites

  • 2 weeks later...

Hi Oxbow,

 

We're currently working on fixing the issues that you may have encountered with rounding on PrestaShop. Actually, there's an updated version of PrestaSthop available here: http://www.prestashop.com/forums/topic/350813-tax-and-rounding-fixes-testers-needed/?p=1777830 

 

Not only do we strongly recommend that you upgrade and get a chance to have your store run exactly the way you want to, but we also need users like you to run some tests and report any rounding-related bug you come across. 

 

First and foremost, we hope this upgrade makes your life easier on PrestaShop.

Link to comment
Share on other sites

  • 3 years later...

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...