Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID?

Quote Reply
Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID?
Hi All

I'm building a catalog system using multiple languages and multiple currencies. I'm trying to find a way to convert the numeric content of the price field for each item into whatever currency the visitor wants to see at any time. So, the customer could at any time select a different currency to view the products, and then all are converted for that visitor for their session, and could be remembered for the next visit. This would be for static and dynamic pages, as well.

The idea is to create a simple way to update prices for large databases that use multiple languages and currencies - update 1 price file, rather than having to go into each subcategory and convert the entire database for each language.

I'm going to create each language as it's own category, and then create a template file for that category. The regional manager for each language will be responsible for translating the item descrips, titles, etc.

French/Items
German/Items
English/Items
Dutch/Items

The whole thing seems like it would work by assigning the pricing to the link id numbers, then setting up something like an array of currencies and their conversion factors, and then using SSI for static pages, but I don't know what for dynamically built pages.

I hope I have explained this well enough. Thanks for any help. Much appreciated.

Happy Holidays!


------------------------------------------
Quote Reply
Re: [DogTags] Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID? In reply to
Hi,

You are going to want a global for this. To do the conversion you could add a global:

Code:
sub convert_price {
my $tags = shift;
my %rates = ( USD => 1, CDN => 1.585, EUR => 1.126, DMARK => 2.203 );
my $price = $tags->{Price};
my $convert = $tags->{Convert} || 'USD';
return sprintf ("%.02f", $price * $rates{$convert});
}

Then you could do:

<%convert_price%>

and it will print out the US dollar amount, but if you passed in ?Convert=CDN, it would display all prices in canadian dollars. Just need to update the rates on a regular basis.

Hope this helps,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID? In reply to
A note to users:

You have to remove the "convert_price" from the sub. Otherwise, it just prints the words.


Okay, back on track...

Alex, this looks great! If this works the way I think it will, it will solve a monster problem.

Here is what I'm wondering. Could this work in any language section of the site and then maintain the selected currency for my entire visit (or until I choose another currency) no matter which language section I am in or chose to jump to? Meaning, if a visitor is in the Korean language section, but the visitor wanted to see what the price would be in Canadian dollars, could the visitor simply click a link and change the currency to Canadian dollars, continue in the Korean section, and have the Canadian currency displayed for the rest of their visit (unless they chose another currency), whether they stay in the Korean section or jump to the French section?

What would be really great is to have the currency conversion work independently of any language section and have the selected currency maintained throughout the visit or until another currency was chosen. This would allow total flexibility between languages and currencies.

Thank you so much!!

------------------------------------------
Quote Reply
Re: [DogTags] Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID? In reply to
Hi,

Yes, if you are using page.cgi for everything, there is an option:

dynamic_preserve => t,d,s

this means these three variables will be preserved. You can modify this to be:

dynamic_preserve => t,d,s,Convert

then if you pass in Convert=EUR, in all Links SQL links, it will keep that link.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID? In reply to
dynamic_preserve !

What else do you have in the goodie bag, Alex Wink

Many thanks for your help Smile


------------------------------------------

Last edited by:

DogTags: Dec 28, 2001, 4:25 AM
Quote Reply
Re: [Alex] Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID? In reply to
This works great for simple pricing:

$15.00 ea

However, what if I have a complex price structure like quantity discount pricing.

SHOES
1-3 pairs.....$5.00 each
4-6 pairs.....$4.75 each
7-10 pairs...$4.50 each
11+ pairs....$4.25 each

Is there any way to enable this type of thing to be converted to the selected currency as well?

Many thanks.

------------------------------------------
Quote Reply
Re: [DogTags] Multiple Languages - Multiple Currencies (Numbers) - Can Currencies Be Converted In Real Time Per Link ID? In reply to
How are you displaying the pricing? For this to work, you need to make it so each price is a field (or I guess you could do it with regex's as well):

s/\$(\d+\.\d\d)/convert($1)/g;

or something similiar.

Cheers,

Alex
--
Gossamer Threads Inc.