X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Multiple Currencies Mod Complete (v4.1.2) (https://forum.x-cart.com/showthread.php?t=23547)

koaloa 07-24-2006 07:07 PM

Multiple Currencies Mod Complete (v4.1.2)
 
Well after a good day or two plugging away I've finally finished a little mod that will allow the customer to select which alternate currency they want prices displayed in. They can choose a currency code using a drop-down list and then the current page will refresh and display the alternate price next to the regular price. The selected currency is also stored as a cookie so subsequent pages remember which currencies to display.

I've also added a simple admin configuration area that lets you change the rates manually.

This is a fairly basic mod in that it does NOT get the latest rates from any bank (I tried at one point but it seems most want to charge fees, etc, etc). It does NOT let you log in as an administrator and add unlimited currency codes & rates (I started to do this but realized my client could probably care less and I don't really have another day to throw around). I think you guys know how it is. ;-) Right now to add another currency code it involves adding an entry to a table and a couple lines of PHP code to a file. Easy as pie, well for an engineer that is, just not something my mother could do.

Another thing this mod does NOT do is charge the user in a foreign currency. This ONLY displays alternate currencies so the user can see product prices and cart prices in BOTH default and user-selected alternate currencies.

BTW, I have this running on X-Cart 4.1.2 Gold and have done my testing on Firefox 1.5.04 and IE 6.

Also, here are a few screenshots.

The main home page with the drop-down list:
http://hurai.dreamhosters.com/images/xcart/home-select.jpg

The admin configuration page:
http://hurai.dreamhosters.com/images/xcart/admin.jpg

UPDATE: you'll need to run the following commands through the database to add text labels to the language table.

INSERT INTO `xcart_languages` VALUES ('US', 'lbl_currencies', 'Currencies', 'Labels');
INSERT INTO `xcart_languages` VALUES ('US', 'option_title_Multiple_Currency', 'Multiple Currencies Options', 'Labels');

And then one more query to add the custom module to X-Cart:

INSERT INTO `xcart_modules` VALUES (74, 'Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y');

Once you do this, go into the Administrator - Modules area and make sure you see it there and make sure it IS enabled.

I've put this mod on my website for you to download here.

Password is: koaconsulting.com

balinor 07-25-2006 03:23 AM

Looks like a good mod...but the Completed Mods forum is for posting Completed Code only. Let me know when you have the code posted and I'll move it back to that forum.

mlivio@vo.lu 07-27-2006 11:33 PM

multiple currencies
 
Hi koaloa,

I would like to try your multiple currencies package, can I download it somewhere ?


Thanks.

leon 08-04-2006 07:06 AM

Very good, can you share the code ?

koaloa 08-04-2006 12:21 PM

Please take a look at my original post as I've put a download link to a zipfile with the mod with install instructions. Hope you like it.

Hurai

leon 08-04-2006 01:32 PM

Thanx, very well explained, Im going to try it out to see how it works.

mffowler 08-04-2006 06:03 PM

In my General Settings, I get an arrow and no text. Is there a missing language variable?

Modified the tpl's - added a field in the currencies table, but nothing shows up....

- Mike

koaloa 08-04-2006 06:16 PM

Hey Mike,
Sorry about that. I thought I was being so diligent explaining everything and documenting each item I changed. I've updated my post above to reflect two more language additions I made.

You need to run these commands on the table:
INSERT INTO `xcart_languages` VALUES ('US', 'lbl_currencies', 'Currencies', 'Labels');
INSERT INTO `xcart_languages` VALUES ('US', 'option_title_Multiple_Currency', 'Multiple Currencies Options', 'Labels');

Or you can just enter these values into the administrator - language section of X-Cart:

lbl_currencies - 'Currencies'
option_title_Multiple_Currency - 'Multiple Currencies Options'

Remember to wipe out your cache if these don't show up right away, I learned that the hard way (after hitting refresh about 30 times and then browsing the forums).

Let me know how it goes, it's actually pretty neat once it all works. :)

mffowler 08-05-2006 01:12 AM

Half way there. I see a form action for shop.php in the tpl, is that your own page? I can't get any options to show up though.... there might be something else missing here?

Thanks,

Mike

koaloa 08-05-2006 09:44 AM

Ah, I may have found the culprit. You need to run this mySQL query to add the custom module to X-Cart:

INSERT INTO `xcart_modules` VALUES (74, 'Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y');

Once you do this, go into the Administrator - Modules area and make sure you see it there and make sure it IS enabled.

Sorry for the run-around. I think you're close!

mffowler 08-05-2006 06:53 PM

Quote:

SQL PATCH FAILED AT QUERY:
INSERT INTO `xcart_modules` VALUES (74, 'Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y')

Any other ideas?

Thanks,

Mike

koaloa 08-07-2006 11:00 AM

Hi Mike,
Well my guess is that you already have a module with id #74 on your system. I used phpMyAdmin to export the field and it put that number in there, I should have removed it to play it safe. Anyway, I'd recommend you going into phpMyAdmin and just adding a new row into the table, leaving the 'moduleid' field empty, and filling in the other fields. Let me know if you are unsure of how to do this and I'll help you out.

Alternatively, you can run this query:

INSERT INTO `xcart_modules` (module_name,module_descr,active) VALUES ('Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y')

Corto_Maltese 08-07-2006 12:09 PM

Hello, Koaloa,

Great mod... I have an 4.0.18 xcart version, and it is almost perfect : I have not the currencies into the drop-down list, in the top_menu.tpl.
And the same question than mffowler : what is the 'shop.php, in the 'show_currency_options.tpl'.
if you can help, it will be fantastic.
Thanks.
Erick

koaloa 08-08-2006 07:05 PM

Hey guys,
My reference to "shop.php" is the main shop.php script used by X-Cart. What I'm doing is causing the original page to be reloaded with the new currency values displayed (regardless of which page of the site they are on). This is not a script I've created. It's really a detail, nothing so tricky really.

If you're not getting values to appear in your combo-box I think the problem is elsewhere. Are you sure you entered the right values into the mySQL table/database? The function "func_koa_get_currency_rates" (in the "show_currency_options.tpl" file) makes a mySQL call to get all entries from the "xcart_currencies" table, but ONLY if they have a rate value that is not equal to zero (rate != '0'). This code that populates the combo is really simple. So make sure you've set these values appropriately and you should see your combo populated.

Hope this helps. :)

mffowler 08-08-2006 10:29 PM

Koaloa-

I have the mod showing up and there are the default currency values in the mods admin area, but the dropdown is blank. There is no shop.php - can you think of ahything else that is missing?

Thanks,

- Mike

koaloa 08-09-2006 12:32 AM

You're right, there is no "shop.php", I think I mistakenly put that in there, but it still works as it should because there is actually no submit button, just a javascript redirect that causes the page to reload.

Back to your problem, try putting in a print statement in the func.php file (that's part of my module) to see what it finds from the database. I'm thinking you MUST not be able to retrieve the entries from the db.

I usually use a line or two like the following:

Code:

echo "<pre>";
print_r($rows);
echo "</pre>";


Corto_Maltese 08-15-2006 10:18 AM

Hi,
Just a question : why are the alter_currency rates stocked in the xcart-config table ? I do not understand well. I thought the Multiple_currency screen saved the data in the xcart-currencies table?
And, btw, I am on a 4.0.18 version. Do you think your code works well? Or do you have some idea/modification for that ? (if you have time to debug...)
Many thanks in advance
Erick

mffowler 08-18-2006 08:15 PM

Still no luck with this... dropdown remains empty...

Has nayone got this to woprk on 4.1.2?

Thanks,

Mike

koaloa 08-21-2006 10:01 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Hey guys,
This really boggles me why it's not working for you. Well let's try and debug this... my GUESS is that the script is not able to pull the values out of the database for some reason. To start, make a backup of the file /<your store dir>/skin1/customer/main/show_currency_options.tpl and REPLACE it with the following code. What I'm trying to do is just print what currency values are found in the database. Please let me know if the page prints out all of the currency rates in the database (this debug script is just for testing purposes, it will just print the values and then cause the script to terminate). Please show me your results. Thanks!

Code:

{* $Id: alter_currency_value.tpl,v 1.11.2.1 2006/04/29 06:36:56 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>";
*/
$CURRENCY_RATES = func_koa_get_currency_rates();
echo "<pre>";
print_r($CURRENCY_RATES);
echo "</pre>";

{/php}
<form name="currency_select_form" action="nothing.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 == "USD")
                $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}


bngwarehouse 08-29-2006 06:51 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Downloaded the Module but when I try and unzip it there is a password to extract the contents. Hmmm?

koaloa 08-29-2006 08:54 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
As it says on my post, right below the download link... The password to extract is: koaconsulting.com

Have fun! :)

bngwarehouse 08-29-2006 09:34 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Yes your right...(Oops!) My bad. Nice Mod!

gobligoo 09-13-2006 02:41 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Hi,

Looks like a very good mod, but any chance of seeing it live?

---------------
x-cart 4.19 (Unix)

just wondering 11-13-2006 07:44 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
At first the drop down box was blank. I changed the Currency Rates and it worked.

Crazy, but it did it for me...

Does anyone know if would it be possible to make it so that instead of showing ($4.99) it shows (CAD$4.99) [for example]?

I'd prefer to have it that way to stop the possible 'I didn't know it was in USD, I thought it was in CAD' problems some people will try on you.

Cheers!

girlsbits 12-09-2006 01:59 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Great mod K, huge thanks.

Works perfect in 4.1.4, make sure to follow complete thread for Koalas posts.

Polvo 04-23-2007 11:18 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
I've just installed this mod for v4.1.6. I found it needed a few alterations to work with GBP as the default currency. So here's my revised version of the original installation instructions. Thanks to koaloa for a nice mod.

X-Cart Multiple Currency Mod – for version 4.1.6 Gold
=====================================
Download zip file and open with password given in first post in this thread.

Start by going to Admin > General Settings and remove the default alternate currency code '€'.

Copy:
skin1/customer/top_menu.tpl.
modules/Multiple_Currency/config.php

Copy these three files. If your default currency is not USD then edit them all first changing 'USD' to your default currency eg 'GBP'.:
skin1/customer/main/alter_currency_value.tpl
skin1/customer/main/show_currency_options.tpl
modules/Multiple_Currency/func.php with functions

Edit your copy of admin/configuration.php and add the lines of code from the included version (search for the text koaconsulting.com to see where changes have been made). Note: This file copies the currency rates from the Admin config table to the currencies table on opening or clicking save.

Modify the table xcart_config by adding entries including your default currency eg:
INSERT INTO `xcart_config` VALUES ('currency_rate_usd', 'Rate for the US Dollar', '0', 'Multiple_Currency', 0, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_euro','Rate for the EURO', '0', 'Multiple_Currency', 0, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_gbp', 'Rate for the British Pound', '0', 'Multiple_Currency', 0, 'numeric', '1.0', '');

Modify the table xcart_currencies by adding a field called 'rate', setting it as 'double' and making sure the default value is set to zero.

You need to run these SQL commands:
INSERT INTO `xcart_languages` VALUES ('US', 'lbl_currencies', 'Currencies', 'Labels');
INSERT INTO `xcart_languages` VALUES ('US', 'option_title_Multiple_Currency', 'Multiple Currencies Options', 'Labels');
INSERT INTO `xcart_modules` VALUES (xx, 'Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y');
(Where xx is next id number available).

Go into the Admin > Modules area. 'Multiple_Currency' should be listed and ticked. Click 'Configure' to set your exchange rates, your default currency should be set to 1.

floracal 05-05-2007 11:41 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
I get this error

$query = "SELECT * FROM xcart_currencies WHERE rate != '0'";

How do i add rate field?

effour 06-28-2007 01:52 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
has anyone got this mod working on 4.1.7?

Looker1 08-27-2007 07:44 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
or 4.1.8? Would be interested in this but do not want to be first.

1. Also, anyone have some nice examples from live sites?
2. Can you select yoru currency by clicking on a jpeg instead of pull down menu? Would be great if this could be tweaked to do so.

Kansla 11-08-2007 12:42 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Has anyone run this mod working on 4.1.9?

ShishaPipeUK 12-30-2007 03:39 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Quote:

Originally Posted by floracal
I get this error

$query = "SELECT * FROM xcart_currencies WHERE rate != '0'";

How do i add rate field?


Go to your patch/upgrade in the admin section and in the bottom box type in:
Code:

ALTER TABLE `xcart_currencies` ADD `rate` double NOT NULL default '0'

Also it works on 4.1.9 as well.

And the admin/configuration.php code that puts the rate into the xcart_currencies using the command UPDATE xcart_currencies SET rate='$val' WHERE code='$code' does not work with the euro (as per the instructions) as the code for euro is EUR not euro.

So when you modify the table for xcart_config and you want the Euro currency you must use:

Code:

INSERT INTO `xcart_config` VALUES ('currency_rate_EUR', 'Rate for the Euro', '1.35572', 'Multiple_Currency', 0, 'numeric', '1.0', '');

Now if you use the above insert code, please go into your admin section and change the currency value ('1.35572') and save it, then change it back and save it so that the configuration.php script updates the xcart_currencies, then you will find this new update in the drop down box on your web site.

The code only looks for rates defined in the xcart_currencies table > 0 and by inserting the currency conversion value like the above code the configuration.php file has not been run to update the xcart_currencies rate value, so it wont show on your web site.

Also make sure that the currency symbol is only 3 characters long, like USD, EUR, GBP, CAD, HKD, TND etc.

Anyway you can see a working copy at http://www.elmaallem.com

ShishaPipeUK 12-30-2007 05:29 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Quote:

Originally Posted by just wondering
Does anyone know if would it be possible to make it so that instead of showing ($4.99) it shows (CAD$4.99) [for example]?


You have to edit the xcart_currencies table and change the SYMBOL from $ to CAD $

Here is the code for the Patch / Upgrade in your admin section, you place this code in the bottom SQL query(ies): section.

Code:

UPDATE xcart_currencies SET symbol='CAD $' WHERE CODE='CAD';

You can see this at http://www.elmaallem.com site.

ShishaPipeUK 01-02-2008 08:54 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
1 Attachment(s)
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 (Attachment 708) or belowthe following code.

skin1/customer/top_menu.tpl (File included in Attachment 708)
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}&nbsp;&nbsp;&nbsp;{$lng.lbl_phone_2_title}: {$config.Company.company_phone_2}{/if}&nbsp;&nbsp;</td>
</tr>
</table>
{/if}


modules/Multiple_Currency/config.php (File included in Attachment 708)
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 Attachment 708)
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 Attachment 708)
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 Attachment 708)
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 Attachment 708), 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


ShishaPipeUK 01-02-2008 08:57 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
CONTINUED FROM ABOVE POST DUE TO FORUM POST SIZE RESTRICTIONS.

The Patch file in this zip file (Attachment 708) will do the below automatically for you.

Modify the table xcart_currencies by adding a field called 'rate', setting it as 'double' and making sure the default value is set to zero.

Code:

ALTER TABLE `xcart_currencies` ADD `rate` double NOT NULL default '0'

Modify the table xcart_config by adding entries including your default currency eg:

Code:

INSERT INTO `xcart_config` VALUES ('currency_rate_GBP', 'Rate for the British Pound', '1', 'Multiple_Currency', 10, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_EUR', 'Rate for the EURO', '1.35572', 'Multiple_Currency', 20, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_USD', 'Rate for the US Dollar', '1.99779', 'Multiple_Currency', 30, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_CAD', 'Rate for the Canadian Dollar', '1.95798', 'Multiple_Currency', 40, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_AUD', 'Rate for the Australian Dollar', '2.27001', 'Multiple_Currency', 50, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_HKD', 'Rate for the Hong Kong Dollar', '15.5755', 'Multiple_Currency', 60, 'numeric', '1.0', '');


If you need to delete a currency i.e. you no longer want to show that currency you can run this code in your patch / upgrade section for the code you want to delete, for example HKD:

Code:

DELETE FROM xcart_config WHERE name='currency_rate_HKD';
The above will delete the Hong Kong Dollar RATE ONLY.

You need to run these SQL commands:
Code:

INSERT INTO `xcart_languages` VALUES ('US', 'lbl_currencies', 'Currencies', 'Labels');
INSERT INTO `xcart_languages` VALUES ('US', 'option_title_Multiple_Currency', 'Multiple Currencies Options', 'Labels');
INSERT INTO `xcart_modules` (module_name,module_descr,active) VALUES ('Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y')


THE FULL PATCH FILE CODE THATS INCLUDED IN THE ATTACHEMENT AND ABOVE
Code:

ALTER TABLE `xcart_currencies` ADD `rate` double NOT NULL default '0';
INSERT INTO `xcart_config` VALUES ('currency_rate_GBP', 'Rate for the British Pound', '1', 'Multiple_Currency', 10, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_EUR','Rate for the EURO', '1.35572', 'Multiple_Currency', 20, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_USD', 'Rate for the US Dollar', '1.99779', 'Multiple_Currency', 30, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_CAD', 'Rate for the Canadian Dollar', '1.95798', 'Multiple_Currency', 40, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_AUD', 'Rate for the Australian Dollar', '2.27001', 'Multiple_Currency', 50, 'numeric', '1.0', '');
INSERT INTO `xcart_config` VALUES ('currency_rate_HKD', 'Rate for the Hong Kong Dollar', '15.5755', 'Multiple_Currency', 60, 'numeric', '1.0', '');
INSERT INTO `xcart_languages` VALUES ('US', 'lbl_currencies', 'Currencies', 'Labels');
INSERT INTO `xcart_languages` VALUES ('US', 'option_title_Multiple_Currency', 'Multiple Currencies Options', 'Labels');
INSERT INTO `xcart_modules` (module_name,module_descr,active) VALUES ('Multiple_Currency', 'Enables users to select different currencies to be displayed.', 'Y');
UPDATE xcart_currencies SET symbol='CAD $' WHERE CODE='CAD';
UPDATE xcart_currencies SET symbol='HKD $' WHERE CODE='HKD';
UPDATE xcart_currencies SET symbol='AUD $' WHERE CODE='AUD';


I wanted to show that AUD $ and CAD $ and HKD $ was not the same as USD $ so the 3 above update patches is to change the symbol from $ too ??? $

Go into the Admin > Modules area. 'Multiple_Currency' should be listed and ticked.

Click 'Configure' to set your exchange rates, your default currency in this case GBP should be set to 1.

The above files have been tested at http://www.shishapipe.net/shopcart/home.php (Because of the way the site is designed I do not use the skin1/customer/top_menu.tpl so I placed my code in the head.tpl)

ShishaPipeUK 01-02-2008 08:03 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
What i did notice about this mod, is it works fine on the home.php page but if you go to a product and then change the currency you get an access denied.

Here is an example, go to http://www.shishapipe.net/shopcart/product.php?productid=16818&cat=0&page=1 and then change the currency, you then get:

Access denied !
You are not allowed to access that resource!
Error ID: 33

Now i know why to a certain point. I am not using the skin1/customer/top_menu.tpl
Instead I have the code in the skin1/head.tpl file which is:

Code:

<table cellpadding="0" cellspacing="0">
      <tr>
        <td><b>{$lng.lbl_cc_currency}:</b>&nbsp;&nbsp;</td>
        <td style="padding-right: 5px;">{include file="customer/main/show_currency_options.tpl"}</td>
      </tr>
    </table>   


I know the code works fine when looking at a product and using the skin1/customer/top_menu.tpl so the above posting is correct but with my site having just a few modifications i need this code in the head.tpl.

Has anyone any ideas what i need to change to get it to work in the head.tpl file when looking at a product ?

junaid 01-01-2009 05:44 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
is there any way to change show a particular payment method with each currency selected.
for example:
there are two payment methods.
1) credit card for gbp
2) credit card for US$
default is 1 and when US$ is selected and customer reaches choose payment method it only show credit card for US$.
regards
Junaid

kmaw 02-20-2009 01:24 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
I've got this mod working on 4.1.11, but my problem is a price not showing up when the USD is selected. The other currencies seem to work, but not the USD when selected.

TanyaG 04-08-2009 08:39 AM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Great mode, thanks for sharing. I have a small problem. I’m trying to make it work for v4.2 and for some reason as soon as I’m going to next page it display only default currency. I think its a cookie problem. Is anyone know how can I fix it?

gotpump 09-04-2009 03:31 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
I cannot get this to work in 4.10. :(

Learner 09-04-2009 11:19 PM

Re: Multiple Currencies Mod Complete (v4.1.2)
 
Hi, ShishaPipeUK

Our Primary currency is set to one Credit card payment method ..

All we want is to link alt currency for customers opting to pay using Paypal (in USD -"$")...

Is it possible?

Thanks to all in advance !!


All times are GMT -8. The time now is 04:56 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.