Installation is pretty simple though please do read the README.txt. I'm hoping to get feedback.

I wasn't sure if I should continue in the other thread or start a new one. Actually, I wasn't sure whether to create a patch or release a new module.

I've modified the code but renamed the module to "uc_multi_currency" and similarly moved the menu settings to "multi-currency".

The changes are not a complete rewrite but it seems significant enough from the original that maybe a new module made more sense. There is so much information in the other threads that it becomes overwhelming. So instead of knowing which patches to use, I decided to just recode as to how I wanted it.

Can anyone advise on whether this should be a patch or another module? Can anyone test the module and give feedback?

Much appreciated,
KJ

------------------------------------------------------------------------------
Installaion
------------------------------------------------------------------------------
1) unzip folder into appropriate modules directory inside Drupal
2) enable the module "Uberacrt Multi-Currency"
3) go to http://yoursite/admin/store/settings/price-handlers
a) enable: "Multi currency price handler"
b) uncheck "Cache generated price values until the next cron run."
c) Save configurations
4) go to "Administer -> Site building -> Block"
a) enable "Currency Selection" to the region you want to display in

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Shane Birley’s picture

Testing.

KiranJoshi’s picture

Thanks Shane.

I await your feedback.

==
KJ

Andy Langton’s picture

Initial testing looks very good! It would make more sense to me for this to be a new module or a replacement for the current one which is next to unworkable. At the moment, this looks like it might be the only truly working multicurrency solution for ubercart and it's a bit lost in this issue thread!

KiranJoshi’s picture

Thanks Andy for the feedback. It's good to hear that initial tests were successful for you.

I'm looking into the process of creating a new module.

zakir.gori’s picture

Testing

pkej’s picture

I'm testing the module and I've found that it doesn't work with options which change the price, the prices on the options reflect the default store currency.

First screenshot is in a converted currency, the second screenshot is in the default currency.

The currency selection dropdown should have a "store default" option to return back to store defaults. I had to add NOK manually to return to store default.

Apart from that it works pretty well.

sfdrummer’s picture

I've installed the module and it works fine! Right up until the point when the user checks out through PayPal, I've followed the instructions in the readme.txt and the currency is transfered but not the adjusted price. So if I'm ordering a product that costs £1.50 the module converts that to $2.39, but when checking out, PayPal shows the price as $1.50.

Not sure if I've made an error during the installation...

Any suggestions?

suvannet’s picture

Yes, it's works fine, thanks KingJoshi. But I have one problem with views. My site works on one currency. And admin panel is work on another, default currency. I want to create exposed filter to get product by it's cost in range. But filter is work with default currency. What should I do to make the filter works with the currency on the site (secondary currency, not defualt)?

P.S. Sorry for my bad English

Les_Paul’s picture

Great module! Works perfect. But I have one problem. I can't find where to change default currency. After installation I delete SGD, but it still used like default on Convertion Settings page.

KiranJoshi’s picture

FileSize
10.72 KB

Sorry about this late reply. I was hoping to create a new project and answer questions there but I have not received permission to upload a new project.

I've attached updated code of the module. There were some tiny bug fixes and now, the default store currency is automatically added to the list. Also, USD and EUR is added so that is on the list as well as the store's default currency. Just to allow demonstration of the module.

KiranJoshi’s picture

@pkej

I had tested with Attributes module. Usually, it adjusts prices by adding to the default price. For me, it adjusts those prices.

Are you themeing that or displaying the prices differently from normal? Or are you using a different system for price adjustments besides the default "Attributes" module?

BTW, now with the latest update, the stores default currency is on the list. So when a user installs, they don't have to do that manually. Thanks for pointing out that bug :D

==
KJ

KiranJoshi’s picture

@sfdrummer

It's hard to debug just by thinking :)

Can you check your PayPal setting? I don't recall what the default is for PayPal payment, but I think currently, " Submit the whole order as a single line item." needs to be selected. If it's not checked, can you do that and see if that solves the problem?

==
KJ

KiranJoshi’s picture

@Les_Paul,

Now the new code will use the store's default currency. SGD is only a fall back option. I had a bug in the code where it wasn't doing some things properly.

Can you see if the new update solves your issues? Thanks.

==
KJ

KiranJoshi’s picture

@atontimes,

I'm sorry but I don't know of a simple solution. I looked into it a little but I don't currently have the time to properly investigate. It seems Views just does a query from the DB and uses the original sell price without using the price handlers. Just my assumption based upon prelim search.

Theoretically, we could convert the number entered by the user for searches, convert them to the default currency before filtering the views. Or we could make views use price handlers.

Either way, there would be PHP coding and it would take time to implement this feature. Unfortunately, I do not have a lot of time...

==
KJ

Les_Paul’s picture

@KingJoshi,

Great thanks, default currency feature work properly now.

nicksanta’s picture

Subscribe

jaybhancock’s picture

I am testing the 1.01 version. Seems like everything works properly except for the SGD issue.

My default currency is stuck on SGD. My store currency is set to USD. I am using the code that should have fixed the issue.

By inspecting the uc_multi_currency.module, I notice:

define('UC_MULTI_CURRENCY_DEFAULT_CURRENCY', 'SGD');

I changed this setting to USD and it is working for me now. However this solution is not idea. Somehow this setting is not being corrected later in the code.

What is the mechanism in the code that will override this default?

KiranJoshi’s picture

Hi Jay,

Thanks for testing. I'm not sure why you are encountering problems. My only guess is that when you installed Ubercart, it defaulted to store currency of USD but you never saved it. So instead of saving the currency in a setting, it always just uses hard-coded assumption of USD.

Can you go to "Store Settings" -> "Format settings" -> "Currency format" -> "Default currency" ?
It should be USD but that setting is probably not saved in a variable. If you click on Save and change the module define code back to SGD, the module should retreive USD as the default.
define('UC_MULTI_CURRENCY_DEFAULT_CURRENCY', 'SGD');

Of course, I'm doing debugging by guess work but the following is a technical explanation for my reasoning:

Throughout the source, you should see the following code.
variable_get('uc_currency_code', UC_MULTI_CURRENCY_DEFAULT_CURRENCY);

Ubercart sets a variable ('uc_currency_code') for the store's currency. To retrieve the store's currency, we use the Drupal function variable_get. UC_MULTI_CURRENCY_DEFAULT_CURRENCY is only used if Drupal can't find the store's default currency.

I created the following define statement so that in the case such as yours, if someone needs to change the default value in php, they would only need to change one line instead of each instance where the function is called.

If you want to do even more debugging, you can check your Drupal database. There is a table called variable and if you search for a record where the column name is uc_currency_code, then you should see the result with the store's currency. Since the multi-currency code couldn't find it, it probably isn't there. If it is there, the module should be using it. If it isn't, then that is a really strange error.

jaybhancock’s picture

Yes, THAT FIXED IT.

When viewing that the Store's Default Currency it shows USD. By clicking SAVE it fixes the issue. This seems to be a bug in Ubercart - that it assumes USD and behaves as though USD is set (by showing it in the field) even though it is not set.

So this needs to be a step in your module OR we need to file an issue with Ubercart to ensure there is a standard way of making that variable available to other modules.

Thanks for the quick reply.

jaybhancock’s picture

I am having a new challenge.

I am using uc_aac with attributes and price adjustments. My attribute prices are being displayed with the units changed (I display as CAD$ or USD$), but the price amounts next to each attribute option are not being converted. This seems similar to the challenge @pkej had.

I have calculated the final result, however, and the price total for the item is correctly calculated.

Example:

USD Currency setting (USD default):
* Item = USD$44.99
* Option = +USD$35.00
* Total when option selected = $79.99 (correct)
* Exchange Rate: CAD = 1.0269 * USD

CAD Currency setting:
* Item = CAD$46.20 (correct)
* Option = +CAD$35.00 (not converted properly; should say +CAD$35.94)
* Total when option selected = CAD$82.14 (correct: $79.99 * 1.0269)

When I disable uc_aac to remove the ajax price updating, the option displays correctly with +CAD$35.94.

Is it a defect in uc_aac or uc_multi_currency?

KiranJoshi’s picture

Personally, I think Ubercart should save the currency setting during install, but that's a personal perspective. I had used the default currency in the module to SGD to more easily notice conflicts and errors in my code. Regardless, I have to hack this module to make it work with the current system of Ubercart. So I've updated my default value to USD so that there is no conflict for others who have not saved the settings page. I've attached the install file in the next post.

KiranJoshi’s picture

FileSize
10.73 KB

It's not possible to assign blame or say one module has a defect. There was no proper planning for how to handle multi-currency, so it's not as though either module is breaking specifications. I looked into uc_aac and noticed they do send context information when they call uc_price, which is the function you're supposed to call to get the price.

I have coded this module as a hack really. Because there is no protocol on when a module calls uc_price, how the context information relates to currency. For example, lets say you have two products and you add the price of each product and display the total. Well, for each individual product, you might want the price converted, but then the total is already converted. So you still want to display the total in the foreign currency, but you shouldn't convert the total with the exchange rate.

So what I did was test every case I saw where Ubercart displays the price. After testing all situations where prices are shown, I had coded this module to only alter the price where necessary. So it's unlikely to work with modules I haven't tested with.

I downloaded uc_aac and looked at the source. I've altered this module and it should work with uc_aac now. But I haven't installed uc_aac and done a complete test to make sure I didn't break anything. I just did the tests in my head and it seems like it should be ok.

I recommend people use v1.01 unless you use uc_aac.

Shane Birley’s picture

Sorry, I was distracted with life and didn't get enough time the past couple of weeks to test properly. I will try version 1.01 tomorrow and let you know what I find. Thanks for your hard work on this!

pkej’s picture

Hi, I haven't tested the latest version because it isn't compatible with the boost-module.

I suggest that the uc_multi_currency module should add "/NOK", "/USD" etc to the end of the page url in order to create unique pages which are boostable. A different approach would be if the dropdown instead of being something you submit, instead runs a jquery-xpath query which could search through the page for all prices and configure them accordingly. Done "right" it could probably live as a fully cacheable block as well.

Another thing that could be nice for uc_multi_currency would be to autosubmit upon change of the dropdown.

jaybhancock’s picture

I tested this module.

This change is necessary even with uc_aac disabled. I have found a new situation that the pricing was not correct:
* no uc_aac
* attributes for a product
* have attributes show total price (instead of the differential)

In this scenario, the default currency price was displayed. When I used v1.02, the correct price was displayed.

KiranJoshi’s picture

Thanks for the testing. Much appreciated.

==
Kiran

KiranJoshi’s picture

Currently, that's beyond the scope of our needs. Creating a URL for each currency shouldn't be hard to implement. I haven't used the boost module nor know the difficulty of parsing the page for prices. I guess one could look at how uc_aac or other modules do it, or there maybe meta-data to denote prices. But currently, I don't have the time to look into this.

==
KJ

jaybhancock’s picture

I've discovered a new issue with anonymous users.

The currency change works perfectly when logged in.

For an anonymous user, the currency switch works sometimes
* If I am viewing the cart, and use the block to switch currency, then it changes currency.
* Same for checkout process

However it doesn't work on the following pages:
* When I am viewing a category in the catalog, showing a listing of products.
* When I am viewing a product

The manner in which it is not working is as follows:
* Start in default currency (USD in my case)
* View catalog
* Change to other currency (CDN in my case)
* Result: the ajax shopping cart changes to CDN but the block shows the selector as "USD" and the prices in the catalog show USD prices.
* Then, if I click on a product, the pricing is in CDN, the block selector is CDN, and the cart are CDN.
* From that point forward, the catalog and products are in CDN.

Also:
* Start in default currency
* View a product
* Switch to other currency
* Same result - cart is correct while selector and pricing in product are not
* Click on catalog, then pricing, selector, and cart are all correct as before

Also:
* Start in Catalog in default currency
* switch currency (problem)
* change categories in catalog (problem persists)
* change categories again (problem not evident)
* change categories back and forth - some categories have the currency switched properly and some do not, and the same ones are consistent if you switch back and forth among them.

I tested with a regular shopping cart with ajax cart disabled, and same issue.
I have Ajax attributes turned off as well.
Caching - I have block caching turned off, and site caching on normal.

There's something funny with how the page load retrieves the value from the session for anonymous users. For product or catalog pages you switch on, the currency change does not apply. When you go to other product or catalog pages, some of them have the new selection and some do not. However it remembers which are which, so it seems to cache the value on a per-page basis.

The behaviour seems dependent on which page you choose to do the switch on.

Play with it here: http://healthcarebedding.com to see for yourself.

Let me know if you would like me to do anything to help you debug the issue.

jaybhancock’s picture

Is there anything I can do to help with the anonymous user issue?

sszawlim’s picture

doesn't work with the uc_coupon value.
Any advice on this.

Thx

Shane Birley’s picture

By the way, I realized I haven't posted to this thread for some time. This module works (with manual selection) to PayPal. I just updated to the latest Ubercart, reapplied the uc_paypal module hack/patch and it still functions fine passing the correct currency to PayPal.

I will catch up on the rest of the thread now... :)

dukem’s picture

FileSize
19.92 KB

I have reworked this code to support page cache.
See the attached archive and readme file.
Tested (and prepared patches) on Drupal drupal-6.22 and ubercart-6.x-2.7.

Ubercart must be patched in order this to work, patches are supplied.
Currently there are patches for PayPal and CyberSource payment methods.
Later I may add patches for uc_gift_certificate, uc_discounts_alt modules.

If you want patches for other payment methods please ask, and it would be great if you could also test them.
And you can make modifications yourself using PayPal or Cybersource as an example.

Considering cache support, it may be brutal but it works.
When caching is enabled, this module takes drupal page workflow from Drupal after hook_boot().
The cache logic is reworked so that pages are stored in the cache table with currency added to its cid.

Please test and comment.
Thanks!

voj’s picture

I will test out Dukem's post then I will post a feedback.

voj’s picture

After testing Dukem's code I have concluded that:

1. Multi-currency works as expected.
2. Some of the products that was previously created before patching up the code and enabling the Ubercart multi-currency module, there's a chance that the product will be broken. The SKU and sell price cannot be modified/save and stays blank. - Can anyone confirm it this?

dukem’s picture

I cannot confirm this. But i'm using an empty devel site with 1 product.
Also this module works on a production site and there were no such problems.
Can you post Drupal and Ubercart versions you are using?

voj’s picture

On my first test, I tested it out first on a fresh drupal site with 1 product.

Versions I used was:
Ubercart 6.x-2.9
Product Power Tools 6.x-1.12(to remove the sku and other fields)
Currency 6.x-1.3

I tried to edit the one product then after I save it, I tried to edit it again but the sku and the sell price dont save it to the database. To solve this I just have to recreate the product. I think the the Power tools conflicted with the code or something...

On my second test, I tested it out on a sandbox with more populated products.
Version I used was the same as above.

The second test worked but some of the sku of the products was removed, to solve this I just added an sku. I don't know what went wrong on my first installation.

We tried this in a production site the third time(duplicate of the 2nd site) and there were no problems and it worked!

[edit: may 22, 2012]
Sometimes there's 1 refresh delay before the currency applies right (applies from tests #1-3).
The problem is that whenever I tried to change the currency the uc_multi_currency_set_currency($currency);
won't apply after selecting it first, It will then apply after another page refresh.
[/edit: may 22, 2012]

In another hand we created a simple module that connects the Internationalization(multi language) module with the currency.
whenever the user clicks a country or language, the currency will also change.
If anyone is interested I will post the module here(not on the projects page of drupal because it's not an official version of ubercart).

dukem’s picture

Check if block cache is disabled (/admin/settings/performance), I don't remember exactly, might be an issue.

voj’s picture

I used the hook_init() to call the uc_multi_currency_set_currency()
I traced the values and It seems that uc_multi_currency_set_currency() applies the currency but it needs additional refresh can you enlighten me with block cache?

voj’s picture

Okay we solve the caching issue...
it seems that the user_save() was causing the problem.
here's my theory: when you use the user_save()(only if you are logged in) it saves your data to the database first. Then after another request it cache the data from the database to the global $user

After using user_save() make sure that the most changeable data is stored with the cache($global $user) only if you needed to see the changes immediately.

you can do it by overriding the global $user;

on the code
uc_multi_currency.module line 569:

568:   if ($user->uid) {
569:     user_save($user, array('uc_multi_currency_code' => $currency)); //saves it to the database but it needs to be cached immediately
++ $user->uc_multi_currency_code = $currency; // save to cache
570:  }
571:  uc_multi_currency_set_session_currency($currency);
AndreaD’s picture

Ok, I have been searching, and searching, and found these:

http://drupal.org/project/uc_currency_convert
http://drupal.org/project/currency_cck

I know you have been working with this long now, but are these modules, not useful?

dukem’s picture

Looks like the first one doesn't work with cache (anonymous users when cache enabled).
The second one has a bit different purpose as I understand.

javdich’s picture

FileSize
4.91 KB

I am having an issue with the currency selection block. It only shows the currency symbol, but not a currency name (CAD, USD, EUR). Has anyone else experienced this?

grey_’s picture

Seems broken on Ubercart 6.x-2.11. Anyone got updated code?

marinex’s picture

@ragnaewan

I would like try your module that connects the Internationalization, I would be glad if you post your module to this thread.

Thanks

Shane Birley’s picture

Status: Needs review » Closed (outdated)