Ok first of all I saw the event currency_display_options_forming
and I thought that this would be so easy, but sadly that was not the case :( You can use this event to change the display of the currency across the whole site but the follow code stops the precision from working in all cases.
Under Mage_Directory_Model_Currency
there is a function formatPrecision
. Here it checks for the options and if it does not find one for precision it will hard code it to 2!
So the first thing I did as Marius said is to rewrite the Mage_Directory_Model_Currency::format
I chose to set it up with xml (great minds think alike)
public function format($price, $options = array(), $includeContainer = true, $addBrackets = false)
{
return $this->formatPrecision(
$price,
Mage::getStoreConfig(self::XML_PATH_CURRENCY_ALLOW), // Mage uses '2' here
$options,
$includeContainer,
$addBrackets
);
}
But that only changes the display. Most of the price displays all call Mage_Core_Model_Store::roundPrice
and this again has a hard coded 2, I am starting to think this was a bad idea.
public function roundPrice($price)
{
return round($price, 2);
}
So the obvious thing now is to rewrite the roundPrice function and again use the same xml config value.
public function roundPrice($fPrice)
{
return round($fPrice, Mage::getStoreConfig(Sitewards_Currency_Model_Format::XML_PATH_CURRENCY_ALLOW));
}
Now that covers most of the front-end if you also want to change this in the admin section that would involve changing templates and rewriting at least Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Price
public function getEscapedValue($iIndex=null)
{
$fValue = $this->getValue();
if (!is_numeric($fValue)) {
return null;
}
return number_format($fValue, Mage::getStoreConfig(Sitewards_Currency_Model_Format::XML_PATH_CURRENCY_ALLOW), null, '');
}
One not on the template front, the one I know about now is catalog/product/edit/price/tier.phtml
as again that has <?php echo sprintf('%.2f', $_item['price']) ?>
On one final note the admin grid actually does work with the first event currency_display_options_forming
.
I will update this answer the more I find out, but it is still a work in progress.
Ok so I am not sure if this is the bug but if you compare the Magento 1.8 and Magento 1.7 versions of the function currency in Mage_Core_Model_Local you will notice a reference to a bug with Zend_Currency
Magento 1.7: Mage_Core_Model_Local->currency
/**
* 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());
} 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];
}
Magento 1.8: Mage_Core_Model_Local->currency
/**
* 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])) {
$options = array();
try {
$currencyObject = new Zend_Currency($currency, $this->getLocale());
} catch (Exception $e) {
/**
* catch specific exceptions like "Currency 'USD' not found"
* - back end falls with specific locals as Malaysia and etc.
*
* as we can see from Zend framework ticket
* http://framework.zend.com/issues/browse/ZF-10038
* zend team is not going to change it behaviour in the near time
*/
$currencyObject = new Zend_Currency($currency);
$options['name'] = $currency;
$options['currency'] = $currency;
$options['symbol'] = $currency;
}
$options = new Varien_Object($options);
Mage::dispatchEvent('currency_display_options_forming', array(
'currency_options' => $options,
'base_code' => $currency
));
$currencyObject->setFormat($options->toArray());
self::$_currencyCache[$this->getLocaleCode()][$currency] = $currencyObject;
}
Varien_Profiler::stop('locale/currency');
return self::$_currencyCache[$this->getLocaleCode()][$currency];
}
My suggestion would be to try updating the try catch to match that of Magento 1.8 (I know this is not the best solution and obviously I would not suggest editing the core files but adding a rewrite)
Best Answer
You can change the currency symbols from
System->Manage Currency->Symbols
.