2014-12-04 49 views
5

我在我的搜索中发现的所有内容都是一个编程解决方案。 我知道我们可以修改/lib/Zend/Locale/Data/en.xml英文商店。 有在en.xml这一部分:如何从Magento-1价格中删除小数?

 <currencyFormats> 
      <currencyFormatLength> 
       <currencyFormat> 
        <pattern>#,##0.00 ¤</pattern> 
       </currencyFormat> 
      </currencyFormatLength> 
     </currencyFormats> 

而且价格显示格式为:1,321.54 现在从价格移除小数部分,我想我必须做的唯一的事情就是变化en.xml是这样的:

<currencyFormats> 
      <currencyFormatLength> 
       <currencyFormat> 
        <pattern>#,##0 ¤</pattern> 
       </currencyFormat> 
      </currencyFormatLength> 
     </currencyFormats> 

问题是这样的变化之后根据需要将价格显示(1132格式),但没有货币符号($)。 我在这里错过了什么? 在此先感谢。


更新 我还在努力,当模式节点更改为以下

<pattern>¤ #,##0</pattern> 

价格与货币符号($ 1,132)来,但不期望位置O_O,要求货币符号在右边没有剩下:(因此...

+0

请尝试使用此扩展名。 http://www.magentocommerce.com/magento-connect/price-rounding.html 它通常用于处理多种货币。 – Harit 2014-12-04 08:59:10

+0

感谢您的回复,我不会使用编程解决方案,解决方案是在en.xml中,但无法弄清楚 – rramiii 2014-12-04 09:48:33

回答

4

In或要改变magento的价格精度,你需要覆盖一些核心文件。

在下面的例子我们正在改变精度为0

1)覆盖LIB/Zend的/ Currency.php和改变周围的线精度:

69  protected $_options = array(
70   'position' => self::STANDARD, 
71   'script' => null, 
72   'format' => null, 
73   'display' => self::NO_SYMBOL, 
74   'precision' => 0, /*CHANGE*/ 
75   'name'  => null, 
76   'currency' => null, 
77   'symbol' => null, 
78   'locale' => null, 
79   'value'  => 0, 
80   'service' => null, 
81   'tag'  => 'Zend_Locale' 
82 ); 

2)重写应用程序/code/core/Mage/Core/Model/Store.php并更改roundPrice功能:

public function roundPrice($price) 
{  
    return round($price, 4); 
} 

3)重写应用程序/代码/核心/法师/目录/型号/ Currency.php和更改格式功能:

public function format($price, 
          $options=array(), 
          $includeContainer = true, 
          $addBrackets = false) 
{ 
    return $this->formatPrecision($price, 
             4, 
             $options, 
             $includeContainer, 
             $addBrackets); 
} 
+0

谢谢,我认为这是唯一的方法..但我可以确保所有价格是在ceil价值观和所有结帐过程? – rramiii 2014-12-04 11:47:39

+1

而不是4你必须使用0其他明智将有4位十进制数字。 – rramiii 2014-12-04 13:17:34

3

要删除的小数部分的价格,您需要修改文件 “代码/core/Mage/Directory/Model/Currency.php”

首先,以替代线路:

return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets); 

使用:

return $this->formatPrecision($price, 0, $options, $includeContainer, $addBrackets); 

要更改货币符号的位置,修改文件“lib/Zend公司/地点/数据/ en.xml”与线:

<pattern>#,##0.00 ¤;(#,##0.00 ¤)</pattern> 

完成后,不要忘记清除缓存。

P.S.为避免升级过程中出现任何问题,我们强烈建议您通过扩展来实现上述所有更改: (在此检查工具:http://www.magentocommerce.com/magento-connect/catalogsearch/result/?id=&s=7&pl=0&eb=0&hp=0&q=currency|position&t=1&p=1

+0

谢谢..我做到了这一点 – rramiii 2014-12-07 14:07:52

2

要从价格中删除小数部分,您需要修改文件:

1)首先是改变精度围绕线

LIB /的Zend/Currency.php

protected $_options = array(
    'position' => self::STANDARD, 
    'script' => null, 
    'format' => null, 
    'display' => self::NO_SYMBOL, 
    'precision' => 2, 
    'name'  => null, 
    'currency' => null, 
    'symbol' => null, 
    'locale' => null, 
    'value'  => 0, 
    'service' => null, 
    'tag'  => 'Zend_Locale' 
); 

变化= '精度'=> 2, '精确'=> 0,

2)第二文件(变化roundPrice函数:)

应用程序/代码/核心/法师/核心/型号/Store.php

public function roundPrice($price) 
{ 
    return round($price, 2); 
} 

public function roundPrice($price) 
{ 
    return round($price, 0); 
} 

3)三和最后一个是改变格式功能:

应用程序/代码/核心/法师/目录/型号/ Currency.php

public function format($price, 
         $options=array(), 
         $includeContainer = true, 
         $addBrackets = false) 
{ 
return $this->formatPrecision($price, 
            2, 
            $options, 
            $includeContainer, 
            $addBrackets); 
} 

TO

public function format($price, 
         $options=array(), 
         $includeContainer = true, 
         $addBrackets = false) 
{ 
return $this->formatPrecision($price, 
            0, 
            $options, 
            $includeContainer, 
            $addBrackets); 
} 
6

所有答案在这里涉及更改核心文件。这是不是任何人都应该做的。要么开发一个模块并进行这些更改,要么保留这样的核心文件,并用str_replace更改价格。

所以进入theme/template/catalog/product/price.phtml和(取决于配置)围绕线路209改变这样的:

$_coreHelper->formatPrice($_price, true) 

$without_decimals = $_coreHelper->formatPrice($_price, true); echo str_replace(".00", "", $without_decimals); 

这消除了从价格.00。好事是保留其他小数的价格。如果你不想要这个,你可以删除点后面的所有内容,并用round()函数将数字加起来。

根据配置的不同等价格可能需要的变化(如果你表现出的价格不含税等)

+0

我认为这有点不对,因为它不仅仅是观看价格没有小数,如果我遵循你的方式,magento将使订单无价格,前端将价格圆整。不是吗? – rramiii 2015-07-02 04:50:28

+0

@rramiii如果您的值不是0作为小数,您必须在ajax中添加购物车,以便在结账时保持这些价格不变。但我不明白为什么有人会插入价格为56.89,并希望它显示在前端57.只是在后端57. – 2015-07-02 08:21:03

+0

有几个原因,这是行不通的。 1.它只适用于以.00结尾的价格。因此,当产品在销售中时,它将不起作用,并且您可以得到价格的十进制值。 2.它不适用于可配置产品。虽然价格来自助手,但它们会被javascript替换为getJsonConfig中创建的JSON数组Product.OptionsPrice的内容。 – aeu 2016-11-29 19:18:15

0

你可以做一个更多的变化除了上述的一切。

请到 的PriceCurrency.php页面,则最后一行改为

public function round($price) 
{ 
    return round($price, 0); 
} 

后,在PriceCurrencyInterface.php页面使

const DEFAULT_PRECISION = 0; 

在顶部。

就是这样。希望它能起作用。

相关问题