00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 abstract class Mage_Directory_Model_Currency_Import_Abstract
00033 {
00034
00035
00036
00037
00038
00039 protected function _getCurrencyCodes()
00040 {
00041 return Mage::getModel('directory/currency')->getConfigAllowCurrencies();
00042 }
00043
00044
00045
00046
00047
00048
00049 protected function _getDefaultCurrencyCodes()
00050 {
00051 return Mage::getModel('directory/currency')->getConfigBaseCurrencies();
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061 abstract protected function _convert($currencyFrom, $currencyTo);
00062
00063
00064
00065
00066
00067
00068
00069 protected function _saveRates($rates)
00070 {
00071 foreach ($rates as $currencyCode => $currencyRates) {
00072 Mage::getModel('directory/currency')
00073 ->setId($currencyCode)
00074 ->setRates($currencyRates)
00075 ->save();
00076 }
00077 return $this;
00078 }
00079
00080
00081
00082
00083
00084
00085 public function importRates()
00086 {
00087 $data = $this->fetchRates();
00088 $this->_saveRates($data);
00089 return $this;
00090 }
00091
00092 public function fetchRates()
00093 {
00094 $data = array();
00095 $currencies = $this->_getCurrencyCodes();
00096 $defaultCurrencies = $this->_getDefaultCurrencyCodes();
00097 @set_time_limit(0);
00098 foreach ($defaultCurrencies as $currencyFrom) {
00099 if (!isset($data[$currencyFrom])) {
00100 $data[$currencyFrom] = array();
00101 }
00102
00103 foreach ($currencies as $currencyTo) {
00104 if ($currencyFrom == $currencyTo) {
00105 $data[$currencyFrom][$currencyTo] = $this->_numberFormat(1);
00106 }
00107 else {
00108 $data[$currencyFrom][$currencyTo] = $this->_numberFormat($this->_convert($currencyFrom, $currencyTo));
00109 }
00110 }
00111 ksort($data[$currencyFrom]);
00112 }
00113
00114 return $data;
00115 }
00116
00117 protected function _numberFormat($number)
00118 {
00119 return $number;
00120 }
00121
00122 public function getMessages()
00123 {
00124 return $this->_messages;
00125 }
00126 }