magento2.4 去除价格符号¥跟 价格之间的空格

首先,先理清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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值