Multiple currencies for products

Posts: 5
Joined: 09/25/2007

I'm possibly being a bit dim and just not seeing it, but is it possible to set prices for a product in Euros and GB Pounds (say), and allow the user to choose which currency they wish to use?

Posts: 489
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Multi currency is not available in ubercart. The only way to do that would be to develop a module...

Posts: 173
Joined: 08/13/2007
Cool profile pic award.Getting busy with the Ubercode.Internationalizationizer

Is that true? And if so, will multi currency be supported some day by Ubercart?

Posts: 302
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Some stores may sell products from suppliers in different currencies. Their products would need updating at regular intervals to take into account currency fluctuations.

Posts: 489
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer


Is that true? And if so, will multi currency be supported some day by Ubercart?...

Someday, if somebody develop a module that do it... Eye-wink

Posts: 11
Joined: 11/27/2007

You're wrong, rich.

The way multi currencies work is to have a default currency specified for each product within a store and then if customer change his own default currency - he will see a result of currency conversion. Have you posted here for advertising purpose?

But this is definitely would be useful to have this module - as selling within one country isn't actual these days. So I suggest to create a team who will be developing the currency module - otherwise we will wait for years...

If somebody wants to participate in development - please post here for a beginning.

Posts: 302
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator

Hi ivan.g, I posted here because one of our clients source their products from different countries, Japan, UK and USA. They sell their products in GBP so need a way to display their product prices taking into account currency fluctuations. They don't need customers to be able to buy products in their chosen currency but I agree that this would certainly be a useful addition to Ubercart.

Posts: 45
Joined: 12/24/2007

Ivan.g! I am in your team.
I need to have this module in a 2 or 3 weeks - so i want to partisipate in your team.
I write modules for drupal but not for ubercart.

One more question - where are tour from? I am from Ukraine.

Posts: 14
Joined: 02/07/2008

I have developing site for client that needs to set different currency for products in one stock. I have developed some modules for Drupal 5 & 6 for my own needs and I think that I can help us with developing multicurrency module for Ubercart.
I am from Russia, Nizhniy Novgorod.

P.S. Sorry for my English Smiling

Posts: 14
Joined: 02/07/2008

I try to hook an array before render a product rendering form, but I can't found any hook to do this! When Drupal shows node edit form (node type is product), it calls function uc_product_form (setted in uc_product_node_info function) but this function have no hooks!
Have anybody some ideas how we can hook node render process and add additional currency fields?

Posts: 14
Joined: 02/07/2008

I think function uc_product_form needs something like this before 'return $form;':

  foreach (module_implements('product_edit_form') as $module) {
    $function = $module .'_product_edit_form';
    $form = array_merge($form, (array) $function($form));
  }

Because without this I can't found any method to hook product edit form.

Posts: 2083
Joined: 08/07/2007
AdministratoreLiTe!

Drupal provides hook_form_alter(), which is how the shipping modules add in their fieldsets. These functions have access to all of the product fields, but they choose to ignore them for the most part.

hook_form_alter() basically does what you proposed, but for every form identified by the $form_id.

Posts: 14
Joined: 02/07/2008

Function hook_form_alter() hooks all of Drupal forms, that it have a great number. And, I think, when I add new function to hook_form_alter, this will have a negative impact on all form perfomance, because calling product edit form is less frequently than other forms.
But at now I try to use hook_form_alter() in my module...

Posts: 14
Joined: 02/07/2008

I create some multicurrency functional in my module. Module is in alpha development stage, don't use it on work sites!

It can set product prices in custom currency and convert display price to selected currency. On my test site all works properly.

List of available currency and exchange rates at now is only in source code, file uc_currency.module.

I try to use currency drupal module API (function currency_api_convert()) but it is too slow (it is ask Yahoo site for every conversion), so for testing I write an easy equivalent function in my module.

Filter for available currency in product edit form ($currency_enabled):

function uc_currency_filter($currency) {
  $currency_enabled=array(
    'USD'=>'',
    'EUR'=>'',
    'RUB'=>'',
  );
  return array_intersect_key($currency,$currency_enabled);
}

Exchange rates ($values):

function currency_api_convert($currency_from, $currency_to, $amount = 1) {
  if($currency_from==$currency_to) return $amount;
  $equivalent='RUB';
  $values=array(
    'USD' => 24.6325,
    'EUR' => 35.9832,
    'RUB' => 1,
  );
  if(!($values[$currency_from] && $values[$currency_to]))return -1;
  return $amount*$values[$currency_from]/$values[$currency_to];
}

Values you can set relative to any currency.

Waiting for you comments and ideas.

AttachmentSize
uc_currency_5.x-1.x-dev-0.1.tar.gz2.32 KB
Posts: 4686
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

It won't have a noticeable impact. Just wrap all your code in an if statement checking against the form ID:

<?php
function example_form_alter($form_id, &$form) {
  if (
$form_id == 'the_form_id') {
   
// Code goes here. Smiling
 
}
}
?>

Posts: 2083
Joined: 08/07/2007
AdministratoreLiTe!

Most implementations I've seen of hook_form_alter() are just changing a single form. Of course, they're just testing a single $form_id, and not several like the product forms. I'm not too concerned about the performance because all of the node type info is cached in memory, and I trust in_array() to be efficient.

Posts: 45
Joined: 12/24/2007

It would be nice to have an administration form for this module - where we can set a range of currencies and its rates

Posts: 302
Joined: 08/28/2007
Early adopter... addicted to alphas.Not KulvikTheminator
Posts: 34
Joined: 11/29/2007
Bug Finder

*subscribe*

Yeah i need to do this too, will be a good thing to have in ubercart.

matt

Posts: 14
Joined: 08/08/2007
Getting busy with the Ubercode.

I too am currently working on a site that needs similar functionality. I am going to attempt to write a module to handle it. I think it'll be pretty straight-forward, and if I succeed, I'll definitely post the module here.. stay tuned, it shouldn't take too long.

-Rob

Posts: 34
Joined: 11/29/2007
Bug Finder

Cool, thanks.

I remember a nice feature in osCommerce was that you could set a standard currrency, then have it pop over to xe.com and check the exchange rates for other currencies, if that could be set up as a cron job it would be sweet. I seem to remember you could also add on a variable percentage to account for the hastle incured of people paying with other currencies, eg cost to convert to your currency.

What does the Locale module do? I guess it only handles the translations.

Good luck

m

Posts: 2
Joined: 05/02/2008

izi wrote:
I too am currently working on a site that needs similar functionality. I am going to attempt to write a module to handle it. I think it'll be pretty straight-forward, and if I succeed, I'll definitely post the module here.. stay tuned, it shouldn't take too long.
-Rob

This is something I'd also find useful, and I can envisage it working in a couple of different ways:

Currency selection

  1. Allow user-selected currency(s)
  2. Allow only Admin-selected currency(s)

Currency display

  1. Show just one price (EITHER the default currency, OR the alternative currency(s) )
  2. Show more than one price (ie the default currency, AND the alternative currency(s) )

Currency conversion

  1. Convert default currency either (a) using Currency exchange module, or (b) Manually (ie. admin specifies the conversion value)
  2. After converting currency, (a) add/subtract result by a fixed or % amount, (b) round the result EITHER up or down, to the nearest 0.05 or 0.10 or 0.25 etc.

Just my two cents worth (or 0.1 Euro, or 0.15 pence, worth).

Posts: 2
Joined: 11/12/2007

Hi, I'd also love module with similar functionality as iantresman asks for and I'm ready to help. The problem is, that i don't know the current state of matters, latest post on this topic is almost two months old. So could someone drop me a line about what's currently going on and how can I help? I need those functionalities as soon as possible so I'm goging to implement some dirty and fast temporary solution, because tomorow I'm going on holiday for a month, but when I return, we can realy focus on it and make clean elagant and fast wich ubercart could proud of Eye-wink

Posts: 14
Joined: 03/05/2008

subscribe. thx.

Posts: 2
Joined: 07/15/2008

How far did you guys get?

I'm having the same need.

Posts: 869
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

I have a solution that I will release as soon as my client signs off on it.

--

<tr>.

Posts: 72
Joined: 02/14/2008
Bug FinderGetting busy with the Ubercode.Internationalizationizer

Hi TR,
what about your solution? I am sure you would make a lot of people really happy Smiling

Posts: 869
Joined: 11/05/2007
Bug FinderFAQ ModeratorGetting busy with the Ubercode.

I still haven't gotten around to getting it in Drupal CVS, but I've just posted it in the Ubercart.org contributions section for your enjoyment: http://www.ubercart.org/contrib/6102

I would appreciate any feedback.

--

<tr>.

Posts: 489
Joined: 08/13/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer

Thank you very much. I will make a project soon that request this feature, I will stay you informed.

If UC2.0 progress quickly, I even plan to do it directly with D6 and UC2, so I will port your module to 6.x ^^

thank you again for this usefull feature !