开发者

ConvertPrice changing

I guys i try to make something link this with开发者_C百科 an override on a prestashop function ConvertPrice (in Tools class) :

<span>750</span>,00€

With this code in my override :

/**
* 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);
}


I founded a solution by myself, i didn't edit the right function so there is the correct way :

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;
}

In override/classes/Tools.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜