首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ubercart 3的多货币(Drupal 7)

Ubercart 3的多货币(Drupal 7)
EN

Stack Overflow用户
提问于 2011-10-07 22:27:20
回答 2查看 2.7K关注 0票数 3

Ubercart3(Drupal7)有没有什么解决方案(比如Drupal Ubercart: multi-currency? )或者更好的实现这些东西的小贴士?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-02-10 07:16:44

我不建议你硬编码它。在下一次更新时,您将丢失所有更改。请尝试查看此主题:http://drupal.org/node/1434470#comment-5582812

票数 1
EN

Stack Overflow用户

发布于 2011-10-30 05:47:02

作为解决方案之一,我找到并使用了以下内容:

在ubercart/store/uc_store.module中添加新定义,例如

代码语言:javascript
复制
define('RUR',0.33);

其中0.33 -是默认货币和新货币(RUR)之间的差异。rur/美元= 0.33

并在uc_currency_format函数中添加以下内容:

代码语言:javascript
复制
  global $language;
  if ($language->language=='ru') {
    $sign = ' RUB'; 
    $thou = ','; 
    $dec = '.';    
    $value = $value / RUR;
    $sign_after = FALSE;
  };

和完整的功能:

代码语言:javascript
复制
function uc_currency_format($value, $sign = NULL, $thou = NULL, $dec = NULL) {
  if ($value === NULL) {
    return NULL;
  }

  $output = '';

  $sign_after = variable_get('uc_sign_after_amount', FALSE);
  $prec = variable_get('uc_currency_prec', 2);
  if (is_null($sign)) {
    $sign = variable_get('uc_currency_sign', '$');
  }
  if (is_null($thou)) {
    $thou = variable_get('uc_currency_thou', ',');
  }
  if (is_null($dec)) {
    $dec = variable_get('uc_currency_dec', '.');
  };

  // If the value is significantly less than the minimum precision, zero it.
  if ($prec > 0 && round(abs($value), $prec + 1) < pow(10, -$prec)) {
    $value = 0;
  }

  global $language;
  if ($language->language=='ru') {
    $sign = '$'; 
    $thou = ','; 
    $dec = '.';    
    $value = $value / RUR;
    $sign_after = FALSE;
  };

  // Force the price to a positive value and add a negative sign if necessary.
  if ($value < 0) {
    $value = abs($value);
    $output .= '-';
  }

  // Add the currency sign first if specified.
  if ($sign && !$sign_after) {
    $output .= $sign;
  }

  // Format the number, like 1234.567 => 1,234.57
  $output .= number_format($value, $prec, $dec, $thou);

  // Add the currency sign last if specified.
  if ($sign && $sign_after) {
    $output .= $sign;
  };

  if ($value=='0') {
  $output = t('free'); 
  };
  return $output;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7688662

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档