Public Member Functions | |
getRegionCollection () | |
getCountryCollection () | |
getRegionJson () | |
currencyConvert ($amount, $from, $to=null) | |
Protected Attributes | |
$_countryCollection | |
$_regionCollection | |
$_regionJson | |
$_currencyCache = array() |
Definition at line 32 of file Data.php.
currencyConvert | ( | $ | amount, | |
$ | from, | |||
$ | to = null | |||
) |
Definition at line 103 of file Data.php.
00104 { 00105 if (empty($this->_currencyCache[$from])) { 00106 $this->_currencyCache[$from] = Mage::getModel('directory/currency')->load($from); 00107 } 00108 if (is_null($to)) { 00109 $to = Mage::app()->getStore()->getCurrentCurrencyCode(); 00110 } 00111 $converted = $this->_currencyCache[$from]->convert($amount, $to); 00112 return $converted; 00113 }
getCountryCollection | ( | ) |
Definition at line 49 of file Data.php.
00050 { 00051 if (!$this->_countryCollection) { 00052 $this->_countryCollection = Mage::getModel('directory/country')->getResourceCollection() 00053 ->loadByStore(); 00054 } 00055 return $this->_countryCollection; 00056 }
getRegionCollection | ( | ) |
Definition at line 39 of file Data.php.
00040 { 00041 if (!$this->_regionCollection) { 00042 $this->_regionCollection = Mage::getModel('directory/region')->getResourceCollection() 00043 ->addCountryFilter($this->getAddress()->getCountryId()) 00044 ->load(); 00045 } 00046 return $this->_regionCollection; 00047 }
getRegionJson | ( | ) |
Retrieve regions data json
Definition at line 63 of file Data.php.
00064 { 00065 00066 Varien_Profiler::start('TEST: '.__METHOD__); 00067 if (!$this->_regionJson) { 00068 $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE'.Mage::app()->getStore()->getId(); 00069 if (Mage::app()->useCache('config')) { 00070 $json = Mage::app()->loadCache($cacheKey); 00071 } 00072 if (empty($json)) { 00073 $countryIds = array(); 00074 foreach ($this->getCountryCollection() as $country) { 00075 $countryIds[] = $country->getCountryId(); 00076 } 00077 $collection = Mage::getModel('directory/region')->getResourceCollection() 00078 ->addCountryFilter($countryIds) 00079 ->load(); 00080 $regions = array(); 00081 foreach ($collection as $region) { 00082 if (!$region->getRegionId()) { 00083 continue; 00084 } 00085 $regions[$region->getCountryId()][$region->getRegionId()] = array( 00086 'code'=>$region->getCode(), 00087 'name'=>$region->getName() 00088 ); 00089 } 00090 $json = Zend_Json::encode($regions); 00091 00092 if (Mage::app()->useCache('config')) { 00093 Mage::app()->saveCache($json, $cacheKey, array('config')); 00094 } 00095 } 00096 $this->_regionJson = $json; 00097 } 00098 00099 Varien_Profiler::stop('TEST: '.__METHOD__); 00100 return $this->_regionJson; 00101 }