我正在使用blockspecials模块,并且您可以在图片中看到显示的货币。只要我知道,如果你从这里删除货币符号,你可以从商店的任何地方删除它。也许有一种方法可以从块特殊中删除它?这种方式看起来不太好。
提前感谢您的帮助。
答案 0 :(得分:0)
此模块正在调用名为displayWtPrice的自定义prestashop smarty函数(位于/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复制/classes/Tools.php中的displayPrice函数 - 创建新类/overrides/classes/Tools.php
<?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;
}
}
现在您需要以与使用Tools相同的方式覆盖,但这次是Product类中的函数displayWtPrice
。
我们会覆盖此功能,如下所示;
public static function displayWtPrice($params, &$smarty)
{
return Tools::displayPrice($params['p'], Context::getContext()->currency, false, null, (($params['showsymbol'] == false) ? false : true));
}
我们已经指定了附加功能参数,如果提供的话,它将从smarty中获取。
现在您需要使用blockspecials.tpl
displayWtPrice
中的附加参数修改showsymbol=false
1>
{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}