Exchange rates update handlers
An exchange rates update handler fetches today's rates for the Update auto rates button of the currency list. Exponential 6 ships one handler, eZECB, which reads the daily reference rates of the European Central Bank (relative to EUR).
Settings
[ExchangeRatesSettings] ExchangeRatesUpdateHandler=eZECB RepositoryDirectories[]=kernel/shop/classes/exchangeratehandlers ExtensionDirectories[]= BaseCurrency=EUR [ECBExchangeRatesSettings] ServerName=http://www.ecb.int ServerPort=80 RatesURI=stats/eurofxref/eurofxref-daily.xml
Use the HTTPS address
The shipped address http://www.ecb.int now answers with a permanent redirect to https://www.ecb.europa.eu (checked November 2026), and the handler does not follow redirects. Point it at the HTTPS address in settings/override/shop.ini.append.php:
[ECBExchangeRatesSettings] ServerName=https://www.ecb.europa.eu ServerPort=443 RatesURI=stats/eurofxref/eurofxref-daily.xml
Writing a handler
A handler named mysource is the file mysource/mysourcehandler.php in one of the RepositoryDirectories, or in exchangeratehandlers/ of an extension listed in ExtensionDirectories. Its class is MySourceHandler (the name is matched in lower case) and extends eZExchangeRatesUpdateHandler:
<?php
// extension/myshop/exchangeratehandlers/mysource/mysourcehandler.php
class MySourceHandler extends eZExchangeRatesUpdateHandler
{
function requestRates()
{
// fetch the rates, then:
$this->setBaseCurrency( 'EUR' );
$this->setRateList( array( 'USD' => '1.0800', 'NOK' => '11.7000' ) );
return array( 'code' => self::OK, 'description' => '' );
}
}# extension/myshop/settings/shop.ini.append.php [ExchangeRatesSettings] ExchangeRatesUpdateHandler=mysource ExtensionDirectories[]=myshop
Return an error code (for example self::FAILED) with a description when the rates cannot be fetched; the list shows the description.
Related pages
Contributors
- Svitlana Shatokhina
- Geir Arne Waaler
- Graham BrookinsUpdated Maintainer
Comments
Add a comment