Magento 2 Currency symbol is not showing

4.6k Views Asked by At

I have 2 stores English and Arabic. Default Store is Arabic and default currency is SAR. Currency symbol is showing fine on English Store but not showing anywhere on Arabic store. It only showing price like this 44 on product listing page and on single product page.

5

There are 5 best solutions below

3
On BEST ANSWER

I fixed it. Posting my answer may be it can help someone.

edit this file.

vendor\magento\zendframework1\library\Zend\Locale\Data\ar_SA.xml

and remove following code.

<numbers>
<currencyFormats numberSystem="latn">
<currencyFormatLength>
<currencyFormat type="standard">
<pattern>¤#0.00</pattern>
</currencyFormat>
</currencyFormatLength>
</currencyFormats>
</numbers>

UPDATED ANSWER ========

I got better solution instead editing core file you can do it with observer.

Vendor/Module/etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="currency_display_options_forming">
        <observer name="change_currency_position" instance="Vendor\Module\Model\Observer\ChangeCurrencyPosition" />
    </event>
</config>

and observer File.

use Magento\Framework\Event\ObserverInterface;
class ChangeCurrencyPosition implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $currencyOptions = $observer->getEvent()->getCurrencyOptions();
        $currencyOptions->setData('position', \Magento\Framework\Currency::RIGHT);
        return $this;
    }
}

Need to change the 'position' to RIGHT.

0
On

Update ar_SA.xml like below:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ldml SYSTEM "../../common/dtd/ldml.dtd">
<!-- Copyright © 1991-2013 Unicode, Inc.
CLDR data files are interpreted according to the LDML specification (http://unicode.org/reports/tr35/)
For terms of use, see http://www.unicode.org/copyright.html
-->
<ldml>
    <identity>
        <version number="$Revision: 9287 $"/>
        <generation date="$Date: 2013-08-28 21:32:04 -0500 (Wed, 28 Aug 2013) $"/>
        <language type="ar"/>
        <territory type="SA"/>
    </identity>
    <dates>
        <calendars>
            <calendar type="islamic">
                <dateTimeFormats>
                    <availableFormats>
                        <dateFormatItem id="Md" draft="contributed">M/d</dateFormatItem>
                        <dateFormatItem id="MEd" draft="contributed">E, M/d</dateFormatItem>
                        <dateFormatItem id="MMMd" draft="contributed">MMM d</dateFormatItem>
                        <dateFormatItem id="MMMEd" draft="contributed">E, MMM d</dateFormatItem>
                    </availableFormats>
                </dateTimeFormats>
            </calendar>
        </calendars>
    </dates>
    <numbers>
        <symbols numberSystem="latn">
            <decimal>.</decimal>
            <group>,</group>
            <list>;</list>
            <percentSign>%</percentSign>
            <plusSign>+</plusSign>
            <minusSign>-</minusSign>
            <exponential>E</exponential>
            <superscriptingExponent>×</superscriptingExponent>
            <perMille>‰</perMille>
            <infinity>∞</infinity>
            <nan>NaN</nan>
        </symbols>
        <decimalFormats numberSystem="latn">
            <decimalFormatLength>
                <decimalFormat>
                    <pattern>#,##0.###</pattern>
                </decimalFormat>
            </decimalFormatLength>
        </decimalFormats>
        <currencyFormats numberSystem="latn">
            <currencyFormatLength>
                <currencyFormat type="standard">
                    <pattern>¤#,##0.00</pattern>
                </currencyFormat>
                <currencyFormat type="accounting">
                    <pattern>¤#,##0.00;(¤#,##0.00)</pattern>
                </currencyFormat>
            </currencyFormatLength>
            <unitPattern count="one">{0} {1}</unitPattern>
            <unitPattern count="other">{0} {1}</unitPattern>
        </currencyFormats>
        <currencies>
            <currency type="USD">
                <displayName>US Dollar</displayName>
                <displayName count="one">US dollar</displayName>
                <displayName count="other">US dollars</displayName>
                <symbol>$</symbol>
            </currency>
        </currencies>
    </numbers>
</ldml>
0
On

I fixed it.

We were running into this issue on m2.4.3 and 2.4.5.

Viewing the screenshots on Safari's Timeline feature on Inspect Element, I could see when the currency symbol disappears. You can see just before the symbol disappears that there are two .js scripts running. Filtering by "price" results in price-box.js line 148, which is located in:

vendor/magento/module-catalog/view/base/web/js/price-box.js

I copied this file into our theme: <vendor>/<theme>/Magento_Catalog/web/js/price-box.js

and where it said:

_.each(this.cache.displayPrices, function (price, priceCode) {

I removed the ".cache" from the code and it now runs perfectly. eg:

    _.each(this.displayPrices, function (price, priceCode) {

Haven't seen any dramatic slowdown in pageload speed

0
On

Its a bug in 2.4.3:

src\vendor\magento\module-directory\Model\Currency.php

Comment out these lines:

if ($this->canUseNumberFormatter($options)) {
    return $this->formatCurrency($price, $options);
}

Then:

php -dmemory_limit=6G bin/magento setup:upgrade
php -dmemory_limit=6G bin/magento setup:di:compile
php -dmemory_limit=6G bin/magento setup:static-content:deploy -f
php -dmemory_limit=6G bin/magento cache:flush

Editing core is bad, we can create preference.

2
On

If @Ask4Tec's solution is not working

Try this

Copy the currency and numbers block from en.xml file and paste it into the ar_SA.xml file Clean and flush cache Check after hard refresh