This file attached is the code for x-cart 4.1.9 and for a GBP (UK site) which also includes all the files and patches (plus a read me text file) which i will also display below.
A special thanks to koaloa for a very nice mod.
Go to Admin > General Settings and remove the default alternative currency code.
Copy from (
muti_currency_mod.zip) or belowthe following code.
skin1/customer/top_menu.tpl (File included in
muti_currency_mod.zip)
Code:
{if $printable ne ''}
{include file="customer/top_menu_printable.tpl"}
{else}
<table cellpadding="0" cellspacing="0" width="100%">
{if $speed_bar}
<tr>
<td valign="top" align="right">
{* ADD THE CURRENCY BOX TO TOP OF THE MENU IF CURRENCY MODULE IS SELECTED *}
{if $active_modules.Multiple_Currency ne ""}
<table>
<tr>
<td valign="top"><table width="100%" border="0">
<tr>
<td>{$lng.lbl_cc_currency}</td>
<td>{include file="customer/main/show_currency_options.tpl"}</td>
</tr>
</table>
</td>
<td>
{/if}
{* END OF ADD THE CURRENCY BOX TO TOP OF THE MENU IF CURRENCY MODULE IS SELECTED *}
<table cellpadding="0" cellspacing="0">
<tr>
{section name=sb loop=$speed_bar}
{if $speed_bar[sb].active eq "Y"}
<td valign="top">{include file="customer/tab.tpl" tab_title="<a href=\"`$speed_bar[sb].link`\">`$speed_bar[sb].title`</a>"}</td>
<td width="1"><img src="{$ImagesDir}/spacer.gif" class="Spc" alt="" /></td>
{/if}
{/section}
</tr>
{* ADD THE CURRENCY BOX TO TOP OF THE MENU IF CURRENCY MODULE IS SELECTED *}
{if $active_modules.Multiple_Currency ne ""}
</table></td>
{/if}
{* END OF ADD THE CURRENCY BOX TO TOP OF THE MENU IF CURRENCY MODULE IS SELECTED *}
</table>
</td>
</tr>
{/if}
<tr>
<td height="35" align="center" class="HeadText">
{if $config.Company.company_phone}{$lng.lbl_phone_1_title}: {$config.Company.company_phone}{/if}{if $config.Company.company_phone_2} {$lng.lbl_phone_2_title}: {$config.Company.company_phone_2}{/if} </td>
</tr>
</table>
{/if}
modules/Multiple_Currency/config.php (File included in
muti_currency_mod.zip)
Code:
<?php
if ( !defined('XCART_SESSION_START') ) { header("Location: ../../"); die("Access denied"); }
$currency_code_var_name = "currency_code";
$currency_code_cookie_time = $use_session_length;
//echo "currency_code is: " . $HTTP_GET_VARS[$currency_code_cookie_name] . "<br>";
if($HTTP_GET_VARS[$currency_code_var_name] != "") {
// set cookie to remember it
setcookie($currency_code_var_name, $HTTP_GET_VARS[$currency_code_var_name], time() + $currency_code_cookie_time, "/", "", 0);
$_COOKIE[$currency_code_var_name] = $HTTP_GET_VARS[$currency_code_var_name];
}
?>
skin1/customer/main/alter_currency_value.tpl (File included in
muti_currency_mod.zip)
Code:
{* $Id: alter_currency_value.tpl,v 1.11.2.1 2006/04/29 06:36:56 max Exp $ *}
{php}
global $currency_code, $smarty;
// Don't show an alternate currency code if none is specified.
if($currency_code == "GBP" || $currency_code == "")
return;
{/php}
{if $alter_currency_value eq ""}{assign var="alter_currency_value" value="0"}{/if} ({if $plain_text_message eq ""}<span style="WHITE-SPACE: nowrap">{/if}
{php}
global $currency_code, $smarty;
global $alter_currency_symbol, $alter_currency_rate;
$currency = func_koa_get_current_currency($currency_code);
if($currency->symbol != "")
$smarty->assign('alter_currency_symbol', $currency->symbol);
if($currency->rate != "")
$smarty->assign('alter_currency_rate', $currency->rate);
{/php}
{$alter_currency_symbol}{math equation="altercurrencyvalue*rate" altercurrencyvalue=$alter_currency_value rate=$alter_currency_rate format="%.2f" assign=alter_price}{$alter_price|formatprice}{if $plain_text_message eq ""}</span>{/if})
skin1/customer/main/show_currency_options.tpl (File included in
muti_currency_mod.zip)
Code:
{* $Id: show_currency_value.tpl max Exp $ *}
{literal}
<script language="javascript">
<!---
function SelectLink(form, url) {
/*alert(document.currency_select_form.currency_options.options[document.currency_select_form.currency_options.selectedIndex].value);*/
window.location.href=url + "currency_code=" + document.currency_select_form.currency_options.options[document.currency_select_form.currency_options.selectedIndex].value;
}
//-->
</script>
{/literal}
{php}
// Debug Info:
/*
echo "<pre>";
print_r($_COOKIE);
echo "</pre>";
*/
{/php}
<form name="currency_select_form" action="home.php" method="post">
<select name="currency_options" onChange="SelectLink(document.currency_select_form, '{php}
$url = $_SERVER['REQUEST_URI'];
// remove any existing 'currency_code' variables.
if(strstr($url, "currency_code")) {
// we DID find the variable, so remove it!
$url = preg_replace("/currency_code=[a-zA-Z]+(&)?/", "", $url);
}
$parsed_url = parse_url($url);
if(!strstr($url, "?")) {
$url .= "?";
}
//echo "query is: " . $parsed_url[query] . "<br>";
if(trim($parsed_url['query']) != "") {
$url = trim($url, "&");
$url .= "&";
}
echo $url;
{/php}')">
{php}
global $smarty, $currency_code;
$CURRENCY_RATES = func_koa_get_currency_rates();
if($_COOKIE[currency_code] != "")
$currency_code = $_COOKIE[currency_code];
for($i = 0; $i < count($CURRENCY_RATES); $i++) {
$cur_rate = $CURRENCY_RATES[$i];
$abbrev = $cur_rate->code;
if($currency_code == "" && $abbrev == "GBP")
$selected_str = "selected=\"selected\"";
if($currency_code != "" && $currency_code == $abbrev) {
$selected_str = "selected=\"selected\"";
$default_selected = true;
}
echo "<option value=\"$abbrev\" $selected_str>$abbrev</option>\n";
$selected_str = "";
}
{/php}
</select>
</form>
{php}
/*
echo "<pre>";
print_r($_COOKIE);
echo "</pre>";
*/
{/php}
modules/Multiple_Currency/func.php (File included in
muti_currency_mod.zip)
Code:
<?php
if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }
/**
* Searched the database for any entries in the xcart_currencies table that have a rate
* that is specified (e.g. not-zero). Returns an array of objects.
*/
function func_koa_get_currency_rates() {
$query = "SELECT * FROM xcart_currencies WHERE rate != '0'";
$result = db_query($query);
while($row = mysql_fetch_object($result)) {
$rows[] = $row;
}
return $rows;
}
/**
* Returns the database object ($row->id, $row->name, etc) for the specified currency code
* (e.g. USD, CAD, GBP). If none is found in the list of rates, "GBP" is used for default.
*/
function func_koa_get_current_currency($currency_code) {
$CURRENCY_RATES = func_koa_get_currency_rates();
for($i = 0; $i < count($CURRENCY_RATES); $i++) {
$cur_rate = $CURRENCY_RATES[$i];
if($cur_rate->code == $currency_code) {
//echo "found code $currency_code with rate $cur_rate->rate<br>";
return $cur_rate;
}
}
// If we get here it means that there was an invalid currency code specified, so just return GBP
for($i = 0; $i < count($CURRENCY_RATES); $i++) {
$cur_rate = $CURRENCY_RATES[$i];
if($cur_rate->code == "GBP")
return $cur_rate;
}
}
?>
Edit your copy of
admin/configuration.php see below.
Note: This file copies the currency rates from the Admin config table to the currencies table on opening or clicking save.
You may not want to copy the full admin/configuration.php (File included in
muti_currency_mod.zip), so if this is the case search for:
Code:
if ($option == "Security") {
func_pgp_remove_key();
$config[$option] = $section_data; # no code after func_pgp_add_key() using these settings
func_pgp_add_key();
}
And then AFTER this put in the following code:
Code:
// koaconsulting.com - currency mod
if($option == "Multiple_Currency") {
// Search through all currency_rate_* variables and update the database accordingly.
while(list($key,$val) = each($_POST)) {
if(strstr($key, "currency_rate_")) {
//echo "found var: $key<br>";
$code = strtoupper(str_replace("currency_rate_", "", $key));
//echo "code is: $code<br>";
$query = "UPDATE xcart_currencies SET rate='$val' WHERE code='$code'";
//echo "query is: $query<br>";
db_query($query);
}
}
}
// koaconsulting.com - end currency mod