ecshop在php5.3上報錯:
Warning: number_format() expects parameter 1 to be double, string given inD:/*******/includes/lib_common.php on line 959
Warning: number_format() expects parameter 1 to be double, string given inD:/*******/includes/lib_common.php on line 959
這個錯誤是ecshop 在php5.3以上的報錯
原因是配送插件里面的免費額度為0,ec本身的bug導(dǎo)致了$price的值為空值,直接調(diào)用number_format出現(xiàn)了錯誤。
解決方案如下:
/**
* 格式化商品價格
*
* @access public
* @param float $price 商品價格
* @return string
*/
function price_format($price, $change_price = true)
{
if ($change_price && defined('ECS_ADMIN') === false)
{
switch ($GLOBALS['_CFG']['price_format'])
{
case 0:
$price = number_format($price, 2, '.', '');
break;
case 1: // 保留不為 0 的尾數(shù)
$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: // 先四舍五入,不保留小數(shù)
$price = round($price);
break;
}
}
else
{
if(!$price){
$price = 0;
}
$price = number_format($price, 2, '.', '');
}
return sprintf($GLOBALS['_CFG']['currency_format'], $price);
}
新聞熱點
疑難解答
圖片精選