1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_System_Currency_Rate_Matrix extends Mage_Adminhtml_Block_Template
35: {
36: public function __construct()
37: {
38: $this->setTemplate('system/currency/rate/matrix.phtml');
39: }
40:
41: protected function _prepareLayout()
42: {
43: $newRates = Mage::getSingleton('adminhtml/session')->getRates();
44: Mage::getSingleton('adminhtml/session')->unsetData('rates');
45:
46: $currencyModel = Mage::getModel('directory/currency');
47: $currencies = $currencyModel->getConfigAllowCurrencies();
48: $defaultCurrencies = $currencyModel->getConfigBaseCurrencies();
49: $oldCurrencies = $this->_prepareRates($currencyModel->getCurrencyRates($defaultCurrencies, $currencies));
50:
51: foreach( $currencies as $currency ) {
52: foreach( $oldCurrencies as $key => $value ) {
53: if( !array_key_exists($currency, $oldCurrencies[$key]) ) {
54: $oldCurrencies[$key][$currency] = '';
55: }
56: }
57: }
58:
59: foreach( $oldCurrencies as $key => $value ) {
60: ksort($oldCurrencies[$key]);
61: }
62:
63: sort($currencies);
64:
65: $this->setAllowedCurrencies($currencies)
66: ->setDefaultCurrencies($defaultCurrencies)
67: ->setOldRates($oldCurrencies)
68: ->setNewRates($this->_prepareRates($newRates));
69:
70: return parent::_prepareLayout();
71: }
72:
73: protected function getRatesFormAction()
74: {
75: return $this->getUrl('*/*/saveRates');
76: }
77:
78: protected function _prepareRates($array)
79: {
80: if( !is_array($array) ) {
81: return $array;
82: }
83:
84: foreach ($array as $key => $rate) {
85: foreach ($rate as $code => $value) {
86: $parts = explode('.', $value);
87: if( sizeof($parts) == 2 ) {
88: $parts[1] = str_pad(rtrim($parts[1], 0), 4, '0', STR_PAD_RIGHT);
89: $array[$key][$code] = join('.', $parts);
90: } elseif( $value > 0 ) {
91: $array[$key][$code] = number_format($value, 4);
92: } else {
93: $array[$key][$code] = null;
94: }
95: }
96: }
97: return $array;
98: }
99: }
100: