Subesh Pokhrel

Magento Developers Blog

Displaying Currency Code After the Price Value in Magento

I had a time to research on Magento’s currency format and its display on Magento webshop. I then came across a block where I could change the format of currency display, in this case I am talking about moving the currency symbol to the right of the price value. In other words I found a way to show $10.00 as 10.00$. Notice the $ (Dollar) sign moving at the right of the price value. Here’s a description of how this can be achievable. The basic idea is to rewrite Mage_Core_Model_Locale class’s currency function and add additional code. First you must write a rewrite code in your module’s config.xml. [source language=”xml”] <core> <rewrite> <locale>Namespace_Module_Model_Locale</locale> </rewrite> </core> [/source] Then in Namespace_Module_Model_Locale class you can add the following code. [source language=”php”] class Namespace_Module_Model_Locale extends Mage_Core_Model_Locale{ /* * Code: subesh.com.np */ public function currency($currency) { Varien_Profiler::start(‘locale/currency’); if (!isset(self::$_currencyCache[$this->getLocaleCode()][$currency])) { try { $currencyObject = new Zend_Currency($currency, $this->getLocale()); // Additionally Added Code // The options array’s position key has other values as well. // Zend_Currency::STANDARD // Zend_Currency::RIGHT // Zend_Currency::LEFT $options = array( ‘position’ => Zend_Currency::RIGHT ); $currencyObject->setFormat($options); // END Additionally Added Code } 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]; } } [/source] You can see the comment of the code above for more detail understanding. P.S: Be informed that you need to change the Class Name you are about to create on the basis of your Namespace and Module name.