ECSHOP多国货币支持PAYPAL换算支付

当你的商城主要面向国外进行销售的时候, 你的网站必须得保证买家可以用各种货币进行支付才行。 客户自行选择支付货币,自动跟踪,无需每页都设置。
自动记忆功能,例如客户今天选择的是“美元USD”,当他(她)第二天再登录网站的时候,“支付货币”默认选中“美元USD”。
可后台设置币种与汇率,随时更新汇率的变化,如果你的在线支付方式有币种区分的话(例如paypal),通过该支付方式支付时,也会自动变换币种。

1.进入后台“SQL查询”输入以下代码,提交
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');
alter table ecs_order_info add currency varchar(10) not null;
alter table ecs_order_info add new_money decimal(10,2) not null;
2.打开/languages/zh_cn/admin/shop_config.php文件添加如下代码
$_LANG['cfg_name']['rate'] = '货币汇率';
$_LANG['cfg_name']['ybprice_format'] = '英镑格式';
$_LANG['cfg_name']['aprice_format'] = '欧元格式';
$_LANG['cfg_name']['cprice_format'] = '人民币格式';
$_LANG['cfg_name']['aoprice_format'] = '澳元格式';
$_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('ECS_ADMIN') === false)
    {
        switch ($GLOBALS['_CFG']['price_format'])
        {
            case 0:
                $price = number_format($price, 2, '.', '');
                break;
            case 1: // 保留不为 0 的尾数
                $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.打开flow.php文件,搜索如下代码
    else
    {
        //分成功能关闭
        $parent_id = 0;
    }
    $order['parent_id'] = $parent_id;
下面加上以下代码:
$order['currency'] = $_SESSION['currency'];
$order['new_money'] = price_format_hs($order['order_amount']);
7.打开/inlucdes/lib_common.php文件最后面添加如下代码
/**
 * 格式化支付换算
 *
 * @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('ECS_ADMIN') === false)
    {
        switch ($GLOBALS['_CFG']['price_format'])
        {
            case 0:
                $price = number_format($price, 2, '.', '');
                break;
            case 1: // 保留不为 0 的尾数
                $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, '.', '');
    }
    return $price;
}
8.打开/includes/modules/payment/paypal.php文件,搜索如下代码
    function get_code($order, $payment)
    {
        $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      = $payment['paypal_currency'];
        $data_notify_url    = return_url(basename(__FILE__, '.php'));
        $cancel_return      = $GLOBALS['ecs']->url();
将以上代码修改成如下
    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;
        $data_notify_url    = return_url(basename(__FILE__, '.php'));
        $cancel_return      = $GLOBALS['ecs']->url();

本文原创地址:https://www.ecshop.vc/article-340.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。

文章评论

暂时还没有任何用户评论

发表 取消
实时购买动态 ×

zzvv会员 在 2018-10-16 购买了 ECSHOP阿里大于短信插件【整合阿里大鱼短信接口】