我只是OpenCart的新手。我用它做了一个电子商务。在该网站中,具有多语言的功能,并具有多货币转换器选项。现在,我希望当用户点击他的语言时,它也应该将货币转换为他的语言。因此,可以使用OpenCart做到这一点。有人可以共享任何代码或任何参考链接,以便我可以做到这一点。任何帮助和建议都将是高度可观的。谢谢。
opencart管理面板中有一个货币选项,路径就是这样:
系统>本地化>货币
您可以更改并添加与特定语言有关的货币选项。
if ($currency && $this->has($currency)) {
$symbol_left = $this->currencies[$currency]['symbol_left'];
$symbol_right = $this->currencies[$currency]['symbol_right'];
$decimal_place = $this->currencies[$currency]['decimal_place'];
} else {
if($_SESSION['language']=="es"):
$symbol_right = $this->currencies[$this->code]['symbol_right'];
else:
$from="USD";
$to="MXN";
$path = "http://www.google.com/ig/calculator?hl=en&q=1".$from."=?".$to;
$rawdata = file_get_contents($path);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
$e=round($var,3);
if ($e):
$number=$number / $e;
else:
$default_dollar=12.863;
$number=$number / $default_dollar;
endif;
$symbol_right=" USD";
endif;
$symbol_left = $this->currencies[$this->code]['symbol_left'];
$decimal_place = $this->currencies[$this->code]['decimal_place'];
$currency = $this->code;
}
有一个函数:
public function format($number, $currency = '', $value = '', $format = true) {
if ($currency && $this->has($currency)) {
$symbol_left = $this->currencies[$currency]['symbol_left'];
$symbol_right = $this->currencies[$currency]['symbol_right'];
$decimal_place = $this->currencies[$currency]['decimal_place'];
} else {
$symbol_left = $this->currencies[$this->code]['symbol_left'];
$symbol_right = $this->currencies[$this->code]['symbol_right'];
$decimal_place = $this->currencies[$this->code]['decimal_place'];
$currency = $this->code;
}
如果您仔细查看,则可以根据语言更改此处的货币,也可以使用jQuery发送ajax的货币更改请求。