slonline / exchangerates
Exchange rates - Module for SilverStripe 6
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/slonline/exchangerates
Requires
- ext-simplexml: *
- silverstripe/framework: ~6
README
Requirements
- silverstripe/framework ~6.0
Installation
Add the following code to the require key in composer.json file:
composer require slonline/exchangerates
Add configuration into yml, like this:
SLONline\ExchangeRates\ExchangeRates: registered_processor: SLONline\ExchangeRates\Processor\ECB supported_currencies: - EUR - USD
Loading data
Data can be loaded via sake command
php vendor/silverstripe/framework/bin/sake process:exchangerates
or in script by calling
SLONline\ExchangeRates\ExchangeRates::create()->process();
or
SLONline\ExchangeRates\ExchangeRates::singleton()->process();
Converting amount from the basic currency to the second
- Getting the latest value
SLONline\ExchangeRates\ExchangeRates::singleton()->getExchangeRate('EUR','USD');
- Getting the value for specific date if exists
SLONline\ExchangeRates\ExchangeRates::singleton()->getExchangeRate('EUR','USD', '2025-10-30');
Calling it via singleton is recommended to avoid multiple loading of rates from database.
Conversion is available on DBMoney field via extension
First method for getting converted value from base currency to target currency.
$money = DBMoney::create('money')->setAmount( 100)->setCurrency('EUR'); Debug::dump($money->getAmountInCurrency('USD')); // will output amount converted to USD Debug::dump($money->getInAllSupportedCurrencies()); // will output ArrayList with amounts in all supported currencies
Processors
Processor is main class for downloading, parsing and writing exchange rates from some source. Processed data are stored into data objects ExchangeRate
Available processors
- ECB - European Central Bank
SLONline\ExchangeRates\ExchangeRates: registered_processor: SLONline\ExchangeRates\Processor\ECB
- CNB - Czech National Bank
SLONline\ExchangeRates\ExchangeRates: registered_processor: SLONline\ExchangeRates\Processor\CNB
Adding new processor
If you want to add new source of rates, you can create new processor. Each processor should implement ProcessorInterface.