Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Automatic currency selection


Eric_SIN

Recommended Posts

Hello,

 

I'm looking for a contrib which automatically pre-selects the currency depending on the location of the visitor.

I would for example want my shop to show all prices automatically in Euro if a visitor from europe surfs to our page. if from US and rest of world I want to show USD.

 

Is this possible?

From the statistics of my web shop I can roughly see where people are coming from so there must be a possibility to link this to oscommerce to enable the location detection.

 

Any idea?

 

Thanks !!

Link to comment
Share on other sites

I dunno of any contribution doins this as such but I have used in the past the following code, using the geoip library.

If you dont altready use this library, install it you will find info about it in the whois online enhancement contrib for example

Then:

 

Putr GEOIP.DAT and .inc in catalogue/includes

In catalogue/includes/application_top.php

Change

 

 

// currency
if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {
  if (!tep_session_is_registered('currency')) tep_session_register('currency');
  if (isset($HTTP_GET_VARS['currency'])) {
 if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
  } else {
 $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
  }
}

 

$by

 

 

// currency
if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {
  if (!tep_session_is_registered('currency')) tep_session_register('currency');
  if (isset($HTTP_GET_VARS['currency'])) {
 if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
  } else {
//	  $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
require(DIR_WS_INCLUDES . 'geoip.inc');
$gi = geoip_open(DIR_WS_INCLUDES . 'GeoIP.dat',GEOIP_STANDARD);
$country = geoip_country_code_by_addr($gi, $ip_address);
if ($country = 'CH' || $country='ch') {
$currency = 'CHF';
}
  }
}

 

 

In the exemple above, if someone with a swiss ip login then the currency change to Swiss Franc. You will need to hardcode more currency changes if you need them

 

This ocul dbe the based for a contribution where the country table is associated with its currency, which would stop this code having to hardcode it all

LEt me know how it goes

 

Ca a l air de marcher sur ma base de test, si erreur faites moi signe

Link to comment
Share on other sites

I dunno of any contribution doins this as such but I have used in the past the following code, using the geoip library.

If you dont altready use this library, install it you will find info about it in the whois online enhancement contrib for example

Then:

 

Putr GEOIP.DAT and .inc in catalogue/includes

In catalogue/includes/application_top.php

Change

// currency
if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {
  if (!tep_session_is_registered('currency')) tep_session_register('currency');
  if (isset($HTTP_GET_VARS['currency'])) {
 if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
  } else {
 $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
  }
}

 

$by

// currency
if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || ( (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') && (LANGUAGE_CURRENCY != $currency) ) ) {
  if (!tep_session_is_registered('currency')) tep_session_register('currency');
  if (isset($HTTP_GET_VARS['currency'])) {
 if (!$currency = tep_currency_exists($HTTP_GET_VARS['currency'])) $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
  } else {
//	  $currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
require(DIR_WS_INCLUDES . 'geoip.inc');
$gi = geoip_open(DIR_WS_INCLUDES . 'GeoIP.dat',GEOIP_STANDARD);
$country = geoip_country_code_by_addr($gi, $ip_address);
if ($country = 'CH' || $country='ch') {
$currency = 'CHF';
}
  }
}

In the exemple above, if someone with a swiss ip login then the currency change to Swiss Franc. You will need to hardcode more currency changes if you need them

 

This ocul dbe the based for a contribution where the country table is associated with its currency, which would stop this code having to hardcode it all

LEt me know how it goes

 

Ca a l air de marcher sur ma base de test, si erreur faites moi signe

 

 

I've been looking for something that will automaticly convert currency based on where the person is, and this seems like an easier way to do it. Could you explain your code a bit? I just tried to install it, but I'm not seeing any changes. I want the default currency to be USD, but if a customer is from Canada, then it would convert it to CAD. Do I simply change CH and ch to CA and ca, and CHF to CAD?

 

Mark

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...