*/ class Mage_Adminhtml_Block_System_Currency_Rate_Matrix extends Mage_Adminhtml_Block_Template { public function __construct() { $this->setTemplate('system/currency/rate/matrix.phtml'); } protected function _prepareLayout() { $newRates = Mage::getSingleton('adminhtml/session')->getRates(); Mage::getSingleton('adminhtml/session')->unsetData('rates'); $currencyModel = Mage::getModel('directory/currency'); $currencies = $currencyModel->getConfigAllowCurrencies(); $defaultCurrencies = $currencyModel->getConfigBaseCurrencies(); $oldCurrencies = $this->_prepareRates($currencyModel->getCurrencyRates($defaultCurrencies, $currencies)); foreach( $currencies as $currency ) { foreach( $oldCurrencies as $key => $value ) { if( !array_key_exists($currency, $oldCurrencies[$key]) ) { $oldCurrencies[$key][$currency] = ''; } } } foreach( $oldCurrencies as $key => $value ) { ksort($oldCurrencies[$key]); } sort($currencies); $this->setAllowedCurrencies($currencies) ->setDefaultCurrencies($defaultCurrencies) ->setOldRates($oldCurrencies) ->setNewRates($this->_prepareRates($newRates)); return parent::_prepareLayout(); } protected function getRatesFormAction() { return $this->getUrl('*/*/saveRates'); } protected function _prepareRates($array) { if( !is_array($array) ) { return $array; } foreach ($array as $key => $rate) { foreach ($rate as $code => $value) { $parts = explode('.', $value); if( sizeof($parts) == 2 ) { $parts[1] = str_pad(rtrim($parts[1], 0), 4, '0', STR_PAD_RIGHT); $array[$key][$code] = join('.', $parts); } elseif( $value > 0 ) { $array[$key][$code] = number_format($value, 4); } else { $array[$key][$code] = null; } } } return $array; } }