网站开发 · 2025年4月26日

验证ZenCart货币类型是否存在函数zen_currency_exist

ZenCart 的 zen_currency_exists 函数是检验指定的货币代码的货币是否存在,如果存在返回该货币的货币代码,如果不存在,返回false 第一个参数就是指定货币的货币代码,比如美元就是usd

第二个参数是指是否返回默认货币,就是网站指定的默认货币,汇率为1的

函数原型代码

function zen_currency_exists($code, $getFirstDefault = false) {

global $db;

$code = zen_db_prepare_input($code);

$currency_code = “select code

from ” . TABLE_CURRENCIES . ”

where code = ‘” . zen_db_input($code) . “‘ LIMIT 1″;

$currency_first = “select code

from ” . TABLE_CURRENCIES . ”

order by value ASC LIMIT 1″;

$currency = $db->Execute(($getFirstDefault == false) ? $currency_code : $currency_first);

if ($currency->RecordCount()) {

return strtoupper($currency->fields[‘code’]);

} else {

return false;

}

}