2013-02-05 88 views
0

我正在使用blockspecials模塊,並有貨幣顯示,你可以在圖片中看到。只要我知道,如果您從這裏刪除貨幣符號,就可以將其從商店的任何地方移除。也許有一種方法可以從blockspecials中移除它?這樣看起來不太好。Prestashop 1.5。貨幣符號blockspecials模塊

enter image description here

感謝提前的幫助。

回答

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的核心。

你將不得不通過覆蓋複製在/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.tplshowsymbol=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}