Home » Magento20 July 2010

Magento: How to change Currency symbol by Model Override ?

In my previous article, I had written about how you can change the currency symbol by making some change in the Zend (lib/Zend/Locale/Data/en.xml) file.

It’s easy way but the main drawback of this method is that all your changes will vanish once you upgrade Magento.

A better way will be overriding Magento model classes that are responsible for fetching the currency symbol.

This article shows how to override Magento model classes to change the currency symbol.

Scenario

I need to change the currency symbol of Nepalese Rupee (from Nrs to Rs). By default, the currency symbol for Nepalese Rupee is Nrs.

Solution

Create a new module and Override two model classes.

1) Mage_Core_Model_Locale_Currency
2) Mage_Core_Model_Locale

Config file of my module
(MyNamespace/MyModule/etc/config.xml)

MyNamespace_MyModule_Model_Locale_Currency class of my module
(MyNamespace/MyModule/Model/Locale/Currency.php)

In this class I have changed currency symbol from Nrs to Rs.

MyNamespace_MyModule_Model_Locale class of my module
(MyNamespace/MyModule/Model/Locale.php)

In this way, you can override Magento Model classes to change the currency symbol.

Hope this helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Hi Mukesh,

    I have Magento 1.4.1 and your module seem to be not working ?

    Have a idea ?

    Thanks

  • Saurabh

    Hi,

    How to integrate new rupee sumbol in magento,

    I tried the CSS way but it don’t work

    Thanks & Regards,
    Saurabh

  • Anatoliy

    Hi,

    it is new article, good approach, but it doesnt work. To get it running change your Locale.php to this:


    class MyNamespace_MyModul_Model_Locale extends Mage_Core_Model_Locale
    {

    /**
    * Create Zend_Currency object for current locale
    *
    * @param string $currency
    * @return Zend_Currency
    */
    public function currency($currency)
    {
    Varien_Profiler::start('locale/currency');
    if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) {
    try {
    $currencyObject = new Zend_Currency($currency, $this->getLocale());
    if ($currency == "UAH") {
    $currencyObject->setFormat(array('symbol'=> 'грн'));
    }
    } catch (Exception $e) {
    $currencyObject = new Zend_Currency($this->getCurrency(), $this->getLocale());
    $options = array(
    'name' => $currency,
    'currency' => $currency,
    'symbol' => $currency
    );
    $currencyObject->setFormat($options);
    }

    self::$_currencyCache[$this->getLocaleCode()][$currency] = $currencyObject;
    }
    Varien_Profiler::stop('locale/currency');
    return self::$_currencyCache[$this->getLocaleCode()][$currency];
    }
    }

    And config-file should look like this:

    Narechena_Zend_Model_Locale

    Regards,
    Anatoliy