使用ECShop搭建外貿站多國貨幣切換功能

//1   在數據庫裏的表ecs_shop_config插入


insert into ecs_shop_config('id','parent_id','code','type','store_range','store_dir','value','sort_order') values(null,'1','rate','text','','','1,0.71,0.69,6.85,1.45','1'),(null,'1','ybprice_format','text','','','&%s','1'),(null,'1','aprice_format','text','','','EUR%s','1'),(null,'1','cprice_format','text','','','¥%s','1'),(null,'1','aoprice_format','text','','','AU%s','1');
//INSERT INTO `ecs_shop_config`(`id`, `parent_id`, `code`, `type`, `store_range`, `store_dir`, `value`, `sort_order`) VALUES (null,'1','rate','text','','','1,0.71,0.69,6.85,1.45','1'),(null,'1','ybprice_format','text','','','&%s','1'),(null,'1','aprice_format','text','','','EUR%s','1'),(null,'1','cprice_format','text','','','¥%s','1'),(null,'1','aoprice_format','text','','','AU%s','1')




//2   在/languages/zh_cn/admin/shop_config.php下添加 (73行)
 
 $_LANG['cfg_name']['rate'] = '貨幣匯率';
 $_LANG['cfg_name']['ybprice_format'] = '英鎊格式';
 $_LANG['cfg_name']['aprice_format'] = '歐元格式';
 $_LANG['cfg_name']['cprice_format'] = '人民幣格式';
 $_LANG['cfg_name']['aoprice_format'] = '澳元格式';


//並且添加下面的幫助信息 (199行)


$_LANG['cfg_desc']['rate'] = '輸入規則按照和美元的匯率進行出入 Us,EURP,BriishPound,China,Austriliar';
$_LANG['cfg_desc']['ybprice_format'] = '顯示英鎊格式,%s將被替換爲相應的價格。';
$_LANG['cfg_desc']['aprice_format'] = '顯示歐元格式,%s將被替換爲相應的價格。';
$_LANG['cfg_desc']['cprice_format'] = '顯示人民幣格式,%s將被替換爲相應的價格。';
$_LANG['cfg_desc']['aoprice_format'] = '顯示澳元格式,%s將被替換爲相應的價格。';








//3.在themes/當前使用的模板文件夾/library/page_header.lbi的合適位置添加


<div class="TopNavList">
<li><a href="{$url_head}&currency=USD">美元</a><span></span></li>
<li><a href="{$url_head}&currency=CNY">人民幣</a><span></span></li>
<li><a href="{$url_head}&currency=EUR">歐元</a><span></span></li>
<li><a href="{$url_head}&currency=GBP">英鎊</a><span></span></li>
<li><a href="{$url_head}&currency=AUD">澳元</a><span></span></li>
</div> 
<select>
<option value="{$url_head}&currency=USD">美元</option>
<option value="{$url_head}&currency=CNY">人民幣</option>
<option value="{$url_head}&currency=EUR">歐元</option>
<option value="{$url_head}&currency=GBP">英鎊</option>
<option value="{$url_head}&currency=AUD">澳元</option>
</select>






//或
<div class="TopNavList">
<ul>
<li><a href="{$url_head}&currency=USD">美元</a><span></span></li>
<li><a href="{$url_head}&currency=CNY">人民幣</a><span></span></li>
<li><a href="{$url_head}&currency=EUR">歐元</a><span></span></li>
<li><a href="{$url_head}&currency=GBP">英鎊</a><span></span></li>
<li><a href="{$url_head}&currency=AUD">澳元</a><span></span></li>
</ul>
</div>








//    4在/includes/init.php最後面添加 //路徑處理 


$url_this="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?id=".@$_GET['id'];
$smarty->assign("url_head",$url_this);

$currency=@$_GET['currency'];

clear_all_files(); 清除緩存功能

if($currency!=""){
$_SESSION['currency']=$currency;
}
if($_SESSION['currency']==''){
$_SESSION['currency']='USD';
}






//    5.在/includes/lib_commom.php找到這個函數price_format並且按下面的進行修改 
/**   * 格式化商品價格 
 *   * @access  public 
 * @param   float   $price  商品價格 
 * @return  string 
*/


function price_format($price,$change_price=true){
$currency=$_SESSION['currency'];
$rate=explode(',',$GLOBALS['_CFG']['rate']);
if($currency=='USD'){
$price=$price*$rate[0];
}
if($currency=='CNY'){
$price=$price*$rate[3];
}
if($currency=='EUR'){
$price=$price*$rate[1];
}
if($currency=='GBP'){
$price=$price*$rate[2];
}
if($currency=='AUD'){
$price=$price*$rate[4];
}
if($change_price && defined('ESC_ADMIN')==false){
switch($GLOBALS['_CFG']['price_format']){
case 0:
$price=number_format($price,2,'.','');
break;
case 1: //保留不爲3的尾數
$price=preg_replace('/(.*)(\\.)([0-9]*?)0+$/','\1\2\3',number_format($price,2,'.',''));
if(substr($price,-1)=='.'){
$price=substr($price,0,-1);
}
break;
case 2: //四捨五入,保留1位
$price=substr(number_format($price,2,'.',''),0,-1);
break;
case 3: //直接取整
$price=intval($price);
break;
case 4: //四捨五入,保留1位
$price=number_format($price,1,'.','');
break;
case 5: //四捨五入,不保留小數
$price=round($price);
break;
}
}else{
$price=number_format($price,2,'.','');
}
switch ($currency){
case 'USD':
return sprintf($GLOBALS['_CFG']['currency_format'],$price);
break;
case 'CNY':
return sprintf($GLOBALS['_CFG']['cprice_format'],$price);
break;
case 'EUR':
return sprintf($GLOBALS['_CFG']['aprice_format'],$price);
break;
case 'GBP':
return sprintf($GLOBALS['_CFG']['ybprice_format'],$price);
break;
case 'AUD':
return sprintf($GLOBALS['_CFG']['aoprice_format'],$price);
break;
}
}






// 6.修改表ecs_order_info


alter table 'ecs_order_info' add 'currency' varchar(10) not null,add 'new_money' decimal(10,2) not null








// 7.修改flow.php文件中
{
//分成功能關閉
$parent_id=0;
}


$order['parent_id']=$parent_id;


//大約1608行左右下面  插入以下代碼


$order['currency']=$_SESSION['currency'];
$order['new_money']=price_format_hs($order['order_amount']);


//同時修改\inlucdes\lib_common.php在裏面新增加price_format_hs函數


/** 
  * 用於支付換算  * 
 * @access  public 
 * @param   float   $price  商品價格  * @return  string 
*/


function price_format_hs($price,$change_price=true){
$currency=$_SESSION['currency'];
$rate=explode(',',$GLOBALS['_CFG']['rate']);
if($currency=='USD'){
$price=$price*$rate[0];
}
if($currency=='CNY'){
$price=$price*$rate[3];
}
if($currency=='EUR'){
$price=$price*$rate[1];
}
if($currency=='GBP'){
$price=$price*$rate[2];
}
if($currency=='AUD'){
$price=$price*$rate[4];
}
if($change_price && defined('ESC_ADMIN')==false){
switch ($GLOBALS['_CFG']['price_format']){
case 0:
$price=number_format($price,2,'.','');
break;
case 1: //保留不爲0的尾數
$price=price_replace('/(.*)(\\.)([0-9]*?)0+$/','\1\2\3',number_format($price,2,'.',''));
if(substr($price,-1)=='.'){
$price=substr($price,0,-1);
}
break;
case 2: //不四捨五入,保留1位
$price=substr(number_format($price,2,'.',''),0,-1);
break;
case 3: //直接取整
$price=intval($price);
break;
case 4: //四捨五入,保留1位
$price=number_format($price,1,'.','');
break;
case 5: //四捨五入,不保留小數
$price=round($price);
break;
}
}else{
$price=number_format($price,2,'.','');
}
return $price;
}






// 8.在\includes\modules\payment\paypal.php 大約92行一個get_code函數


function get_code($order,$payment){
$paypal_currency=$_SESSION["currency"];//新增加的
$data_order_id=$order['log_id'];
$data_amount=$order['order_amount'];
$data_return_url=return_url(basename(__FILE__,'.php'));
$data_pay_account=$payment['paypal_account'];
$currency_code=$paypal_currency;//把下一行復製出來,並下行注掉,修改爲這一行
//$currency_code=$payment['paypal_currency'];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章