Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Multiple Currencies Mod Complete (v4.1.2)

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #31  
Old 12-30-2007, 03:39 PM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Smile 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
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #32  
Old 12-30-2007, 05:29 PM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Default 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.
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #33  
Old 01-02-2008, 08:54 AM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Thumbs up Re: Multiple Currencies Mod Complete (v4.1.2)

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}&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 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
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #34  
Old 01-02-2008, 08:57 AM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Default 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)
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #35  
Old 01-02-2008, 08:03 PM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Default 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 ?
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #36  
Old 01-01-2009, 05:44 AM
 
junaid junaid is offline
 

Advanced Member
  
Join Date: Dec 2003
Posts: 96
 

Default 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
__________________
xcart 4.18 on linux
Reply With Quote
  #37  
Old 02-20-2009, 01:24 AM
  kmaw's Avatar 
kmaw kmaw is offline
 

Newbie
  
Join Date: Dec 2008
Posts: 2
 

Default 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.
__________________
X-Cart Gold Version 4.1.12
Add-on: X-SpecialOffers
Add-on: X-Magnifier
Add-on: X-AOM (Advanced Order Management)
PHP Version: 5.2.6
MySQL Version: 5.0.85-community
Apache: 2.2.10
Reply With Quote
  #38  
Old 04-08-2009, 08:39 AM
 
TanyaG TanyaG is offline
 

Advanced Member
  
Join Date: Nov 2007
Posts: 94
 

Default 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?
__________________
Tanya

x-cart version: 4.1.7 4.1.9. 4.2
Reply With Quote
  #39  
Old 09-04-2009, 03:31 PM
 
gotpump gotpump is offline
 

eXpert
  
Join Date: Aug 2008
Posts: 272
 

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

I cannot get this to work in 4.10.
__________________
X-Cart DB Version: 5
Reply With Quote
  #40  
Old 09-04-2009, 11:19 PM
 
Learner Learner is offline
 

X-Adept
  
Join Date: Dec 2008
Posts: 807
 

Default 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 !!
__________________
4.6.1 Platinum


Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:34 AM.

   

 
X-Cart forums © 2001-2020