38 replies [Last post]
Gordonjcp's picture
Offline
Joined: 09/25/2007
Juice: 15
Was this information Helpful?

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?

zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1192
Re: Multiple currencies for products

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

qrios's picture
Offline
Cool profile pic award.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 554
Re: Re: Multiple currencies for products

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

psynaptic's picture
Offline
Early adopter... addicted to alphas.Not KulvikTheminator
Joined: 08/28/2007
Juice: 731
Re: Re: Re: Multiple currencies for products

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

ivan.g's picture
Offline
Joined: 11/27/2007
Juice: 22
You're wrong, rich.

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.

psynaptic's picture
Offline
Early adopter... addicted to alphas.Not KulvikTheminator
Joined: 08/28/2007
Juice: 731
Re: You're wrong, rich.

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.

eugef@drupal.org's picture
Offline
Joined: 12/24/2007
Juice: 102
Re: You're wrong, rich.

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.

murz@drupal.org's picture
Offline
Joined: 02/07/2008
Juice: 37
I think that I need this module too

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

murz@drupal.org's picture
Offline
Joined: 02/07/2008
Juice: 37
How can I hook a product node edit form?

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?

murz@drupal.org's picture
Offline
Joined: 02/07/2008
Juice: 37
Re: How can I hook a product node edit form?

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.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: How can I hook a product node edit form?

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.

murz@drupal.org's picture
Offline
Joined: 02/07/2008
Juice: 37
hook_form_alter() hooks all of Drupal forms

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

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: hook_form_alter() hooks all of Drupal forms

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. :)
 
}
}
?>
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: hook_form_alter() hooks all of Drupal forms

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.

zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1192
Multi currency is not


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

murz@drupal.org's picture
Offline
Joined: 02/07/2008
Juice: 37
Re: Multiple currencies for products

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.gz 2.32 KB
eugef@drupal.org's picture
Offline
Joined: 12/24/2007
Juice: 102
Re: Re: Multiple currencies for products

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

psynaptic's picture
Offline
Early adopter... addicted to alphas.Not KulvikTheminator
Joined: 08/28/2007
Juice: 731
Re: Re: Re: Multiple currencies for products

Does this module try to implement the following?

http://www.ubercart.org/forum/development/3194/how_implement_currency_mo...

sphism's picture
Offline
Bug Finder
Joined: 11/29/2007
Juice: 215
*subscribe* Yeah i need to

*subscribe*

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

matt

izi
izi's picture
Offline
Getting busy with the Ubercode.
Joined: 08/08/2007
Juice: 63
Re: Multiple currencies for products

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

sphism's picture
Offline
Bug Finder
Joined: 11/29/2007
Juice: 215
Cool, thanks. I remember a

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

iantresman's picture
Offline
Joined: 05/02/2008
Juice: 78
izi wrote:I too am currently
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).

shomeet's picture
Offline
Joined: 11/12/2007
Juice: 4
Current state?

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

Gergely Varga's picture
Offline
Joined: 03/05/2008
Juice: 51
Re: Multiple currencies for products

subscribe. thx.

I really like lemonade.
42droids.co.uk

matkokubko's picture
Offline
Joined: 07/15/2008
Juice: 11
Re: Multiple currencies for products

How far did you guys get?

I'm having the same need.

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Re: Multiple currencies for products

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

<tr>.
Al
Al's picture
Offline
Bug FinderGetting busy with the Ubercode.Internationalizationizer
Joined: 02/14/2008
Juice: 249
Hi TR, what about your

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

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Hi TR, what about your

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>.
zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1192
Re: Re: Hi TR, what about your

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 !

pjriot's picture
Offline
Joined: 12/14/2008
Juice: 41
Re: Re: Re: Hi TR, what about your

I threw together something today that lets you define your own currency rate through an admin menu. It will enable you to show an end user whichever currency applies to their locale. Its my first attempt at module writing but its basic enough in functionality. Unzip this in your ubercart module folder then go to Store admin -> config -> Multiple Currencies

It basically lists all of the countries you have enabled in Country Settings and provides a Currency box for each for you to define. (with "conversion rate" and "round to" boxes thrown in)

get_current_country_name() basically pulls the whitespace from the current country as returned by IP2Nation.

The uc_multiplecurrencies_format function takes a country argument (sans whitespace! hence get_current_country_name()) and performs the conversion/formats the price accordingly.

I do need to add the facility to specify a default currency should the user be from an unsupported country, but that can wait till later.

Obviously this is set up so that you'll have to keep tabs on your currencies. The person I wrote this for is only concerned about two currencies anyway and to be blunt, sees the conversion rate as an opportunity for profit. (a normal enough practice for retailers here unfortunately)

Its very rough and ready and I would greatly appreciate feedback/codereviews. (like I said, I'm new at this so I'd love to learn why my code sucks)

AttachmentSize
uc_multiplecurrencies.tar.gz 2.56 KB
eugef@drupal.org's picture
Offline
Joined: 12/24/2007
Juice: 102
Re: Re: Re: Re: Hi TR, what about your

Hi, pjriot!

I try you module and have 2 questions
1. Why you need ip2nation module - i didn't find any using of it?
2. Can you make a block for all users to select currency directly?

pjriot's picture
Offline
Joined: 12/14/2008
Juice: 41
Hey Eugef, Need is a strong

Hey Eugef,

Need is a strong word alright. Its used in the following function:

function get_current_country_name() {
$addr = $_SERVER['REMOTE_ADDR'];
$c = ip2nation_get($addr);
return str_replace(' ', '', $c->country);
}

Its really just a convenience method, but I left the dependency in there anyway.

Actually I've noticed a few little things that need cleaning up with the module so I might post an update later today/tomorrow.

Also, this is probably obvious to some, but in order to implement this module you'd need to use uc_multiplecurrencies_format in your theme to display the price. Forgot to mention that earlier.

pjriot's picture
Offline
Joined: 12/14/2008
Juice: 41
cleanup

Slight code cleanup (indentation and the removal of some string code I was using for debugging)

AttachmentSize
uc_multiplecurrencies.tar.gz 2.47 KB
TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: cleanup

Why are you writing your own code, rather than using the existing uc_multicurrency module?

<tr>.
pjriot's picture
Offline
Joined: 12/14/2008
Juice: 41
Re: Re: cleanup

Good question. I started it out of ignorance. I came across the uc_multicurrency module later in the day. Since I was already using my version in the theme (I've themed the product node/cart etc. as part of the work I'm doing) I hoped to avoid the need to change ubercart code with this one.

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Re: Re: cleanup

If you want to have a routine you only call from theme functions, all you have to do is rename the uc_currency_format() that comes with uc_multicurrency, then use that to format your prices.

But let me suggest that your strategy of doing everything in theme functions is a poor choice, for the following reasons:

Presentation of price is central to every aspect of Ubercart. Because of this, every module and every contribution deals with prices, and most of them are responsible for displaying prices at some point. So in order to make your site display currencies properly, you will need to override every single theme function that uses prices.

A huge problem with this scheme is that there are lots of theme functions: The product page, catalog page, cart block, all the individual cart panes (shipping, taxes, payment, etc), order review page, all the order history and admin pages, reports, stock, attributes ... not to mention theme functions for any contributed modules you've installed. All these theme functions will have to be copied into your template.php and edited to change the name of all occurrences of uc_currency_format() to your own special function name. What happens when Ubercart gets updated? Then you have to go through the entire process again - identifying all the theme functions that display prices, copying them, and modifying them. Contrast this to how uc_multicurrency works - not modifying core but overriding just one function in Ubercart in a manner that is impossible to neglect when you upgrade Ubercart.

What happens if you want to add a new contribution, or turn on a new shipping method, or define a new product class? You've just set yourself up for tremendous maintenance problems because any little change requires thorough examination to see where prices might come into play, along with the aforementioned copying and modifying theme functions. You won't be able to just "try out this contribution and see how it works", instead you'll have to identify and modify the module's theme functions before you can do anything.

One assumption you're making is that all display of prices occurs from within theme functions. That's just not true. For instance, off the top of my head, uc_order_history() is just one of the many places where prices are formatted for display without passing through a theme function. So no matter what you do to theme your site, with this strategy you'll end up hacking *lots* of Ubercart core functions.

Additionally, theme functions in Ubercart tend NOT to be small snippets of code. When you copy these theme functions, you will have hundreds of lines that have nothing to do with price display, all for the sake of renaming one function call.

In fact, the only place where you can be sure of affecting all prices is uc_currency_format(). Which is why I chose that choke point as the preferred place to hook into. This underscores the fact that uc_currency_format() should have been defined as a theme function in the first place - IMO this is an architectural problem in Ubercart that needs to be fixed. There is discussion of this issue elsewhere in the forums if you're interested.

This is not to say uc_multicurrency is perfect. Which is why I think it is better for the community to put development effort into improving existing code rather than duplicating and fragmenting the effort. As I said in my first paragraph, if the only reason to have your own codebase is so you can put the function call in your theme, uc_multicurrency already provides you with a way to do that, as well as simple integration into IP Nation (although I also urge you to look at the "IP-based determination of Country" contribution, which has significant advantages over IP Nation, automated updates of the database from a non-proprietary datasource, for one).

<tr>.
pjriot's picture
Offline
Joined: 12/14/2008
Juice: 41
Re: Re: Re: Re: cleanup

"There is discussion of this issue elsewhere in the forums if you're interested." - I am, I'll root around.

"it is better for the community to put development effort into improving existing code rather than duplicating and fragmenting the effort" - I agree. A learning exercise started out of ignorance.

"I also urge you to look at the "IP-based determination of Country" contribution" - I will, IP2Nation was the first I came across. Seemed simple enough. I'll dig into this.

One other thing thats bothering me is the anonymous cached pages. Is there a way to intercept the caching mechanism in Drupal? (with a view to writing a module that could provide location based cache pages?)

betancourt's picture
Offline
Joined: 10/04/2009
Juice: 17
Question

Hey:

First of all thanks for working on this module. I am currently developing a store that ships products from two differenct countries, therefore I need to valid currencies. The problem I have is with the UPS module, as Ubercart can have one default currency, and UPS returns a estimation cost in currency of the country of origin, there is the problem. When the country of origin's currency and default currency in Ubercary match is no problem, but when they are different I cannot estimate the shipping costs? Any idea. I believe that the problem here is that the order has a currency and this is independent of the currencies displayed per product am I right? Displaying multiple curencies is just for the frontend but at the end it is just one currency used in the backend?

Thanks

amcoms's picture
Offline
Joined: 04/04/2012
Juice: 41
multiple currency support

Hi Guys, has there been any dev for multi currency support?

this would be a great contrib if we could get a moving forward steering group?

Andrew