1

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?

2

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!

  • i did this and nothing changed .... should i see the new symbol in Currency setup section of admin? – Sina Miandashti Oct 25 '16 at 15:26
0

Finally I managed changing the currency symbol via event/observer according to magento/module-currency-symbol and magento/module-currency-symbol/Observer/CurrencyDisplayOptions.php

0

You can use the solution Kevin Krieger posted. So create/edit config.xml file in any module and instead of a serialized array add a JSON array.

Using a serialized array caused an exception in my case (Unable to unserialize array - while it was acutally a valid string), but using JSON worked for me.

Here is an example:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <currency>
            <options>
                <customsymbol>{"RSD":"rsd"}</customsymbol>
            </options>
        </currency>
    </default>
</config>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.