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:  * Abstract model for import currency
 29:  *
 30:  * @author      Magento Core Team <core@magentocommerce.com>
 31:  */
 32: abstract class Mage_Directory_Model_Currency_Import_Abstract
 33: {
 34:     /**
 35:      * Retrieve currency codes
 36:      *
 37:      * @return array
 38:      */
 39:     protected function _getCurrencyCodes()
 40:     {
 41:         return Mage::getModel('directory/currency')->getConfigAllowCurrencies();
 42:     }
 43: 
 44:     /**
 45:      * Retrieve default currency codes
 46:      *
 47:      * @return array
 48:      */
 49:     protected function _getDefaultCurrencyCodes()
 50:     {
 51:         return Mage::getModel('directory/currency')->getConfigBaseCurrencies();
 52:     }
 53: 
 54:     /**
 55:      * Retrieve rate
 56:      *
 57:      * @param   string $currencyFrom
 58:      * @param   string $currencyTo
 59:      * @return  float
 60:      */
 61:     abstract protected function _convert($currencyFrom, $currencyTo);
 62: 
 63:     /**
 64:      * Saving currency rates
 65:      *
 66:      * @param   array $rates
 67:      * @return  Mage_Directory_Model_Currency_Import_Abstract
 68:      */
 69:     protected function _saveRates($rates)
 70:     {
 71:         foreach ($rates as $currencyCode => $currencyRates) {
 72:             Mage::getModel('directory/currency')
 73:                 ->setId($currencyCode)
 74:                 ->setRates($currencyRates)
 75:                 ->save();
 76:         }
 77:         return $this;
 78:     }
 79: 
 80:     /**
 81:      * Import rates
 82:      *
 83:      * @return Mage_Directory_Model_Currency_Import_Abstract
 84:      */
 85:     public function importRates()
 86:     {
 87:         $data = $this->fetchRates();
 88:         $this->_saveRates($data);
 89:         return $this;
 90:     }
 91: 
 92:     public function fetchRates()
 93:     {
 94:         $data = array();
 95:         $currencies = $this->_getCurrencyCodes();
 96:         $defaultCurrencies = $this->_getDefaultCurrencyCodes();
 97:         @set_time_limit(0);
 98:         foreach ($defaultCurrencies as $currencyFrom) {
 99:             if (!isset($data[$currencyFrom])) {
100:                 $data[$currencyFrom] = array();
101:             }
102: 
103:             foreach ($currencies as $currencyTo) {
104:                 if ($currencyFrom == $currencyTo) {
105:                     $data[$currencyFrom][$currencyTo] = $this->_numberFormat(1);
106:                 }
107:                 else {
108:                     $data[$currencyFrom][$currencyTo] = $this->_numberFormat($this->_convert($currencyFrom, $currencyTo));
109:                 }
110:             }
111:             ksort($data[$currencyFrom]);
112:         }
113: 
114:         return $data;
115:     }
116: 
117:     protected function _numberFormat($number)
118:     {
119:         return $number;
120:     }
121: 
122:     public function getMessages()
123:     {
124:         return $this->_messages;
125:     }
126: }
127: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0