Jump to content
seb1188

New: Auto change currency ased on customer's IPA location

Recommended Posts

Well this is my first ever contribution. Wasn't sure where to post about it so I thought I'd just stick it in General...

If something similar already exists somewhere then my apologies, but I couldn't find it anywhere myself.

 

Find it here:

http://addons.oscommerce.com/info/6450

 

 

What it does:

It looks up the location of a customer's IP address and changes the currency to wahtever the database says belongs to that country, using 2 letter ISO codes. Once set, the use of sessions means the user can still manually change currency, as it won't query the IP address again after the first page request per session.

 

It uses an API from http://www.wipmani.com

 

To see it working, visit my store at http://www.thesebweb.com

If you now go there again, but using a proxy, you'll see the currency won't change until you clear your sessions and cookies. Then it'll change to the currency of the country of the proxy.

Edited by seb1188

osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

This is absolutly a great great idea. I have been looking for this kind of contribution for a very long time, with no success.

I'm glad you did it.

My question is : Does the customer has to being logged already or your contribution works also for simple visitors ?

 

I build an osc commerce site with "different currency = different prices "

The point for me is to be able to display the proper currency according to the IP address of the "visitor" who doesn't need to know how much do I sell the same product in another country.

 

Your contribution does that ?

Share this post


Link to post
Share on other sites
This is absolutly a great great idea. I have been looking for this kind of contribution for a very long time, with no success.

I'm glad you did it.

My question is : Does the customer has to being logged already or your contribution works also for simple visitors ?

 

I build an osc commerce site with "different currency = different prices "

The point for me is to be able to display the proper currency according to the IP address of the "visitor" who doesn't need to know how much do I sell the same product in another country.

 

Your contribution does that ?

 

 

Currency is set for all visitors, not just those logged in.

In the future I'd like to set it up so that if a customer is logged in it takes their location from their address in the database as well, but for now it's purely IP based.

 

If you've removed the currency infobox then it should only ever display one currency to a customer (unless they actively type ?currency=EUR into the address bar or something). If the prices are different in different currencies (rather than a simple exchange rate), do a back up of your site before you try to install - this uses the original osCommerce code with a bit added in the middle, so I don't know how compatible it'll be with a store that's set up to charge different prices altogether for a different currency. It should be fine though.

 

Also bear in mind the IP to location check will only be 99.9% accurate, not 100%... that's fine for most store owners, as visitors can change it manually, but for something more accurate you might want to consider a paid for services that might be updated more often.


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

Just to clarify the final steps in the installation instructions:, as there has been some confusion:

 

By "change the countries_currencyid field for any countries that you wish to have a different currency for", I mean you will have to look at your existing table, the "countries" table, and manually (or with SQL commands) change the value of the "countries_currencyid" field to the 3 letter currency that you want to be associated with that country.

 

 

For example:

 

Let's say this is your "countries" table, and what it looks a bit like after using my SQL
command to add the new field/column:

countries_Country_id    countries_Country      Countries_currencyid
1                       United States          USD
2                       United Kingdom         USD
3                       Canada                 USD
4                       France                 USD

As you can see, all countries are currently associated with USD, so they will all display
in dollars. You will need to change the value of the currencyid *for each individual
country* to whatever currency you want it to use. The first thing I did was to change
United Kingdom to GBP. I did this in phpMyAdmin. Then I changed Canada to CAD and France
to EUR. Of course, you will have to manually change the value in that field/column to the
currency you want to use for that country.

The outcome should be something like this:
countries_Country_id    countries_Country      Countries_currencyid
1                       United States          USD
2                       United Kingdom         GBP
3                       Canada                 CAD
4                       France                 EUR

Sadly I couldn't have the module set up to do this for you, as I had no idea what
currencies/countries different osCommerce users would want to use. Remember to only use
currencies that you have set up in your admin countrols!


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

hello friends

i installed the contribution, but now all i get is a white page! with no errors or anything.

could someone help me and tell me whats wrong.

i have attached the code below

 

<?php
/*
 $Id: $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2007 osCommerce

 Released under the GNU General Public License
*/

// start the timer for the page parse time log
 define('PAGE_PARSE_START_TIME', microtime());

// set the level of error reporting
 error_reporting(E_ALL & ~E_NOTICE);

// check support for register_globals
 if (function_exists('ini_get') && (ini_get('register_globals') == false) && (PHP_VERSION < 4.3) ) {
exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory. Please use PHP 4.3+ if register_globals cannot be enabled on the server.');
 }

// Set the local configuration parameters - mainly for developers
 if (file_exists('includes/local/configure.php')) include('includes/local/configure.php');

// include server parameters
 require('includes/configure.php');

 if (strlen(DB_SERVER) < 1) {
if (is_dir('install')) {
  header('Location: install/index.php');
}
 }

// define the project version
 define('PROJECT_VERSION', 'osCommerce Online Merchant v2.2 RC1');

// some code to solve compatibility issues
 require(DIR_WS_FUNCTIONS . 'compatibility.php');

// set the type of request (secure or not)
 $request_type = (getenv('HTTPS') == 'on') ? 'SSL' : 'NONSSL';

// set php_self in the local scope
 if (!isset($PHP_SELF)) $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];

 if ($request_type == 'NONSSL') {
define('DIR_WS_CATALOG', DIR_WS_HTTP_CATALOG);
 } else {
define('DIR_WS_CATALOG', DIR_WS_HTTPS_CATALOG);
 }

// include the list of project filenames
 require(DIR_WS_INCLUDES . 'filenames.php');

// include the list of project database tables
 require(DIR_WS_INCLUDES . 'database_tables.php');

// customization for the design layout
//  define('BOX_WIDTH', 125);  how wide the boxes should be in pixels (default: 125)

// include the database functions
 require(DIR_WS_FUNCTIONS . 'database.php');

// make a connection to the database... now
 tep_db_connect() or die('Unable to connect to database server!');

// set the application parameters
 $configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
 while ($configuration = tep_db_fetch_array($configuration_query)) {
define($configuration['cfgKey'], $configuration['cfgValue']);
 }

// if gzip_compression is enabled, start to buffer the output
 if ( (GZIP_COMPRESSION == 'true') && ($ext_zlib_loaded = extension_loaded('zlib')) && (PHP_VERSION >= '4') ) {
if (($ini_zlib_output_compression = (int)ini_get('zlib.output_compression')) < 1) {
  if (PHP_VERSION >= '4.0.4') {
	ob_start('ob_gzhandler');
  } else {
	include(DIR_WS_FUNCTIONS . 'gzip_compression.php');
	ob_start();
	ob_implicit_flush();
  }
} else {
  ini_set('zlib.output_compression_level', GZIP_LEVEL);
}
 }

// set the HTTP GET parameters manually if search_engine_friendly_urls is enabled
 if (SEARCH_ENGINE_FRIENDLY_URLS == 'true') {
if (strlen(getenv('PATH_INFO')) > 1) {
  $GET_array = array();
  $PHP_SELF = str_replace(getenv('PATH_INFO'), '', $PHP_SELF);
  $vars = explode('/', substr(getenv('PATH_INFO'), 1));
  for ($i=0, $n=sizeof($vars); $i<$n; $i++) {
	if (strpos($vars[$i], '[]')) {
	  $GET_array[substr($vars[$i], 0, -2)][] = $vars[$i+1];
	} else {
	  $HTTP_GET_VARS[$vars[$i]] = $vars[$i+1];
	}
	$i++;
  }

  if (sizeof($GET_array) > 0) {
	while (list($key, $value) = each($GET_array)) {
	  $HTTP_GET_VARS[$key] = $value;
	}
  }
}
 }

// define general functions used application-wide
 require(DIR_WS_FUNCTIONS . 'general.php');
 require(DIR_WS_FUNCTIONS . 'html_output.php');

// set the cookie domain
 $cookie_domain = (($request_type == 'NONSSL') ? HTTP_COOKIE_DOMAIN : HTTPS_COOKIE_DOMAIN);
 $cookie_path = (($request_type == 'NONSSL') ? HTTP_COOKIE_PATH : HTTPS_COOKIE_PATH);

// include cache functions if enabled
 if (USE_CACHE == 'true') include(DIR_WS_FUNCTIONS . 'cache.php');

// include shopping cart class
 require(DIR_WS_CLASSES . 'shopping_cart.php');

// include navigation history class
 require(DIR_WS_CLASSES . 'navigation_history.php');

// check if sessions are supported, otherwise use the php3 compatible session class
 if (!function_exists('session_start')) {
define('PHP_SESSION_NAME', 'osCsid');
define('PHP_SESSION_PATH', $cookie_path);
define('PHP_SESSION_DOMAIN', $cookie_domain);
define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY);

include(DIR_WS_CLASSES . 'sessions.php');
 }

// define how the session functions will be used
 require(DIR_WS_FUNCTIONS . 'sessions.php');

// set the session name and save path
 tep_session_name('osCsid');
 tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
  if (function_exists('session_set_cookie_params')) {
session_set_cookie_params(0, $cookie_path, $cookie_domain);
 } elseif (function_exists('ini_set')) {
ini_set('session.cookie_lifetime', '0');
ini_set('session.cookie_path', $cookie_path);
ini_set('session.cookie_domain', $cookie_domain);
 }

// set the session ID if it exists
  if (isset($HTTP_POST_VARS[tep_session_name()])) {
 tep_session_id($HTTP_POST_VARS[tep_session_name()]);
  } elseif ( ($request_type == 'SSL') && isset($HTTP_GET_VARS[tep_session_name()]) ) {
 tep_session_id($HTTP_GET_VARS[tep_session_name()]);
  }

// start the session
 $session_started = false;
 if (SESSION_FORCE_COOKIE_USE == 'True') {
tep_setcookie('cookie_test', 'please_accept_for_session', time()+60*60*24*30, $cookie_path, $cookie_domain);

if (isset($HTTP_COOKIE_VARS['cookie_test'])) {
  tep_session_start();
  $session_started = true;
}
 } elseif (SESSION_BLOCK_SPIDERS == 'True') {
$user_agent = strtolower(getenv('HTTP_USER_AGENT'));
$spider_flag = false;

if (tep_not_null($user_agent)) {
  $spiders = file(DIR_WS_INCLUDES . 'spiders.txt');

  for ($i=0, $n=sizeof($spiders); $i<$n; $i++) {
	if (tep_not_null($spiders[$i])) {
	  if (is_integer(strpos($user_agent, trim($spiders[$i])))) {
		$spider_flag = true;
		break;
	  }
	}
  }
}

if ($spider_flag == false) {
  tep_session_start();
  $session_started = true;
}
 } else {
tep_session_start();
$session_started = true;
 }

 if ( ($session_started == true) && (PHP_VERSION >= 4.3) && function_exists('ini_get') && (ini_get('register_globals') == false) ) {
extract($_SESSION, EXTR_OVERWRITE+EXTR_REFS);
 }

// set SID once, even if empty
 $SID = (defined('SID') ? SID : '');

// verify the ssl_session_id if the feature is enabled
 if ( ($request_type == 'SSL') && (SESSION_CHECK_SSL_SESSION_ID == 'True') && (ENABLE_SSL == true) && ($session_started == true) ) {
$ssl_session_id = getenv('SSL_SESSION_ID');
if (!tep_session_is_registered('SSL_SESSION_ID')) {
  $SESSION_SSL_ID = $ssl_session_id;
  tep_session_register('SESSION_SSL_ID');
}

if ($SESSION_SSL_ID != $ssl_session_id) {
  tep_session_destroy();
  tep_redirect(tep_href_link(FILENAME_SSL_CHECK));
}
 }

// verify the browser user agent if the feature is enabled
 if (SESSION_CHECK_USER_AGENT == 'True') {
$http_user_agent = getenv('HTTP_USER_AGENT');
if (!tep_session_is_registered('SESSION_USER_AGENT')) {
  $SESSION_USER_AGENT = $http_user_agent;
  tep_session_register('SESSION_USER_AGENT');
}

if ($SESSION_USER_AGENT != $http_user_agent) {
  tep_session_destroy();
  tep_redirect(tep_href_link(FILENAME_LOGIN));
}
 }

// verify the IP address if the feature is enabled
 if (SESSION_CHECK_IP_ADDRESS == 'True') {
$ip_address = tep_get_ip_address();
if (!tep_session_is_registered('SESSION_IP_ADDRESS')) {
  $SESSION_IP_ADDRESS = $ip_address;
  tep_session_register('SESSION_IP_ADDRESS');
}

if ($SESSION_IP_ADDRESS != $ip_address) {
  tep_session_destroy();
  tep_redirect(tep_href_link(FILENAME_LOGIN));
}
 }

// create the shopping cart & fix the cart if necesary
 if (tep_session_is_registered('cart') && is_object($cart)) {
if (PHP_VERSION < 4) {
  $broken_cart = $cart;
  $cart = new shoppingCart;
  $cart->unserialize($broken_cart);
}
 } else {
tep_session_register('cart');
$cart = new shoppingCart;
 }

// include currencies class and create an instance
 require(DIR_WS_CLASSES . 'currencies.php');
 $currencies = new currencies();

// include the mail classes
 require(DIR_WS_CLASSES . 'mime.php');
 require(DIR_WS_CLASSES . 'email.php');

// set the language
 if (!tep_session_is_registered('language') || isset($HTTP_GET_VARS['language'])) {
if (!tep_session_is_registered('language')) {
  tep_session_register('language');
  tep_session_register('languages_id');
}

include(DIR_WS_CLASSES . 'language.php');
$lng = new language();

if (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) {
  $lng->set_language($HTTP_GET_VARS['language']);
} else {
  $lng->get_browser_language();
}

$language = $lng->language['directory'];
$languages_id = $lng->language['id'];
 }

// include the language translations
 require(DIR_WS_LANGUAGES . $language . '.php');

// 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 {
/*Auto change currencies update from Koonuki Wear
HTTP://WWW.THESEBWEB.COM
Please visit our website if you like this contribution.*/	

//INSERT YOUR DOMAIN URL HERE
$site_name = "http://www.parsuaclothing.com";

//Define function to get the 2 letter code of the country customer is from
function getUserCountry() {
$url = 'http://api.wipmania.com/'.$_SERVER['REMOTE_ADDR'].'?'.$site_name;
$ch = curl_init();
$headers = "Typ: phpcurl\r\n";
$headers .= "Ver: 1.0\r\n";
$headers .= "Connection: Close\r\n\r\n";
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($headers));
$content = curl_exec($ch);
curl_close($ch);
return $content;
};


//set variable to location
$location = getUserCountry();

//since it has not been determined, find the currency it needs to be changed to
$currency_id_result=tep_db_query("SELECT countries_currencyid FROM countries WHERE countries_iso_code_2='".$location."'");
while($currency_row=tep_db_fetch_array($currency_id_result)) {
$currency_id=$currency_row['countries_currencyid'];
};


//create session variable to show that it has now been determined
$currency=$currency_id;
$_SESSION['locationset']=$location;
$_SESSION['currency']=$currency;

//END OF ALTERATIONS
}
 }

// navigation history
 if (tep_session_is_registered('navigation')) {
if (PHP_VERSION < 4) {
  $broken_navigation = $navigation;
  $navigation = new navigationHistory;
  $navigation->unserialize($broken_navigation);
}
 } else {
tep_session_register('navigation');
$navigation = new navigationHistory;
 }
 $navigation->add_current_page();

// Shopping cart actions
 if (isset($HTTP_GET_VARS['action'])) {
// redirect the customer to a friendly cookie-must-be-enabled page if cookies are disabled
if ($session_started == false) {
  tep_redirect(tep_href_link(FILENAME_COOKIE_USAGE));
}

if (DISPLAY_CART == 'true') {
  $goto =  FILENAME_SHOPPING_CART;
  $parameters = array('action', 'cPath', 'products_id', 'pid');
} else {
  $goto = basename($PHP_SELF);
  if ($HTTP_GET_VARS['action'] == 'buy_now') {
	$parameters = array('action', 'pid', 'products_id');
  } else {
	$parameters = array('action', 'pid');
  }
}
switch ($HTTP_GET_VARS['action']) {
  // customer wants to update the product quantity in their shopping cart
  case 'update_product' : for ($i=0, $n=sizeof($HTTP_POST_VARS['products_id']); $i<$n; $i++) {
							if (in_array($HTTP_POST_VARS['products_id'][$i], (is_array($HTTP_POST_VARS['cart_delete']) ? $HTTP_POST_VARS['cart_delete'] : array()))) {
							  $cart->remove($HTTP_POST_VARS['products_id'][$i]);
							} else {
							  if (PHP_VERSION < 4) {
								// if PHP3, make correction for lack of multidimensional array.
								reset($HTTP_POST_VARS);
								while (list($key, $value) = each($HTTP_POST_VARS)) {
								  if (is_array($value)) {
									while (list($key2, $value2) = each($value)) {
									  if (ereg ("(.*)\]\[(.*)", $key2, $var)) {
										$id2[$var[1]][$var[2]] = $value2;
									  }
									}
								  }
								}
								$attributes = ($id2[$HTTP_POST_VARS['products_id'][$i]]) ? $id2[$HTTP_POST_VARS['products_id'][$i]] : '';
							  } else {
								$attributes = ($HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]]) ? $HTTP_POST_VARS['id'][$HTTP_POST_VARS['products_id'][$i]] : '';
							  }
							  $cart->add_cart($HTTP_POST_VARS['products_id'][$i], $HTTP_POST_VARS['cart_quantity'][$i], $attributes, false);
							}
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
  // customer adds a product from the products page
  case 'add_product' :	if (isset($HTTP_POST_VARS['products_id']) && is_numeric($HTTP_POST_VARS['products_id'])) {
							$cart->add_cart($HTTP_POST_VARS['products_id'], $cart->get_quantity(tep_get_uprid($HTTP_POST_VARS['products_id'], $HTTP_POST_VARS['id']))+1, $HTTP_POST_VARS['id']);
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
  // performed by the 'buy now' button in product listings and review page
  case 'buy_now' :		if (isset($HTTP_GET_VARS['products_id'])) {
							if (tep_has_product_attributes($HTTP_GET_VARS['products_id'])) {
							  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['products_id']));
							} else {
							  $cart->add_cart($HTTP_GET_VARS['products_id'], $cart->get_quantity($HTTP_GET_VARS['products_id'])+1);
							}
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
  case 'notify' :		 if (tep_session_is_registered('customer_id')) {
							if (isset($HTTP_GET_VARS['products_id'])) {
							  $notify = $HTTP_GET_VARS['products_id'];
							} elseif (isset($HTTP_GET_VARS['notify'])) {
							  $notify = $HTTP_GET_VARS['notify'];
							} elseif (isset($HTTP_POST_VARS['notify'])) {
							  $notify = $HTTP_POST_VARS['notify'];
							} else {
							  tep_redirect(tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'notify'))));
							}
							if (!is_array($notify)) $notify = array($notify);
							for ($i=0, $n=sizeof($notify); $i<$n; $i++) {
							  $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $notify[$i] . "' and customers_id = '" . $customer_id . "'");
							  $check = tep_db_fetch_array($check_query);
							  if ($check['count'] < 1) {
								tep_db_query("insert into " . TABLE_PRODUCTS_NOTIFICATIONS . " (products_id, customers_id, date_added) values ('" . $notify[$i] . "', '" . $customer_id . "', now())");
							  }
							}
							tep_redirect(tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'notify'))));
						  } else {
							$navigation->set_snapshot();
							tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
						  }
						  break;
  case 'notify_remove' :  if (tep_session_is_registered('customer_id') && isset($HTTP_GET_VARS['products_id'])) {
							$check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");
							$check = tep_db_fetch_array($check_query);
							if ($check['count'] > 0) {
							  tep_db_query("delete from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . $HTTP_GET_VARS['products_id'] . "' and customers_id = '" . $customer_id . "'");
							}
							tep_redirect(tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action'))));
						  } else {
							$navigation->set_snapshot();
							tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
						  }
						  break;
  case 'cust_order' :	 if (tep_session_is_registered('customer_id') && isset($HTTP_GET_VARS['pid'])) {
							if (tep_has_product_attributes($HTTP_GET_VARS['pid'])) {
							  tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $HTTP_GET_VARS['pid']));
							} else {
							  $cart->add_cart($HTTP_GET_VARS['pid'], $cart->get_quantity($HTTP_GET_VARS['pid'])+1);
							}
						  }
						  tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
						  break;
}
 }

// include the who's online functions
 require(DIR_WS_FUNCTIONS . 'whos_online.php');
 tep_update_whos_online();

// include the password crypto functions
 require(DIR_WS_FUNCTIONS . 'password_funcs.php');

// include validation functions (right now only email address)
 require(DIR_WS_FUNCTIONS . 'validations.php');

// split-page-results
 require(DIR_WS_CLASSES . 'split_page_results.php');

// infobox
 require(DIR_WS_CLASSES . 'boxes.php');

// auto activate and expire banners
 require(DIR_WS_FUNCTIONS . 'banner.php');
 tep_activate_banners();
 tep_expire_banners();

// auto expire special products
 require(DIR_WS_FUNCTIONS . 'specials.php');
 tep_expire_specials();

// calculate category path
 if (isset($HTTP_GET_VARS['cPath'])) {
$cPath = $HTTP_GET_VARS['cPath'];
 } elseif (isset($HTTP_GET_VARS['products_id']) && !isset($HTTP_GET_VARS['manufacturers_id'])) {
$cPath = tep_get_product_path($HTTP_GET_VARS['products_id']);
 } else {
$cPath = '';
 }

 if (tep_not_null($cPath)) {
$cPath_array = tep_parse_category_path($cPath);
$cPath = implode('_', $cPath_array);
$current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
 } else {
$current_category_id = 0;
 }

// include the breadcrumb class and start the breadcrumb trail
 require(DIR_WS_CLASSES . 'breadcrumb.php');
 $breadcrumb = new breadcrumb;

 $breadcrumb->add(HEADER_TITLE_TOP, HTTP_SERVER);
 $breadcrumb->add(HEADER_TITLE_CATALOG, tep_href_link(FILENAME_DEFAULT));

// add category names or the manufacturer name to the breadcrumb trail
 if (isset($cPath_array)) {
for ($i=0, $n=sizeof($cPath_array); $i<$n; $i++) {
  $categories_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . (int)$cPath_array[$i] . "' and language_id = '" . (int)$languages_id . "'");
  if (tep_db_num_rows($categories_query) > 0) {
	$categories = tep_db_fetch_array($categories_query);
	$breadcrumb->add($categories['categories_name'], tep_href_link(FILENAME_DEFAULT, 'cPath=' . implode('_', array_slice($cPath_array, 0, ($i+1)))));
  } else {
	break;
  }
}
 } elseif (isset($HTTP_GET_VARS['manufacturers_id'])) {
$manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "'");
if (tep_db_num_rows($manufacturers_query)) {
  $manufacturers = tep_db_fetch_array($manufacturers_query);
  $breadcrumb->add($manufacturers['manufacturers_name'], tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id']));
}
 }

// add the products model to the breadcrumb trail
 if (isset($HTTP_GET_VARS['products_id'])) {
$model_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
if (tep_db_num_rows($model_query)) {
  $model = tep_db_fetch_array($model_query);
  $breadcrumb->add($model['products_model'], tep_href_link(FILENAME_PRODUCT_INFO, 'cPath=' . $cPath . '&products_id=' . $HTTP_GET_VARS['products_id']));
}
 }

// initialize the message stack for output messages
 require(DIR_WS_CLASSES . 'message_stack.php');
 $messageStack = new messageStack;

// set which precautions should be checked
 define('WARN_INSTALL_EXISTENCE', 'true');
 define('WARN_CONFIG_WRITEABLE', 'true');
 define('WARN_SESSION_DIRECTORY_NOT_WRITEABLE', 'true');
 define('WARN_SESSION_AUTO_START', 'true');
 define('WARN_DOWNLOAD_DIRECTORY_NOT_READABLE', 'true');
?>

Share this post


Link to post
Share on other sites
hello friends

i installed the contribution, but now all i get is a white page! with no errors or anything.

could someone help me and tell me whats wrong.

i have attached the code below

 

 

That's very strange. I can't see anything wrong with your copy of my code. If all you did was stick the currency bit in there shouldn't be any problems.

 

Do you have any other currency related contributions installed? Or any contributions that find customer's countries? It's possible there's a conflict, but that shouldn't give a blank page.

 

Sometimes I get a blank page if it didn't upload correctly. Try uploading it again.

 

Otherwise ask in General Support, someone more knowledgeable might be able to help, as I don't think this error relates directly to this contribution.


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

This is a great little add-on, exactly what I was looking for- easy to install and works as advertised. I'll definitely stand you a pint, Sebastian.

 

And best of luck with the tee shirts. They look great! (We have a small chain of clothing shops so I do appreciate a good design when I see one.)

Share this post


Link to post
Share on other sites

Hello!

 

I am trying to install this mod. I am running osC version 2.2 rc2a

 

The instructions state: 'If you look at your "Countries" table in your database, you will need to change the

countries_currencyid field for any countries that you wish to have a different currency for.'

 

My "Countries" table doesn't have a countries_currencyid field.

Fields in "Countries" are:

countries_id countries_name countries_iso_code_2 countries_iso_code_3 address_format_id

 

However, a countries_currencyid field is in the "Currencies" table.

Fields here are:

currencies_id title code symbol_left symbol_right decimal_point thousands_point decimal_places value last_updated

 

In both tables the first field (countries_id and currencies_id) is set to auto_increment.

 

I am not quite sure how this would work now, could you give me a hint? Let me know if you need any further info, bearing in mind that I am not too clever with mysql and/or php.

 

Thanks

Edited by Hugbog

Keyboard failure - press F1 to continue

Share this post


Link to post
Share on other sites

Nil points for being stupid!

 

Didn't read the instructions properly where it says:

 

... insert it into your database: ALTER TABLE `countries` ADD `countries_currencyid` VARCHAR(3) DEFAULT 'GBP' NOT NULL;

 

Easy!

 

I shall curl up in a corner (mentally, not literally) and feel stupid for today, whilst changing currencies manually.

 

TTFN

Edited by Hugbog

Keyboard failure - press F1 to continue

Share this post


Link to post
Share on other sites

Hello,

 

We limited our countries to EU countires. Visitors from other countries will get all prices with 0. Do you have a fix? like if the ip is from a country not in the database then use default value.

 

Thanks :)

Share this post


Link to post
Share on other sites

Hi

 

I have been using this great Contribution on a few sites all working perfectly.

 

Does anybody know if there is a simular contribution for the shipping country, i currently have UK as my default shipping country which atracts VAT (shown as inclusive) but if someone from say US visits there is no VAT but until the client changes the shipping address from the default UK its still there.

 

Thanks for any pointers, could this contrib be modfied for this?

 

David


David

Share this post


Link to post
Share on other sites

The contribution pulls the visitors country from an external IP->country database and outputs the country. It then goes on to look up the currency in a n internal table

 

If you look into the code a bit (it's been far too long for me to remember) you'll see the variable that it stores the country code as. You could use that very easily to perform any operation that needs to know the visitor's country. As long as other uses of it come after this contribution's code on a page, it'll work. I guess the easiest way might be to put an if statement in with the bit of osCommerce code that decides whether or not to add VAT.

 

 

Hi

 

I have been using this great Contribution on a few sites all working perfectly.

 

Does anybody know if there is a simular contribution for the shipping country, i currently have UK as my default shipping country which atracts VAT (shown as inclusive) but if someone from say US visits there is no VAT but until the client changes the shipping address from the default UK its still there.

 

Thanks for any pointers, could this contrib be modfied for this?

 

David


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

I'm not sure what you're asking, but if there isn't a "fail safe" in there already that gives a default if all else fails then that's an issue worth addressing urgently!

 

Hello,

 

We limited our countries to EU countires. Visitors from other countries will get all prices with 0. Do you have a fix? like if the ip is from a country not in the database then use default value.

 

Thanks :)


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

I'm not sure what you're asking, but if there isn't a "fail safe" in there already that gives a default if all else fails then that's an issue worth addressing urgently!

 

 

We are seeing the same thing. Very often, our visitors report the price of $0. It started happening since we installed the contribution.

Share this post


Link to post
Share on other sites

We are seeing the same thing. Very often, our visitors report the price of $0. It started happening since we installed the contribution.

 

 

Did you change the default currency as per installation instructions from USD to a currency you actually use? It sounds like you've left it as USD and your store is looking up a USD exchange rate that doesn't exist, hence the $0. Otherwise it wouldn't be displaying $!

 

Please read the instructions CAREFULLY when installing contributions. I've had a lot of e-mails from people who are having problems with this contribution and it's because they've skipped one of the steps.


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

Did you change the default currency as per installation instructions from USD to a currency you actually use? It sounds like you've left it as USD and your store is looking up a USD exchange rate that doesn't exist, hence the $0. Otherwise it wouldn't be displaying $!

 

Please read the instructions CAREFULLY when installing contributions. I've had a lot of e-mails from people who are having problems with this contribution and it's because they've skipped one of the steps.

 

Our default currency is the USD :rolleyes:

Share this post


Link to post
Share on other sites

I have updated this contribution.

 

The instructions have been edited to ensure they are clear.

 

Please download v1.1.


osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

Our default currency is the USD :rolleyes:

 

 

So your store runs in USD most of the time. You left the defualt in this contrib as USD... Have you set any of the currencies in the countries_currencyid table in the database to anything that you haven't set an exchange rate for in admin?

 

I'm sorry to assume you've done something wrong, but so far every problem I've heard of has been a result of silly mistakes during installation that are easy to make, but disastrous as a result! Usually they're easy to fix, so it's a good place to start.

 

Do you have any other currency contributions installed that might be conflicting? How are you limiting the countries of your visitors exactly?

Edited by seb1188

osCommerce is GREAT. When it works...

Share this post


Link to post
Share on other sites

Hello,

 

Problem is, if you don't have USA in your country list its 0. The value default currency_id doesn't seem to work: if not defined in the database it doesn't apply the default currency. Any possibility to alter the code to add this function?

 

Greetings

Edited by girolimoni

Share this post


Link to post
Share on other sites

For those having the problem where the price is 0, the reason is because the code is not checking for a return from the site it checks for the IP. To fix this, find this code in includes/application_top.php

    curl_close($ch);
   return $content;
};

and change it to

    curl_close($ch);
   return (($content === FALSE) ? 'US' : $content);
};

Note that US should be whatever your default currency is. You may also want to change this line

$timeout = 5;

to

$timeout = 10;

The first change will fix the problem. The second will allow more time for the other site to respond so that the correct result is returned. Although, if the other site is having problems, your customers have to wait longer so this is a judegment call you'll need to make.

Share this post


Link to post
Share on other sites

For those having the problem where the price is 0, the reason is because the code is not checking for a return from the site it checks for the IP. To fix this, find this code in includes/application_top.php

    curl_close($ch);
   return $content;
};

and change it to

    curl_close($ch);
   return (($content === FALSE) ? 'US' : $content);
};

Note that US should be whatever your default currency is. You may also want to change this line

$timeout = 5;

to

$timeout = 10;

The first change will fix the problem. The second will allow more time for the other site to respond so that the correct result is returned. Although, if the other site is having problems, your customers have to wait longer so this is a judegment call you'll need to make.

 

hi didn't work for me. no idea why. chinese guest got still prices 0. so as we have only 2 currencies we added this and its working. :). what do you think about this solution?

 

if ($currency_id != 'CHF') {

$currency='EUR'; }

else {

$currency='CHF'; }

$_SESSION['locationset']=$location;

$_SESSION['currency']=$currency;

Share this post


Link to post
Share on other sites

That may work in your case but won't for any shop that has currencies different than Euro's and China's currency.

Share this post


Link to post
Share on other sites

Just uploaded Version 1.2

 

Error check added incase http://www.wipmania.com/ is down or incase you have other mods based on currency.

 

* All I changed in this version was step 5. Added if statement to see if $location was empty under: $location = getUserCountry();

 

This is what I did in Step 5:

 

if ($location == ''){
		// $location is blank, use default method so we don't get $0 prices or in some cases no product listed.
		$currency = (USE_DEFAULT_LANGUAGE_CURRENCY == 'true') ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
	}else{
		//since it has not been determined, find the currency it needs to be changed to
		$currency_id_result=tep_db_query("SELECT countries_currencyid FROM countries WHERE countries_iso_code_2='".$location."'");

		while($currency_row=tep_db_fetch_array($currency_id_result)) {
			$currency_id=$currency_row['countries_currencyid'];
		};

		//create session variable to show that it has now been determined
		$currency=$currency_id;
		$_SESSION['locationset']=$location;
		$_SESSION['currency']=$currency;
}

 

Hope it helps everyone!

 

Also, changing $timeout to 10 is worth it as Jack_mcs mentioned works for me quite well!

Share this post


Link to post
Share on other sites

Mate you are awesome!

Maybe you know how to make a feature that it will change to a default language using this script?

For example if the visitor is from US, then it will pick "en". If from France for example, it should post the site in "fr".

Can you help?

I really need the site to see the visitor's country and switch the default site's language as well as the currency according to his location.

Edited by doscape

Share this post


Link to post
Share on other sites

Mate you are awesome!

Maybe you know how to make a feature that it will change to a default language using this script?

For example if the visitor is from US, then it will pick "en". If from France for example, it should post the site in "fr".

Can you help?

I really need the site to see the visitor's country and switch the default site's language as well as the currency according to his location.

 

It should already do this in application_top.php:

// set the language
 if (!tep_session_is_registered('language') || isset($HTTP_GET_VARS['language'])) {
   if (!tep_session_is_registered('language')) {
     tep_session_register('language');
     tep_session_register('languages_id');
   }

   include(DIR_WS_CLASSES . 'language.php');
   $lng = new language();

   if (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) {
     $lng->set_language($HTTP_GET_VARS['language']);
   } else {
     $lng->get_browser_language();
   }

   $language = $lng->language['directory'];
   $languages_id = $lng->language['id'];
 }

 

Right here:

$lng->get_browser_language();

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×