首先,先理清magento价格格式的逻辑:
1.根据 use Magento\Framework\Pricing\PriceCurrencyInterface;
在\vendor\magento\framework\Pricing\PriceCurrencyInterface.php里找到public function format()
方法。
2.format()
调用了vendor\magento\module-directory\Model\Currency.php文件中的format()
方法,依次调用了public function formatTxt()
方法。
3.formatTxt()
又调用了vendor\magento\zendframework1\library\Zend\Currency.php里的 public function toCurrency()
方法。
找到toCurrency()
函数时,您将看到$ options数组变量,其中包含用于格式化价格值的所有必要信息。以下是var_dump$ options的。
array(12) {
["position"] => int(16)
["script"] => NULL
["format"] => NULL
["display"] => int(2)
["precision"] => int(2)
["name"] => string(9) "US Dollar"
["currency"] => string(3) "USD"
["symbol"] => string(1) "$"
["locale"] => string(5) "en_GB"
["value"] => int(0)
["service"] => NULL
["tag"] => string(11) "Zend_Locale"
}
toCurrency()
中的下面这段代码Zend_Locale_Data方法又调用了
\vendor\magento\zendframework1\library\Zend\Locale\Data.php中的getContent()
方法,
if (empty($format)) {
$format = Zend_Locale_Data::getContent($locale, 'currencynumber');
} else if (Zend_Locale::isLocale($format, true, false)) {
$locale = $format;
$format = Zend_Locale_Data::getContent($format, 'currencynumber');
}
根据"currencynumber"
值找到
vendor\magento\zendframework1\library\Zend\Locale\Data\zh.xml文件,下面即为 价格格式,空格为¤ #
中间的空格,把他去掉即可。
<currencyFormats numberSystem="latn">
<currencyFormatLength>
<currencyFormat type="stan