我正在使用blockspecials模块,并有货币显示,你可以在图片中看到。只要我知道,如果您从这里删除货币符号,就可以将其从商店的任何地方移除。也许有一种方法可以从blockspecials中移除它?这样看起来不太好。Prestashop 1.5。货币符号blockspecials模块
感谢提前的帮助。
我正在使用blockspecials模块,并有货币显示,你可以在图片中看到。只要我知道,如果您从这里删除货币符号,就可以将其从商店的任何地方移除。也许有一种方法可以从blockspecials中移除它?这样看起来不太好。Prestashop 1.5。货币符号blockspecials模块
感谢提前的帮助。
该模块正在调用一个名为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的核心。
你将不得不通过覆盖复制在/classes/Tools.php的displayPrice功能/扩展Tools.php - 创建新类/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));
}
我们已经指定将从智者如果提供所采取的附加功能参数。
现在,你需要在displayWtPrice
额外的参数去修改blockspecials.tpl
showsymbol=false
{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}