Post by Qphoria » Thu Jun 11, 2009 3:28 am

This was a bug we fix back in 0.x and i see this is another one that still exists in 1.x

In the system/library/currency.php file you have:

Code: Select all

public function format($number, $currency = NULL, $value = NULL, $format = TRUE) {
		if ($currency) {
      		$symbol_left   = $this->currencies[$currency]['symbol_left'];
      		$symbol_right  = $this->currencies[$currency]['symbol_right'];
      		$decimal_place = $this->currencies[$currency]['decimal_place'];
    	} else {
      		$symbol_left   = $this->currencies[$this->code]['symbol_left'];
      		$symbol_right  = $this->currencies[$this->code]['symbol_right'];
      		$decimal_place = $this->currencies[$this->code]['decimal_place'];
    	}

    	if ($value) {
      		$value = $value;
    	} else {
      		$value = $this->currencies[$this->code]['value'];
    	}
.............
Note that even if you have a $currency specified, the $value check only checks "this->code]['value']"
It needs to be something like this:

Code: Select all

public function format($number, $currency = NULL, $value = NULL, $format = TRUE) {
	if ($currency) {
      		$symbol_left   = $this->currencies[$currency]['symbol_left'];
      		$symbol_right  = $this->currencies[$currency]['symbol_right'];
      		$decimal_place = $this->currencies[$currency]['decimal_place'];
    	} else {
      		$symbol_left   = $this->currencies[$this->code]['symbol_left'];
      		$symbol_right  = $this->currencies[$this->code]['symbol_right'];
      		$decimal_place = $this->currencies[$this->code]['decimal_place'];
      		$currency = $this->code;
    	}

    	if ($value) {
      		$value = $value;
    	} else {
      		$value = $this->currencies[$currency]['value'];
    	}
.............
This prevents the $currency argument in the format function from working.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Daniel » Thu Jun 11, 2009 4:13 am

I don't think this is a bug.

On some occasions it is nessary to format a value but not do a conversion.

also you sometimes need to put your own conversion rate for previous orders becuase the conversion rate will have changed at some point.

User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Qphoria » Thu Jun 11, 2009 4:45 am

Daniel wrote:On some occasions it is nessary to format a value but not do a conversion.
And sometimes you want to do a conversion but not a format. Currency conversions will NEVER work the way it currently is.

Let me explain.

The $currency argument means you want to convert from the current currency to the specified currency.

Lets say my current currency that i selected on the front end is USD
So if I do:

Code: Select all

cost = $this->currency->format('160.00', 'SEK', FALSE, TRUE) ;
I want to convert 160.00 USD to SEK, which should be like "20 kr"

But when I run that code it returns:
160,00 kr, which is wrong. It only formatted, but didn't convert.

Because it's not using the converstion rate since the $value doesn't check the $currency value. It only checks "this->code" which will always be my current selection. So its just converting USD to USD, but adding the SEK formatting.

Currently you are only using the $currency argument for formatting the symbol & decimal places. You need to also do it to value.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Thu Jun 11, 2009 9:20 am

does it make sense now? I fear i'm explaining it wrong. But I'm 110% certain it's a bug.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Daniel » Thu Jun 11, 2009 6:56 pm

no i thnk your right now.

if you only need the formatting done and not conversion you can just set the value to 1.0000

User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Qphoria » Thu Jun 11, 2009 7:00 pm

correct.
Or you could just leave the $currency empty

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 14 guests