【问题标题】:How to change price format or locale options in Magento 1.5?如何在 Magento 1.5 中更改价格格式或区域设置选项?
【发布时间】:2011-10-10 11:57:24
【问题描述】:

我打算用magento写一个常见问题和一个最适合我的解决方案。

我已经在网上搜索并反映了几个小时的 magento 代码,以找到上述问题的解决方案。我希望匈牙利价格格式为 1 000 Ft 而不是 1 000,00 Ft

我已将值'precision' 替换为0,但没有成功。 这是我探索的列表:

  • app/code/core/Mage/Core/Model/Store.php

    function formatPrice(){ $option = array('precison' => 2 ); ... }

  • app/code/core/Mage/Directory/Model/Currency.php

    function format() { $this->formatPrecision($price, 0, $options, $includeContainer, $addBrackets); }

在反映了代码之后,我意识到这一切的改变根本无关紧要,因为数字格式信息是基于 Zend 核心 API 提供的 locale 信息。

这是我找到的解决方案,希望价格格式将成为整个应用程序的标准。

您可以在 lib/Zend/Locale/Data/ 中找到您的 YY.xml 文件,其中 YY 是您所在国家/地区的语言环境代码。我的是 hu.xml

你找到了零件:

<currencyFormats>
    <currencyFormatLength>
        <currencyFormat>
            <pattern>#,##0 ¤</pattern>
        </currencyFormat>
    </currencyFormatLength>
    <unitPattern count="other">{0} {1}</unitPattern>
</currencyFormats>

关于格式字符串,您可以在http://framework.zend.com/manual/en/zend.locale.parsing.html找到一个完全没有用的信息

【问题讨论】:

  • 格式字符串链接失效

标签: magento localization locale precision number-formatting


【解决方案1】:

将“app/code/core/Mage/Directory/Model/Currency.php”复制到“app/code/local/Mage/Directory/Model/Currency.php”并替换格式函数。

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

【讨论】:

  • 你不需要使用str_replace,只需将第二个参数从2修改为0
猜你喜欢
  • 2014-04-28
  • 1970-01-01
  • 2016-03-12
  • 1970-01-01
  • 2015-01-31
  • 2011-05-07
  • 2022-01-01
  • 1970-01-01
  • 2012-07-17
相关资源
最近更新 更多