Mage_Directory_Helper_Data Class Reference

Inheritance diagram for Mage_Directory_Helper_Data:

Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 getRegionCollection ()
 getCountryCollection ()
 getRegionJson ()
 currencyConvert ($amount, $from, $to=null)

Protected Attributes

 $_countryCollection
 $_regionCollection
 $_regionJson
 $_currencyCache = array()


Detailed Description

Directory data helper

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 32 of file Data.php.


Member Function Documentation

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

Returns:
string

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     }


Member Data Documentation

$_countryCollection [protected]

Definition at line 34 of file Data.php.

$_currencyCache = array() [protected]

Definition at line 37 of file Data.php.

$_regionCollection [protected]

Definition at line 35 of file Data.php.

$_regionJson [protected]

Definition at line 36 of file Data.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:07 2009 for Magento by  doxygen 1.5.8