我们尝试使用prestashop函数ConvertPrice(在Tools类中)覆盖这个链接:
<span>750</span>,00€
在我的覆盖中使用此代码:
/**
* Return price converted
*
* @param float $price Product price
* @param object $currency Current currency object
* @param boolean $to_currency convert to currency or from currency to default currency
*/
public static function convertPrice($price, $currency = NULL, $to_currency = true)
{
if ($currency === NULL)
$currency = Currency::getCurrent();
elseif (is_numeric($currency))
$currency = Currency::getCurrencyInstance($currency);
$c_id = (is_array($currency) ? $currency['id_currency'] : $currency->id);
$c_rate = (is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate);
if ($c_id != (int)(Configuration::get('PS_CURRENCY_DEFAULT')))
{
if ($to_currency)
$price *= $c_rate;
else
$price /= $c_rate;
}
$price = explode(".", strval($price));
$temp = '<span>'.$price[0]."</span>";
$price[0] = $temp;
return implode(".", $price);
}
答案 0 :(得分:6)
我自己创建了一个解决方案,我没有编辑正确的功能,所以有正确的方法:
public static function displayPrice($price, $currency = NULL, $no_utf8 = false){
if ($currency === NULL)
$currency = Currency::getCurrent();
if (is_int($currency))
$currency = Currency::getCurrencyInstance((int)($currency));
$c_char = (is_array($currency) ? $currency['sign'] : $currency->sign);
$c_format = (is_array($currency) ? $currency['format'] : $currency->format);
$c_decimals = (is_array($currency) ? (int)($currency['decimals']) : (int)($currency->decimals)) * _PS_PRICE_DISPLAY_PRECISION_;
$c_blank = (is_array($currency) ? $currency['blank'] : $currency->blank);
$blank = ($c_blank ? ' ' : '');
$ret = 0;
if (($isNegative = ($price < 0)))
$price *= -1;
$price = self::ps_round($price, $c_decimals);
switch ($c_format){
/* X 0,000.00 */
case 1:
$ret = $c_char.$blank.number_format($price, $c_decimals, '.', ',');
break;
/* 0000,00 X*/
case 2:
$ret = number_format($price, $c_decimals, ',', '').$blank.$c_char;
$price = explode(",", strval($ret));
$price[0] = '<span>'.$price[0]."</span>";
$ret = implode(",", $price);
break;
/* X 0.000,00 */
case 3:
$ret = $c_char.$blank.number_format($price, $c_decimals, ',', '.');
break;
/* 0,000.00 X */
case 4:
$ret = number_format($price, $c_decimals, '.', ',').$blank.$c_char;
break;
}
if ($isNegative)
$ret = '-'.$ret;
if ($no_utf8)
return str_replace('€', chr(128), $ret);
return $ret;
}
在override / classes / Tools.php
中