Hey TR,

My client needed a block to choose the user's Currency, not based on Country. The reason being there are a lot of users who are in Europe that might use the Euro, or might instead be more comfortable with the GBP, etc. Since we're not detecting countries based on location, then this block is something we'd need.

It took a little bit of work but I basically added a function that scrapes the in-use countries and currencies and from that, builds a selection form in a block. It also adds a new variable to the $user object called "currency_code". Finally, and most importantly, I changed the price_handler_alter hook to check for the variable in the $user object first, and if it finds it, it uses that currency code in all the price handling.

Take a look and let me know if it should be changed, cleaned up, etc. I did as much as I could and in testing it seems pretty solid. I'm sure it could use another set of eyes, though :)

One note: This patch is based on my previously-patched version of the module. For some reason, when I rolled the patch from the latest Dev release, I get a WSOD when choosing a new currency.

Comments

torgospizza’s picture

The patch looks pretty ugly... not sure why it did that. I even tried running diff on it again, and it still outputs basically the whole module. Sorry... if you want I can try a third time. Tested it and it still seems pretty solid.

Erik

torgospizza’s picture

StatusFileSize
new11.64 KB

Here we go, I was able to checkout the module in CVS and create a patch that way.

This is rolled against the latest CVS build, obviously, and includes my previous patch for the price handling stuff.

torgospizza’s picture

StatusFileSize
new12.53 KB

Here's a new patch which also adds the ability for ANONYMOUS users to choose the currency, using the Currency selection block. Tested and working so far. (Use this instead of the previous patches.)

piotrsmykaj’s picture

torgosPizza not working for anonymous :/

torgospizza’s picture

Works fine for me in testing. Did you setup your price handlers correctly? It's in Ubercart's admin area, under I believe, Products > Price handler settings.

Which part of the patch doesn't work for you? The selection, the block, or the currency being changed? Need more info please.

dave_______1’s picture

Hi torgosPizza,

Think I'm looking for what you've created in this patch, problem is I'm on a shared host and don't have access to the command line!
Any way I can get this block to work another way?
Some PHP to use in the PHP input type on a block would be a great help.

Thanks for your help.
Dave.

torgospizza’s picture

The functionality involved in selecting a currency isn't something you can just drop into a PHP code block, unfortunately. It's a system that hooks into the user object as well as the price handlers for Ubercart.

I think TR is going to commit my patches to a new dev version soon. I'll see what his status is and ask him to update this thread.

dave_______1’s picture

Thanks torgosPizza, been trying to get this working for a while but just can't seem to get my head round the way Drupal works with forms!
Getting there though with the help of some good books and a boss with a whip!

liliplanet’s picture

Subscribe thanx! Definitely prefer a currency selection instead of 'by country'. EUR and $$$'s only would be fabulous!

korda’s picture

I'm testing this module on a Drupal 6 installation, Ubercart 2.0. I managed to get the block to display, however when I change the currency in the block and hit apply the page refreshes and the block displays the default value with no change to the price.

http://stormunlockonline.com/catalog/135

Any in sight would be greatly appreciated.

dave_______1’s picture

Hi Korda,

Looks like you've taken this off your site??

I couldn't get this module to work either, it seems to create a new display price and changes that instead of the original.
This is no good if you have ajax stuff going on or the VAT module.

If you take the price as you have it, calculate the prices you need in php e.g. to go from £ to $ its (price in £) * ($ to £ exchange rate).
Once you have all the prices you need print them in a layer and use CSS to make it look just right.

To see what I did go to any product from this site:
http://www.satandcable.co.uk

I did it the hard way, when I get some time I'll be working on this one.

If you need me to post the code I used let me know.

Good luck.
Dave.

agileware’s picture

@torgosPizza:
Thanks for the patch, I'll test it out and let you know if I have any troubles.

Also, the problem you were having with diff in your first patch was possibly due to mismatch in whitespace.
Sometimes it causes diff to think the whole file has changed.
If you have trouble with this there are a couple of whitespace options you can play with to get around it (taken from man diff):
-b --ignore-space-change
Ignore changes in the amount of white space.

-w --ignore-all-space
Ignore all white space.

-B --ignore-blank-lines
Ignore changes whose lines are all blank.

It is also good practice to use the -p option as well as the -u option as it adds useful information.
See http://drupal.org/patch/create

agileware’s picture

StatusFileSize
new12.16 KB

Hunk 1 of your patch fails because it has already been fixed in 6.x-1.x-dev

It should not be in this patch anyway as it is an unrelated issue so here is your patch without that hook_help bit.

agileware’s picture

Seems to work well for me after some basic testing.

There are a couple of things to note though:
1. In the readme the module says to rename the uc_currency_format function. It needs to be noted that you must revert that change or this patch will cause undefined function errors.

2. This patch duplicates code from #449322: Drupal 6/Ubercart 2 Version. When that issue is resolved this patch will need to change to just include the block parts.

agileware’s picture

Also, the "Currency Symbol" setting on the admin/store/settings/multicurrency/formats page seems to have no effect.

I'm guessing that that part will end up being handled by the patch in #449322: Drupal 6/Ubercart 2 Version though anyway.

bensquare’s picture

subscribing

kaata’s picture

Category: feature » bug

Hi I tried this patch, its working and changing prices on product page, in cart content everything is OK, but at the end in checkout order total preview it shows some absurd numbers. Maybe it is converting again or something.
For example I have subtotal 2429,00$ in cart
and in Order total preview is
Subtotal: 7,00$
Order total: 123,00$
For default currency its fine.
Any idea how to fix it?

agileware’s picture

Category: bug » feature
Status: Needs review » Postponed

This is a feature request, not a bug report.

This issue should definitely be on hold at least until #449322: Drupal 6/Ubercart 2 Version is finished.
When that is done this issue should be revisited.

Because this patch adds code that is needed for this feature but will be added by that other patch.
Unless someone wants to do a patch here in the meantime that relies on the other patch and just adds the block part.