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?

4 Answers 4

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!

1
  • i did this and nothing changed .... should i see the new symbol in Currency setup section of admin? Commented Oct 25, 2016 at 15:26
1

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>
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

4
  • can u post your code asap? Commented Oct 24, 2016 at 21:34
  • asap? rly? let me look for it Commented Oct 25, 2016 at 7:28
  • what happened ? u lost it? Commented Oct 25, 2016 at 15:27
  • @KevinKrieger, pls update the code Commented Aug 13, 2019 at 14:27
0

You guys can use this extension.

https://marketplace.magento.com/extrembler-overridecurrencysymbol.html

It works as per store views.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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