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

提前感谢您的帮助。
发布于 2013-02-12 22:05:09
此模块调用一个名为displayWtPrice的自定义prestashop智能函数(位于/classes/Tools.php中)。此函数可将数字正确地格式化为货币。如果不需要这种格式,可以从blockspecials.tpl中删除smarty函数。
默认情况下,它看起来像;
{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标签。
{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函数
<?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。
我们将重写此函数,如下所示;
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
{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}https://stackoverflow.com/questions/14714818
复制相似问题