首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Prestashop 1.5。块特殊模块中的货币登录

问Prestashop 1.5。块特殊模块中的货币登录
EN

Stack Overflow用户
提问于 2013-02-06 02:57:08
回答 1查看 2.9K关注 0票数 0

我正在使用块特殊模块,有货币显示,如你可以在图片中看到。据我所知,如果你从这里移除货币符号,你就是在商店里的任何地方移除它。也许有一种方法可以将其从区块特价中删除?这样看起来不太好。

​

​

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2013-02-12 22:05:09

此模块调用一个名为displayWtPrice的自定义prestashop智能函数(位于/classes/Tools.php中)。此函数可将数字正确地格式化为货币。如果不需要这种格式,可以从blockspecials.tpl中删除smarty函数。

默认情况下,它看起来像;

代码语言:javascript
复制
{if !$PS_CATALOG_MODE}
    <span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl}{/if}</span>
    <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price}{else}{displayWtPrice p=$special.price_tax_exc}{/if}</span>
{/if}

去掉smarty标签。

代码语言:javascript
复制
{if !$PS_CATALOG_MODE}
    <span class="price-discount">{if !$priceDisplay}{$special.price_without_reduction}{else}{$priceWithoutReduction_tax_excl}{/if}</span>
    <span class="price">{if !$priceDisplay}{$special.price}{else}{$special.price_tax_exc}{/if}</span>
{/if}

这将为您留下一个未格式化的数字。

如果您需要格式化,但没有符号,并且它只特定于这一个函数,那么您将不得不修改prestashop的核心。

您必须通过重写/扩展Tools.php - create new class /overrides/classes/Tools.php来复制/classes/Tools.php中的displayPrice函数

代码语言:javascript
复制
<?php

/**
* Tools
*/
class Tools extends ToolsCore
{

    /**
    * Return price with currency sign for a given product
    *
    * @param float $price Product price
    * @param object $currency Current currency (object, id_currency, NULL => context currency)
    * @return string Price correctly formated (sign, decimal separator...)
    */
    public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null, $showSymbol = true)
    {
        if (!is_numeric($price))
            return $price;
        if (!$context)
            $context = Context::getContext();
        if ($currency === null)
            $currency = $context->currency;
        // if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js)
        elseif (is_int($currency))
            $currency = Currency::getCurrencyInstance((int)$currency);

        if (is_array($currency))
        {
            $c_char = $currency['sign'];
            $c_format = $currency['format'];
            $c_decimals = (int)$currency['decimals'] * _PS_PRICE_DISPLAY_PRECISION_;
            $c_blank = $currency['blank'];
        }
        elseif (is_object($currency))
        {
            $c_char = $currency->sign;
            $c_format = $currency->format;
            $c_decimals = (int)$currency->decimals * _PS_PRICE_DISPLAY_PRECISION_;
            $c_blank = $currency->blank;
        }
        else
            return false;

        $blank = ($c_blank ? ' ' : '');
        $ret = 0;
        if (($is_negative = ($price < 0)))
            $price *= -1;
        $price = Tools::ps_round($price, $c_decimals);
        switch ($c_format)
        {
            /* X 0,000.00 */
            case 1:
                $ret = (($showSymbol) ? $c_char : '').$blank.number_format($price, $c_decimals, '.', ',');
                break;
            /* 0 000,00 X*/
            case 2:
                $ret = number_format($price, $c_decimals, ',', ' ').$blank.(($showSymbol) ? $c_char : '');
                break;
            /* X 0.000,00 */
            case 3:
                $ret = (($showSymbol) ? $c_char : '').$blank.number_format($price, $c_decimals, ',', '.');
                break;
            /* 0,000.00 X */
            case 4:
                $ret = number_format($price, $c_decimals, '.', ',').$blank.(($showSymbol) ? $c_char : '');
                break;
            /* 0 000.00 X  Added for the switzerland currency */
            case 5:
                $ret = number_format($price, $c_decimals, '.', ' ').$blank.(($showSymbol) ? $c_char : '');
                break;
        }
        if ($is_negative)
            $ret = '-'.$ret;
        if ($no_utf8)
            return str_replace('€', chr(128), $ret);
        return $ret;
    }



}

现在,您需要使用与我们使用工具相同的方式进行覆盖,但这次是Product类中的函数displayWtPrice。

我们将重写此函数,如下所示;

代码语言:javascript
复制
public static function displayWtPrice($params, &$smarty)
    {
        return Tools::displayPrice($params['p'], Context::getContext()->currency, false, null, (($params['showsymbol'] == false) ? false : true));
    }

我们已经指定了附加的函数参数,该参数将从smarty获取(如果提供)。

现在您需要在displayWtPrice中使用showsymbol=false中的附加参数修改blockspecials.tpl

代码语言:javascript
复制
{if !$PS_CATALOG_MODE}
    <span class="price-discount">{if !$priceDisplay}{displayWtPrice p=$special.price_without_reduction showsymbol=false}{else}{displayWtPrice p=$priceWithoutReduction_tax_excl showsymbol=false}{/if}</span>
    <span class="price">{if !$priceDisplay}{displayWtPrice p=$special.price showsymbol=false}{else}{displayWtPrice p=$special.price_tax_exc showsymbol=false}{/if}</span>
{/if}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14714818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档