Magento 2 – How to Change Currency Symbol or Add Custom Currency

currencymagento2

Is there a way to add an own currency? Like "Points".

I tried to write a plugin to intercept after \Magento\Directory\Model\PriceCurrency::getCurrencySymbol but it seems, that this method is not used to format price for frontend.

My Plugin looks like

class PluginAfter
{

/**
 * @param string $interceptedInput
 * @param string $interceptedOutput
 *
 * @return string 'Points'
 *
 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
 */
public function afterGetCurrencySymbol($interceptedInput, $interceptedOutput)
{
    die('getCurrencySymbol'); // not triggered

    return __('Points');
}

So i tried to intercept \Magento\Directory\Model\PriceCurrency::getCurrency
but there is no option to set new currencysymbol

Any suggestions?

Best Answer

Thanks for pointing out the file,

I can add that is no need to implement an observer for that.

You can add a customsymbol node in your own module in config.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <currency>
            <options>
                <customsymbol>a:1:{s:3:"RON";s:3:"Lei";}</customsymbol>
            </options>
        </currency>

        <!-- ... -->

    </default>

    <!-- ... -->

</config>

Where RON is my currency code ( similar to USD for american dollar ), and Lei is my new currency symbol I want to use.

Notice that the accepted value is only a serialized array with currency code as key and custom currency symbol as value.

Thanks!

Related Topic