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_Currencysymbol_Block_Adminhtml_System_Currencysymbol
  • Mage_CurrencySymbol_Helper_Data
  • Mage_CurrencySymbol_Model_Observer
  • Mage_CurrencySymbol_Model_System_Currencysymbol
  • 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_CurrencySymbol
 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:  * Custom currency symbol model
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_CurrencySymbol
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_CurrencySymbol_Model_System_Currencysymbol
 35: {
 36:     /**
 37:      * Custom currency symbol properties
 38:      *
 39:      * @var array
 40:      */
 41:     protected $_symbolsData = array();
 42: 
 43:     /**
 44:      * Store id
 45:      *
 46:      * @var string | null
 47:      */
 48:     protected $_storeId;
 49: 
 50:     /**
 51:      * Website id
 52:      *
 53:      * @var string | null
 54:      */
 55:     protected $_websiteId;
 56:     /**
 57:      * Cache types which should be invalidated
 58:      *
 59:      * @var array
 60:      */
 61:     protected $_cacheTypes = array(
 62:         'config',
 63:         'block_html',
 64:         'layout'
 65:     );
 66: 
 67:     /**
 68:      * Config path to custom currency symbol value
 69:      */
 70:     const XML_PATH_CUSTOM_CURRENCY_SYMBOL = 'currency/options/customsymbol';
 71:     const XML_PATH_ALLOWED_CURRENCIES     = 'currency/options/allow';
 72: 
 73:     /*
 74:      * Separator used in config in allowed currencies list
 75:      */
 76:     const ALLOWED_CURRENCIES_CONFIG_SEPARATOR = ',';
 77: 
 78:     /**
 79:      * Config currency section
 80:      */
 81:     const CONFIG_SECTION = 'currency';
 82: 
 83:     /**
 84:      * Sets store Id
 85:      *
 86:      * @param  $storeId
 87:      * @return Mage_CurrencySymbol_Model_System_Currencysymbol
 88:      */
 89:     public function setStoreId($storeId=null)
 90:     {
 91:         $this->_storeId = $storeId;
 92:         $this->_symbolsData = array();
 93: 
 94:         return $this;
 95:     }
 96: 
 97:     /**
 98:      * Sets website Id
 99:      *
100:      * @param  $websiteId
101:      * @return Mage_CurrencySymbol_Model_System_Currencysymbol
102:      */
103:     public function setWebsiteId($websiteId=null)
104:     {
105:         $this->_websiteId = $websiteId;
106:         $this->_symbolsData = array();
107: 
108:         return $this;
109:     }
110: 
111:     /**
112:      * Returns currency symbol properties array based on config values
113:      *
114:      * @return array
115:      */
116:     public function getCurrencySymbolsData()
117:     {
118:         if ($this->_symbolsData) {
119:             return $this->_symbolsData;
120:         }
121: 
122:         $this->_symbolsData = array();
123: 
124:         $allowedCurrencies = explode(
125:             self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR,
126:             Mage::getStoreConfig(self::XML_PATH_ALLOWED_CURRENCIES, null)
127:         );
128: 
129:         /* @var $storeModel Mage_Adminhtml_Model_System_Store */
130:         $storeModel = Mage::getSingleton('adminhtml/system_store');
131:         foreach ($storeModel->getWebsiteCollection() as $website) {
132:             $websiteShow = false;
133:             foreach ($storeModel->getGroupCollection() as $group) {
134:                 if ($group->getWebsiteId() != $website->getId()) {
135:                     continue;
136:                 }
137:                 foreach ($storeModel->getStoreCollection() as $store) {
138:                     if ($store->getGroupId() != $group->getId()) {
139:                         continue;
140:                     }
141:                     if (!$websiteShow) {
142:                         $websiteShow = true;
143:                         $websiteSymbols  = $website->getConfig(self::XML_PATH_ALLOWED_CURRENCIES);
144:                         $allowedCurrencies = array_merge($allowedCurrencies, explode(
145:                             self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR,
146:                             $websiteSymbols
147:                         ));
148:                     }
149:                     $storeSymbols = Mage::getStoreConfig(self::XML_PATH_ALLOWED_CURRENCIES, $store);
150:                     $allowedCurrencies = array_merge($allowedCurrencies, explode(
151:                         self::ALLOWED_CURRENCIES_CONFIG_SEPARATOR,
152:                         $storeSymbols
153:                     ));
154:                 }
155:             }
156:         }
157:         ksort($allowedCurrencies);
158: 
159:         $currentSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL);
160: 
161:         /** @var $locale Mage_Core_Model_Locale */
162:         $locale = Mage::app()->getLocale();
163:         foreach ($allowedCurrencies as $code) {
164:             if (!$symbol = $locale->getTranslation($code, 'currencysymbol')) {
165:                 $symbol = $code;
166:             }
167:             $name = $locale->getTranslation($code, 'nametocurrency');
168:             if (!$name) {
169:                 $name = $code;
170:             }
171:             $this->_symbolsData[$code] = array(
172:                 'parentSymbol'  => $symbol,
173:                 'displayName' => $name
174:             );
175: 
176:             if (isset($currentSymbols[$code]) && !empty($currentSymbols[$code])) {
177:                 $this->_symbolsData[$code]['displaySymbol'] = $currentSymbols[$code];
178:             } else {
179:                 $this->_symbolsData[$code]['displaySymbol'] = $this->_symbolsData[$code]['parentSymbol'];
180:             }
181:             if ($this->_symbolsData[$code]['parentSymbol'] == $this->_symbolsData[$code]['displaySymbol']) {
182:                 $this->_symbolsData[$code]['inherited'] = true;
183:             } else {
184:                 $this->_symbolsData[$code]['inherited'] = false;
185:             }
186:         }
187: 
188:         return $this->_symbolsData;
189:     }
190: 
191:     /**
192:      * Saves currency symbol to config
193:      *
194:      * @param  $symbols array
195:      * @return Mage_CurrencySymbol_Model_System_Currencysymbol
196:      */
197:     public function setCurrencySymbolsData($symbols=array())
198:     {
199:         foreach ($this->getCurrencySymbolsData() as $code => $values) {
200:             if (isset($symbols[$code])) {
201:                 if ($symbols[$code] == $values['parentSymbol'] || empty($symbols[$code]))
202:                 unset($symbols[$code]);
203:             }
204:         }
205:         if ($symbols) {
206:             $value['options']['fields']['customsymbol']['value'] = serialize($symbols);
207:         } else {
208:             $value['options']['fields']['customsymbol']['inherit'] = 1;
209:         }
210: 
211:         Mage::getModel('adminhtml/config_data')
212:             ->setSection(self::CONFIG_SECTION)
213:             ->setWebsite(null)
214:             ->setStore(null)
215:             ->setGroups($value)
216:             ->save();
217: 
218:         Mage::dispatchEvent('admin_system_config_changed_section_currency_before_reinit',
219:             array('website' => $this->_websiteId, 'store' => $this->_storeId)
220:         );
221: 
222:         // reinit configuration
223:         Mage::getConfig()->reinit();
224:         Mage::app()->reinitStores();
225: 
226:         $this->clearCache();
227: 
228:         Mage::dispatchEvent('admin_system_config_changed_section_currency',
229:             array('website' => $this->_websiteId, 'store' => $this->_storeId)
230:         );
231: 
232:         return $this;
233:     }
234: 
235:     /**
236:      * Returns custom currency symbol by currency code
237:      *
238:      * @param  $code
239:      * @return bool|string
240:      */
241:     public function getCurrencySymbol($code)
242:     {
243:         $customSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL);
244:         if (array_key_exists($code, $customSymbols)) {
245:             return $customSymbols[$code];
246:         }
247: 
248:         return false;
249:     }
250: 
251:     /**
252:      * Clear translate cache
253:      *
254:      * @return Saas_Translate_Helper_Data
255:      */
256:     public function clearCache()
257:     {
258:         // clear cache for frontend
259:         foreach ($this->_cacheTypes as $cacheType) {
260:             Mage::app()->getCacheInstance()->invalidateType($cacheType);
261:         }
262:         return $this;
263:     }
264: 
265:     /**
266:      * Unserialize data from Store Config.
267:      *
268:      * @param string $configPath
269:      * @param int $storeId
270:      * @return array
271:      */
272:     protected function _unserializeStoreConfig($configPath, $storeId = null)
273:     {
274:         $result = array();
275:         $configData = (string)Mage::getStoreConfig($configPath, $storeId);
276:         if ($configData) {
277:             $result = unserialize($configData);
278:         }
279: 
280:         return is_array($result) ? $result : array();
281:     }
282: }
283: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0