Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Directory_Block_Adminhtml_Frontend_Currency_Base
  • Mage_Directory_Block_Adminhtml_Frontend_Region_Updater
  • Mage_Directory_Block_Currency
  • Mage_Directory_Block_Data
  • Mage_Directory_CurrencyController
  • Mage_Directory_Helper_Data
  • Mage_Directory_Helper_Url
  • Mage_Directory_Model_Country
  • Mage_Directory_Model_Country_Api
  • Mage_Directory_Model_Country_Api_V2
  • Mage_Directory_Model_Country_Format
  • Mage_Directory_Model_Currency
  • Mage_Directory_Model_Currency_Filter
  • Mage_Directory_Model_Currency_Import_Abstract
  • Mage_Directory_Model_Currency_Import_Webservicex
  • Mage_Directory_Model_Mysql4_Country
  • Mage_Directory_Model_Mysql4_Country_Collection
  • Mage_Directory_Model_Mysql4_Country_Format
  • Mage_Directory_Model_Mysql4_Country_Format_Collection
  • Mage_Directory_Model_Mysql4_Currency
  • Mage_Directory_Model_Mysql4_Currency_Collection
  • Mage_Directory_Model_Mysql4_Region
  • Mage_Directory_Model_Mysql4_Region_Collection
  • Mage_Directory_Model_Observer
  • Mage_Directory_Model_Region
  • Mage_Directory_Model_Region_Api
  • Mage_Directory_Model_Region_Api_V2
  • Mage_Directory_Model_Resource_Country
  • Mage_Directory_Model_Resource_Country_Collection
  • Mage_Directory_Model_Resource_Country_Format
  • Mage_Directory_Model_Resource_Country_Format_Collection
  • Mage_Directory_Model_Resource_Currency
  • Mage_Directory_Model_Resource_Region
  • Mage_Directory_Model_Resource_Region_Collection

Exceptions

  • Mage_Directory_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Directory
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * Directory data helper
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: class Mage_Directory_Helper_Data extends Mage_Core_Helper_Abstract
 33: {
 34:     /**
 35:      * Config value that lists ISO2 country codes which have optional Zip/Postal pre-configured
 36:      */
 37:     const OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH = 'general/country/optional_zip_countries';
 38: 
 39:     /*
 40:      * Path to config value, which lists countries, for which state is required.
 41:      */
 42:     const XML_PATH_STATES_REQUIRED = 'general/region/state_required';
 43: 
 44:     /*
 45:      * Path to config value, which detects whether or not display the state for the country, if it is not required
 46:      */
 47:     const XML_PATH_DISPLAY_ALL_STATES = 'general/region/display_all';
 48: 
 49:     /**
 50:      * Country collection
 51:      *
 52:      * @var Mage_Directory_Model_Resource_Country_Collection
 53:      */
 54:     protected $_countryCollection;
 55: 
 56:     /**
 57:      * Region collection
 58:      *
 59:      * @var Mage_Directory_Model_Resource_Region_Collection
 60:      */
 61:     protected $_regionCollection;
 62: 
 63:     /**
 64:      * Json representation of regions data
 65:      *
 66:      * @var string
 67:      */
 68:     protected $_regionJson;
 69: 
 70:     /**
 71:      * Currency cache
 72:      *
 73:      * @var array
 74:      */
 75:     protected $_currencyCache = array();
 76: 
 77:     /**
 78:      * ISO2 country codes which have optional Zip/Postal pre-configured
 79:      *
 80:      * @var array
 81:      */
 82:     protected $_optionalZipCountries = null;
 83: 
 84:     /**
 85:      * Retrieve region collection
 86:      *
 87:      * @return Mage_Directory_Model_Resource_Region_Collection
 88:      */
 89:     public function getRegionCollection()
 90:     {
 91:         if (!$this->_regionCollection) {
 92:             $this->_regionCollection = Mage::getModel('directory/region')->getResourceCollection()
 93:                 ->addCountryFilter($this->getAddress()->getCountryId())
 94:                 ->load();
 95:         }
 96:         return $this->_regionCollection;
 97:     }
 98: 
 99:     /**
100:      * Retrieve country collection
101:      *
102:      * @return Mage_Directory_Model_Resource_Country_Collection
103:      */
104:     public function getCountryCollection()
105:     {
106:         if (!$this->_countryCollection) {
107:             $this->_countryCollection = Mage::getModel('directory/country')->getResourceCollection()
108:                 ->loadByStore();
109:         }
110:         return $this->_countryCollection;
111:     }
112: 
113:     /**
114:      * Retrieve regions data json
115:      *
116:      * @return string
117:      */
118:     public function getRegionJson()
119:     {
120: 
121:         Varien_Profiler::start('TEST: '.__METHOD__);
122:         if (!$this->_regionJson) {
123:             $cacheKey = 'DIRECTORY_REGIONS_JSON_STORE'.Mage::app()->getStore()->getId();
124:             if (Mage::app()->useCache('config')) {
125:                 $json = Mage::app()->loadCache($cacheKey);
126:             }
127:             if (empty($json)) {
128:                 $countryIds = array();
129:                 foreach ($this->getCountryCollection() as $country) {
130:                     $countryIds[] = $country->getCountryId();
131:                 }
132:                 $collection = Mage::getModel('directory/region')->getResourceCollection()
133:                     ->addCountryFilter($countryIds)
134:                     ->load();
135:                 $regions = array(
136:                     'config' => array(
137:                         'show_all_regions' => $this->getShowNonRequiredState(),
138:                         'regions_required' => $this->getCountriesWithStatesRequired()
139:                     )
140:                 );
141:                 foreach ($collection as $region) {
142:                     if (!$region->getRegionId()) {
143:                         continue;
144:                     }
145:                     $regions[$region->getCountryId()][$region->getRegionId()] = array(
146:                         'code' => $region->getCode(),
147:                         'name' => $this->__($region->getName())
148:                     );
149:                 }
150:                 $json = Mage::helper('core')->jsonEncode($regions);
151: 
152:                 if (Mage::app()->useCache('config')) {
153:                     Mage::app()->saveCache($json, $cacheKey, array('config'));
154:                 }
155:             }
156:             $this->_regionJson = $json;
157:         }
158: 
159:         Varien_Profiler::stop('TEST: '.__METHOD__);
160:         return $this->_regionJson;
161:     }
162: 
163:     /**
164:      * Convert currency
165:      *
166:      * @param float $amount
167:      * @param string $from
168:      * @param string $to
169:      * @return float
170:      */
171:     public function currencyConvert($amount, $from, $to = null)
172:     {
173:         if (empty($this->_currencyCache[$from])) {
174:             $this->_currencyCache[$from] = Mage::getModel('directory/currency')->load($from);
175:         }
176:         if (is_null($to)) {
177:             $to = Mage::app()->getStore()->getCurrentCurrencyCode();
178:         }
179:         $converted = $this->_currencyCache[$from]->convert($amount, $to);
180:         return $converted;
181:     }
182: 
183:     /**
184:      * Return ISO2 country codes, which have optional Zip/Postal pre-configured
185:      *
186:      * @param bool $asJson
187:      * @return array|string
188:      */
189:     public function getCountriesWithOptionalZip($asJson = false)
190:     {
191:         if (null === $this->_optionalZipCountries) {
192:             $this->_optionalZipCountries = preg_split('/\,/',
193:                 Mage::getStoreConfig(self::OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH), 0, PREG_SPLIT_NO_EMPTY);
194:         }
195:         if ($asJson) {
196:             return Mage::helper('core')->jsonEncode($this->_optionalZipCountries);
197:         }
198:         return $this->_optionalZipCountries;
199:     }
200: 
201:     /**
202:      * Check whether zip code is optional for specified country code
203:      *
204:      * @param string $countryCode
205:      * @return boolean
206:      */
207:     public function isZipCodeOptional($countryCode)
208:     {
209:         $this->getCountriesWithOptionalZip();
210:         return in_array($countryCode, $this->_optionalZipCountries);
211:     }
212: 
213:     /**
214:      * Returns the list of countries, for which region is required
215:      *
216:      * @param boolean $asJson
217:      * @return array
218:      */
219:     public function getCountriesWithStatesRequired($asJson = false)
220:     {
221:         $countryList = explode(',', Mage::getStoreConfig(self::XML_PATH_STATES_REQUIRED));
222:         if ($asJson) {
223:             return Mage::helper('core')->jsonEncode($countryList);
224:         }
225:         return $countryList;
226:     }
227: 
228:     /**
229:      * Return flag, which indicates whether or not non required state should be shown
230:      *
231:      * @return bool
232:      */
233:     public function getShowNonRequiredState()
234:     {
235:         return (boolean)Mage::getStoreConfig(self::XML_PATH_DISPLAY_ALL_STATES);
236:     }
237: 
238:     /**
239:      * Returns flag, which indicates whether region is required for specified country
240:      *
241:      * @param string $countryId
242:      * @return bool
243:      */
244:     public function isRegionRequired($countryId)
245:     {
246:         $countyList = $this->getCountriesWithStatesRequired();
247:         if(!is_array($countyList)) {
248:             return false;
249:         }
250:         return in_array($countryId, $countyList);
251:     }
252: }
253: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0