我正在使用 Magento 2.2.3。我的默认货币是 INR,但它以错误的格式显示:
但它应该是 77,65,000.00 卢比。我们如何纠正价格格式?目前它是错误的......比如美元。
您可以通过以下代码设置货币格式。
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of Object Manager
$priceHelper = $objectManager->create('Magento\Framework\Pricing\Helper\Data'); // Instance of Pricing Helper
$price = 1000; //Your Price
$formattedPrice = $priceHelper->currency($price, true, false);
?>
文件路径:vendor/magento/zendframework1/library/Zend/Locale/Data/en.xml
在第 3353 行,在 currencyFormat 和 type = "standard" 部分下,将模式从更改 <pattern>¤#,##0.00</pattern>
为<pattern>¤ #,##,##0.00</pattern>
尽管如此,在 PDP 页面和购物车页面摘要上,价格格式并没有改变,因为奖品格式来自 JS,其中 Magento 使用 RegExp 函数仅用于美国价格格式。为此,请更改以下文件中的代码。
文件路径:(vendor/magento/module-catalog/view/base/web/js/price-utils.js
首先在您的主题目录中扩展此文件并进行相应的更改)
在此行下方的函数 formatPrice 下,注释相应函数中的所有行。
i = parseInt(
amount = Number(Math.round(Math.abs(+amount || 0) + 'e+' + precision) + ('e-' + precision)),
10
) + '';
并将这组代码添加到上述行的下方。
var x=i;
x=x.toString();
var afterPoint = '';
if(x.indexOf('.') > 0)
afterPoint = x.substring(x.indexOf('.'),x.length);
x = Math.floor(x);
x=x.toString();
var lastThree = x.substring(x.length-3);
var otherNumbers = x.substring(0,x.length-3);
if(otherNumbers != '')
lastThree = ',' + lastThree;
var response = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree + afterPoint;
return pattern.replace('%s', response);
部署和`rm -rf var/cache/*
然后你就完成了。例如:以前显示的价格如453,453
,现在将以印度方式显示,如4,53,453
。