Mage_Directory_Model_Currency Class Reference

Inheritance diagram for Mage_Directory_Model_Currency:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getCode ()
 getCurrencyCode ()
 getRates ()
 setRates (array $rates)
 load ($id, $field=null)
 getRate ($toCurrency)
 convert ($price, $toCurrency=null)
 getFilter ()
 format ($price, $options=array(), $includeContainer=true, $addBrackets=false)
 formatTxt ($price, $options=array())
 getOutputFormat ()
 getConfigAllowCurrencies ()
 getConfigDefaultCurrencies ()
 getConfigBaseCurrencies ()
 getCurrencyRates ($currency, $toCurrencies=null)
 saveRates ($rates)

Public Attributes

const XML_PATH_CURRENCY_ALLOW = 'currency/options/allow'
const XML_PATH_CURRENCY_DEFAULT = 'currency/options/default'
const XML_PATH_CURRENCY_BASE = 'currency/options/base'

Protected Member Functions

 _construct ()

Protected Attributes

 $_filter
 $_rates


Detailed Description

Definition at line 34 of file Currency.php.


Member Function Documentation

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 53 of file Currency.php.

00054     {
00055         $this->_init('directory/currency');
00056     }

convert ( price,
toCurrency = null 
)

Convert price to currency format

Parameters:
double $price
string $toCurrency
Returns:
double

Definition at line 139 of file Currency.php.

00140     {
00141         if (is_null($toCurrency)) {
00142             return $price;
00143         }
00144         elseif ($rate = $this->getRate($toCurrency)) {
00145             return $price*$rate;
00146         }
00147 
00148         throw new Exception(Mage::helper('directory')->__('Undefined rate from "%s-%s"', $this->getCode(), $toCurrency->getCode()));
00149     }

format ( price,
options = array(),
includeContainer = true,
addBrackets = false 
)

Format price to currency format

Parameters:
double $price
bool $includeContainer
Returns:
string

Definition at line 172 of file Currency.php.

00173     {
00174         if ($includeContainer) {
00175             return '<span class="price">' . ($addBrackets ? '[' : '') . $this->formatTxt($price, $options) . ($addBrackets ? ']' : '') . '</span>';
00176         }
00177         return $this->formatTxt($price, $options);
00178     }

formatTxt ( price,
options = array() 
)

Fix problem with 12 000 000, 1 200 000

Definition at line 180 of file Currency.php.

00181     {
00182         if (!is_numeric($price)) {
00183             $price = Mage::app()->getLocale()->getNumber($price);
00184         }
00185         /**
00186          * Fix problem with 12 000 000, 1 200 000
00187          */
00188         $price = sprintf("%f", $price);
00189         return Mage::app()->getLocale()->currency($this->getCode())->toCurrency($price, $options);
00190     }

getCode (  ) 

Get currency code

Returns:
string

Definition at line 63 of file Currency.php.

00064     {
00065         return $this->_getData('currency_code');
00066     }

getConfigAllowCurrencies (  ) 

Retrieve allowed currencies according to config

Definition at line 203 of file Currency.php.

00204     {
00205         $allowedCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_ALLOW);
00206         $appBaseCurrencyCode = Mage::app()->getBaseCurrencyCode();
00207         if (!in_array($appBaseCurrencyCode, $allowedCurrencies)) {
00208             $allowedCurrencies[] = $appBaseCurrencyCode;
00209         }
00210         foreach (Mage::app()->getStores() as $store) {
00211             $code = $store->getBaseCurrencyCode();
00212             if (!in_array($code, $allowedCurrencies)) {
00213                 $allowedCurrencies[] = $code;
00214             }
00215         }
00216 
00217         return $allowedCurrencies;
00218     }

getConfigBaseCurrencies (  ) 

Definition at line 231 of file Currency.php.

00232     {
00233         $defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_BASE);
00234         return $defaultCurrencies;
00235     }

getConfigDefaultCurrencies (  ) 

Retrieve default currencies according to config

Definition at line 224 of file Currency.php.

00225     {
00226         $defaultCurrencies = $this->_getResource()->getConfigCurrencies($this, self::XML_PATH_CURRENCY_DEFAULT);
00227         return $defaultCurrencies;
00228     }

getCurrencyCode (  ) 

Definition at line 68 of file Currency.php.

00069     {
00070         return $this->_getData('currency_code');
00071     }

getCurrencyRates ( currency,
toCurrencies = null 
)

Retrieve currency rates to other currencies

Parameters:
string $currency
array $toCurrencies
Returns:
array

Definition at line 244 of file Currency.php.

00245     {
00246         if ($currency instanceof Mage_Directory_Model_Currency) {
00247             $currency = $currency->getCode();
00248         }
00249         $data = $this->_getResource()->getCurrencyRates($currency, $toCurrencies);
00250         return $data;
00251     }

getFilter (  ) 

Get currency filter

Returns:
Mage_Directory_Model_Currency_Filter

Definition at line 156 of file Currency.php.

00157     {
00158         if (!$this->_filter) {
00159             $this->_filter = new Mage_Directory_Model_Currency_Filter($this->getCode());
00160         }
00161 
00162         return $this->_filter;
00163     }

getOutputFormat (  ) 

Definition at line 192 of file Currency.php.

00193     {
00194         $formated = $this->formatTxt(0);
00195         $number = $this->formatTxt(0, array('display'=>Zend_Currency::NO_SYMBOL));
00196         return str_replace($number, '%s', $formated);
00197     }

getRate ( toCurrency  ) 

Get currency rate

Parameters:
string $toCurrency
Returns:
double

Definition at line 115 of file Currency.php.

00116     {
00117         if (is_string($toCurrency)) {
00118             $code = $toCurrency;
00119         } elseif ($toCurrency instanceof Mage_Directory_Model_Currency) {
00120             $code = $toCurrency->getCurrencyCode();
00121         } else {
00122             throw Mage::exception('Mage_Directory', Mage::helper('directory')->__('Invalid target currency'));
00123         }
00124         $rates = $this->getRates();
00125         if (!isset($rates[$code])) {
00126             $rates[$code] = $this->_getResource()->getRate($this->getCode(), $toCurrency);
00127             $this->setRates($rates);
00128         }
00129         return $rates[$code];
00130     }

getRates (  ) 

Currency Rates getter

Returns:
array

Definition at line 78 of file Currency.php.

00079     {
00080         return $this->_rates;
00081     }

load ( id,
field = null 
)

Loading currency data

Parameters:
string $id
string $field
Returns:
Mage_Directory_Model_Currency

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 102 of file Currency.php.

00103     {
00104         $this->unsRate();
00105         $this->setData('currency_code', $id);
00106         return $this;
00107     }

saveRates ( rates  ) 

Save currency rates

Parameters:
array $rates
Returns:
object

Definition at line 259 of file Currency.php.

00260     {
00261         $this->_getResource()->saveRates($rates);
00262         return $this;
00263     }

setRates ( array rates  ) 

Currency Rates setter

Parameters:
array Currency Rates
Returns:
Mage_Directory_Model_Currency

Definition at line 89 of file Currency.php.

00090     {
00091         $this->_rates = $rates;
00092         return $this;
00093     }


Member Data Documentation

$_filter [protected]

Definition at line 43 of file Currency.php.

$_rates [protected]

Definition at line 50 of file Currency.php.

const XML_PATH_CURRENCY_ALLOW = 'currency/options/allow'

CONFIG path constants

Definition at line 39 of file Currency.php.

const XML_PATH_CURRENCY_BASE = 'currency/options/base'

Definition at line 41 of file Currency.php.

const XML_PATH_CURRENCY_DEFAULT = 'currency/options/default'

Definition at line 40 of file Currency.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