Post by chll » Mon Feb 03, 2014 4:55 pm

Suppose a website run in 4 currencies: USD, EURO, Japan YEN and South Korean won. USD is the default currency

For Product A, I set the USD price to be 19.90 USD, the opencart convert it to 14.75EURO, 2031.6 Yen and 21549 Won

It is nice that the price could be rounded to 14.99EURO, 2099Yen and 21999 Won, or 14.90EURO, 2090Yen and 21900 Won

It is quite useful for multi-currency site

New member

Posts

Joined
Thu Nov 28, 2013 9:52 pm

Post by chll » Mon Feb 03, 2014 5:01 pm

there are 2 additional value to configure for each currency
1: to determine the currency to be round to nearest 0.01,0.1,1,10 or 100
2: to determine what value to minus to the rounded value by step 1

for example:
To round the Japanese Yen from 2031.6 to 2099, it means that the yen should be rounded to nearest 100, and minus 1 upon that

New member

Posts

Joined
Thu Nov 28, 2013 9:52 pm

Post by pprmkr » Mon Feb 03, 2014 7:56 pm

Perhaps this helps?

Edit system/library/currency.php

Search for:

Code: Select all

    	if ($value) {
      		$value = (float)$number * $value;
    	} else {
      		$value = $number;
    	}
After that add:

Code: Select all

	switch ($this->code){
		case 'KRW':
			$round = 1000;
			$step = -100;
			break;
		case 'JPY':
			$round = 100;
			$step = -10;
			break;
		case 'GBP':
		case 'USD':
			$round = 1;
			$step = -0.1;
			break;
		case 'EUR':
			$round = 1;
			$step = -0.01;
			break;
		default:
			$round = 0;
			$step = 0;
			break;
	}

    	
    	if ($round) {
	    	$value = ceil($value / $round ) * $round;
    	}
    	
    	if ($step) {
	    	$value += $step;
    	}

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by PakRicard » Fri Apr 11, 2014 12:24 pm

Great!

This code helped me a lot. Simple and easily adaptable to currencies.

Anyway, I think it is better to set $round = 1 in default case, to prevent a divide by zero later on, if the admin adds a currency and forgets to make the "pretty prices correction"

Pak R


Newbie

Posts

Joined
Tue Feb 18, 2014 11:59 am

Post by PakRicard » Sun Apr 13, 2014 9:24 am

Well. It works OK except that it also affects the admin side :-(
For front store works eprfect, but if you have a currency with large numbers (let's say IDR as example), and round to 5.000 IDR and it's the currency of your country, all sales made in USD, EUR, AUD, etc are rounded to 5.000.

So, is there a way to use this nice code modification ONLY for front store and not for admin?

Thanks!

Pak R


Newbie

Posts

Joined
Tue Feb 18, 2014 11:59 am

Post by roadrunner » Thu May 29, 2014 2:10 pm

Hi folks!

Thanks! This helped a lot.
Though this has affected my shipping prices also and my problem is when you choose free shipping it ends up as -0,1€
/0 rounded to 0 - 0,1 = -0,1/

Can you help how to set up a limit, for example only do this if the value is over 2.

Newbie

Posts

Joined
Thu May 29, 2014 2:02 pm

Post by pprmkr » Tue Jun 10, 2014 9:34 pm

Try changing:

Code: Select all

       if ($round) {
          $value = ceil($value / $round ) * $round;
       }
       
       if ($step) {
          $value += $step;
       }
Into:

Code: Select all

       if ($round && $value > 2) {
          $value = ceil($value / $round ) * $round;
       }
       
       if ($step && $value > 2) {
          $value += $step;
       }

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by roadrunner » Tue Jun 10, 2014 9:38 pm

Many thanks!

Newbie

Posts

Joined
Thu May 29, 2014 2:02 pm

Post by roadrunner » Fri Mar 06, 2015 3:52 pm

Hello,

After running some "rounds" :) e.g. I bought an extension to add fixed prices https://www.opencart.com/index.php?rout ... _id=481939 instead of opencart's default currency conversion, now I would like to go back for automatic conversion with some rounding to have nicer prices.

My problem now is that I have the option to sell with or without tax in the EU. I set up the rounding as suggested and it results nice prices on the front, but when someone registers to buy without tax (vat), he's net price is rounded again, which is unwanted.

Any help would be appreciated.

Newbie

Posts

Joined
Thu May 29, 2014 2:02 pm
Who is online

Users browsing this forum: No registered users and 5 guests