Zen Cart Logo
Forums / Currencies & Sales Taxes, VAT, GST, etc. / Forcing default currency at checkout

Forcing default currency at checkout

Views: 8,115

Results 1 to 20 of 24
26 Nov 2015, 4:33 AM
#1
haroldf avatar

haroldf

New Zenner

Join Date:
Nov 2011
Location:
Brisbane, Australia
Posts:
10
Plugin Contributions:
0

Forcing default currency at checkout

I recently upgraded to 1.5.4. Wanting to offer customers the opportunity to see prices in their own currency, I installed the currencies sidebox. However, I need to process transactions in AUD only.

Some customers would select a currency but that selection remained throughout the checkout process and only the invoice total was shown in AUD. This also caused problems with PayPal registering as a currency conflict.

I searched for information on how to force the default currency at checkout and found that people had asked, but never seem to have received a solution. I know that you can stop the currencies sidebox from displaying during checkout, but that doesn't help if the wrong currency is active.

My solution was to modify one file: cart/includes/init_includes/init_currencies.php

I made two insertions. First insertion near the top of the code:

if (!defined('IS_ADMIN_FLAG'))
{
  die('Illegal Access');
}

// begin insertion 1 of 2

$force_default_currency = false;
$requested_page = $_SERVER['REQUEST_URI'];
// Does requested page contain the string 'checkout'?
// If so, then force currency to default
if (strpos($requested_page, 'checkout') !== false)
{
	$force_default_currency = true;
}

// end insertion 1

The second insertion is just before the end of the code:

// begin insertion 2 of 2

elseif ($force_default_currency)
{
	$_SESSION['currency'] = DEFAULT_CURRENCY;
  // redraw the page without the currency/language info in the URL
  if (isset($_GET['currency']) || isset($_GET['language'])) zen_redirect(zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language'))));

// end insertion 2
}

?>

This has solved my issue completely and my method may be helpful to others.

30 Nov 2015, 12:49 AM
#2
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Forcing default currency at checkout

Same can be achieved without a hack.

No matter how many currencies are visible/selectable on the front end, all you need to do in Admin > Modules > Payment > PayPal Express is to set

Transaction Currency
Only AUD

That's it, has worked for me since 2007

30 Nov 2015, 1:10 AM
#3
haroldf avatar

haroldf

New Zenner

Join Date:
Nov 2011
Location:
Brisbane, Australia
Posts:
10
Plugin Contributions:
0

Re: Forcing default currency at checkout

That is how my payment module is set.

As I said, it does put the final total in AUD but everything else in checkout is in the selected currency. Also, I cannot complete the transaction (I only authorise transactions at checkout) because PayPal senses a currency conflict. (I can, however, complete the transaction through my PayPal account rather than Zen's admin.)

I didn't have this issue with 1.3.9. I am sure it behaves as you suggest. However, I am happy with my hack.

19 Jan 2016, 7:50 PM
#4
spifflifkin avatar

spifflifkin

New Zenner

Join Date:
Aug 2011
Location:
Pacific NW
Posts:
28
Plugin Contributions:
0

Re: Forcing default currency at checkout

I am experiencing the same thing with a fresh install of 1.5.4. Is the hack the only way to fix this? 1.3.9 worked fine.

This is my setup.

PayPal Payments Pro (USA)
Attachment 15991

PayPal Express Checkout via Payflow Pro
Attachment 15992

Here is an order I received today
Attachment 15993

19 Jan 2016, 9:51 PM
#5
haroldf avatar

haroldf

New Zenner

Join Date:
Nov 2011
Location:
Brisbane, Australia
Posts:
10
Plugin Contributions:
0

Re: Forcing default currency at checkout

Is the hack the only way to fix this? In the absence of any other suggestions, I am assuming so.

19 Jan 2016, 9:58 PM
#6
spifflifkin avatar

spifflifkin

New Zenner

Join Date:
Aug 2011
Location:
Pacific NW
Posts:
28
Plugin Contributions:
0

Re: Forcing default currency at checkout

Right on. I'll give that a shot. Thanks!

5 Mar 2016, 3:09 AM
#7
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Forcing default currency at checkout

haroldf:

I recently upgraded to 1.5.4. Wanting to offer customers the opportunity to see prices in their own currency, I installed the currencies sidebox. However, I need to process transactions in AUD only.

Some customers would select a currency but that selection remained throughout the checkout process and only the invoice total was shown in AUD. This also caused problems with PayPal registering as a currency conflict.

I searched for information on how to force the default currency at checkout and found that people had asked, but never seem to have received a solution. I know that you can stop the currencies sidebox from displaying during checkout, but that doesn't help if the wrong currency is active.

My solution was to modify one file: cart/includes/init_includes/init_currencies.php

I made two insertions. First insertion near the top of the code:

if (!defined('IS_ADMIN_FLAG'))
{
die('Illegal Access');
}

// begin insertion 1 of 2

$force_default_currency = false;
$requested_page = $_SERVER['REQUEST_URI'];
// Does requested page contain the string 'checkout'?
// If so, then force currency to default
if (strpos($requested_page, 'checkout') !== false)
{
$force_default_currency = true;
}

// end insertion 1

> 
> The second insertion is just before the end of the code:
> 
> ```php
// begin insertion 2 of 2

elseif ($force_default_currency)
{
    $_SESSION['currency'] = DEFAULT_CURRENCY;
  // redraw the page without the currency/language info in the URL
  if (isset($_GET['currency']) || isset($_GET['language'])) zen_redirect(zen_href_link($current_page_base, zen_get_all_get_params(array('currency','language'))));

// end insertion 2
}

?>

This has solved my issue completely and my method may be helpful to others.

Ended up in need of your hack after installing the eWay payment module as my merchant facility only accepts order currency AUD.

Had no further issues after implementation of your code - thanks!

Frank

5 Mar 2016, 4:32 AM
#8
haroldf avatar

haroldf

New Zenner

Join Date:
Nov 2011
Location:
Brisbane, Australia
Posts:
10
Plugin Contributions:
0

Re: Forcing default currency at checkout

Hello Frank. Glad that it is helpful.

5 Mar 2016, 4:18 PM
#9
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Forcing default currency at checkout

Since the currency-conversion requirement is something enforced/required by your specific payment module/gateway, I recommend putting code into the payment module itself to handle the conversion during submission. That way the customer still sees the checkout in their own currency and you don't need to interfere with normal currency handling otherwise.

Here's how it's done in the Authorize.net AIM module: https://github.com/zencart/zencart/blob/v155/includes/modules/payment/authorizenet_aim.php#L396-L403
Obviously you'll need to adjust the specifics for however your gateway prepares its fields for transmission, but this shows you the basics of the calculation logic.

5 Mar 2016, 11:45 PM
#10
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Forcing default currency at checkout

DrByte:

Since the currency-conversion requirement is something enforced/required by your specific payment module/gateway, I recommend putting code into the payment module itself to handle the conversion during submission. That way the customer still sees the checkout in their own currency and you don't need to interfere with normal currency handling otherwise.

Here's how it's done in the Authorize.net AIM module: https://github.com/zencart/zencart/blob/v155/includes/modules/payment/authorizenet_aim.php#L396-L403
Obviously you'll need to adjust the specifics for however your gateway prepares its fields for transmission, but this shows you the basics of the calculation logic.

Excellent - thanks Doc!

6 Mar 2016, 12:38 AM
#11
haroldf avatar

haroldf

New Zenner

Join Date:
Nov 2011
Location:
Brisbane, Australia
Posts:
10
Plugin Contributions:
0

Re: Forcing default currency at checkout

My preference is to show at checkout the currency in which the charge will be transacted. This gives the customer an indication that a conversion to their own currency will take place, hence they will not be too surprised if the charged amount is not in perfect alignment with the checkout's estimated amount. But if that's not an issue, then DrByte's is a good option.

6 Mar 2016, 4:19 AM
#12
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Forcing default currency at checkout

haroldf:

My preference is to show at checkout the currency in which the charge will be transacted. This gives the customer an indication that a conversion to their own currency will take place, hence they will not be too surprised if the charged amount is not in perfect alignment with the checkout's estimated amount. But if that's not an issue, then DrByte's is a good option.

Fixed it without hacking core code (as per DrByte's suggestion).

The shopping cart page(s) still show the chosen currency. Added a few language defines and displayed their relevant content on the checkout_confirmation page. These language defines won't show up if the default currency AUD is selceted - and neither they should show up in this instance as there is nothing to convert.

See screenie:

Attachment 16086

3 Apr 2016, 12:08 AM
#14
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Forcing default currency at checkout

I'm looking for a similar solution to a slightly different problem. The (ZC155) store wants to price its goods in US dollars, but only display them in GB Pounds - not just at the checkout, but throughout the store.

It works just fine if the customer chooses GBP in the currency drop-down, but I don't want them to have that option: I want that setting to default to GBP even though the underlying store Default Currency is USD. Preferably without showing the currency box at all.

How can I do this? What does that Currency box change when the customer alters it? How can I "pre-alter" it?

4 Apr 2016, 1:34 AM
#15
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Forcing default currency at checkout

hairydog:

I'm looking for a similar solution to a slightly different problem. The (ZC155) store wants to price its goods in US dollars, but only display them in GB Pounds - not just at the checkout, but throughout the store.

It works just fine if the customer chooses GBP in the currency drop-down, but I don't want them to have that option: I want that setting to default to GBP even though the underlying store Default Currency is USD. Preferably without showing the currency box at all.

How can I do this? What does that Currency box change when the customer alters it? How can I "pre-alter" it?

You simply set the "default currency" (in Localization->Currencies) to be GBP instead of USD.
And then you have to manually set currency-exchange rates (because the auto-updater of exchange rates is based on the default currency).

4 Apr 2016, 11:26 AM
#16
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Forcing default currency at checkout

You are missing the point, both here and the other place where the thread has been closed so I can't reply there.

If I change the default currency to GBP, all the prices are stored in GBP. That would be no use at all. The client wants to price in dollars, sell in pounds.

I have not been able to get it to work as it should, but I've found a workaround: I have created a new language called UKEnglish, which is simply an exact copy of English. Selecting this as the default store language and then removing the language English has made the system work as I think it is supposed to:

The prices are stored in USD, the currency lookups work automatically on a cron job (though I had to read the php code to find out how to set it up - is there no documentation for this?)

The default language is set to UKEnglish and its default currency is GBP. Customers are now shown prices in GBP.

Clearly there is some hard-coded default somewhere in ZC155 that sets the currency to USD if the language is English, ignoring the settings in the language files. By setting a different language I've bypassed this bug. It would be better to find the bug and fix it, but I don't know how.

The only downside to my workaround is that for any addons I install, I need to rename the English directory before installing. The big advantage is that a future ZC update won't overwrite my Admin english.php settings.

4 Apr 2016, 4:32 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Forcing default currency at checkout

hairydog:

Clearly there is some hard-coded default somewhere in ZC155 that sets the currency to USD if the language is English, ignoring the settings in the language files. By setting a different language I've bypassed this bug. It would be better to find the bug and fix it, but I don't know how.
Not aware of any such "hard-coded" thing in this regard.

4 Apr 2016, 5:06 PM
#18
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Forcing default currency at checkout

I'm sure there shouldn't be, but my experience of the bug and the successful workaround suggests that there is!

4 Apr 2016, 5:41 PM
#19
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,065
Plugin Contributions:
56

Re: Forcing default currency at checkout

@hairydog: What's your store's setting for Configuration->My Store->Switch To Default Language Currency?

4 Apr 2016, 5:47 PM
#20
hairydog avatar

hairydog

Zen Follower

Join Date:
Sep 2006
Posts:
165
Plugin Contributions:
0

Re: Forcing default currency at checkout

True .