Currency exchange calculation bundle
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
Command fixed updateEsRates command and wrote a test for it Mar 29, 2016
DependencyInjection added doctrine cache service, removed cache configuration from tree Jul 4, 2016
Document changed date mapping in document Jul 4, 2016
Driver added date support for drivers Jul 4, 2016
Exception code fixed by strict standard Jan 8, 2015
Resources Fix Deprecation Notices in Symfony 3.1 Nov 24, 2016
Service added date support for drivers Jul 4, 2016
Twig fixed price extension styling issue Jun 29, 2016
.coveralls.yml Use mock to get currency rates Dec 31, 2015
.gitignore Remove user specific files from .gitignore Mar 17, 2016
.travis.yml update travis config Jul 4, 2016
LICENSE Update copyright year Jan 13, 2016
ONGRCurrencyExchangeBundle.php Introduce initial structure Jan 8, 2015 removed stash in favor of doctrine cache Jul 4, 2016
phpunit.xml.dist Introduce initial structure Jan 8, 2015

ONGR Currency Exchange Bundle

This bundle provides an easy way to display price in multiple currencies. It gives a solution to fetch and store current currency rates, to convert prices and display them in Twig templates.

Stable Release Build Status Coverage Status Quality Score


The documentation of the bundle can be found in Resources/doc/


Follow 5 quick steps to setup this bundle.

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require ongr/currency-exchange-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Register bundles in app/AppKernel.php:

class AppKernel extends Kernel
    public function registerBundles()
        return [
            // ...
            new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
            new ONGR\CurrencyExchangeBundle\ONGRCurrencyExchangeBundle(),    

    // ...

Step 3: Update Elasticsearch Mapping

This bundle provides Elasticsearch document to store currency rates. Add this bundle to your ES manager's mapping to associate it:

# app/config/config.yml
    # ...
            # ...
                # ...
                - AppBundle
                - ONGRCurrencyExchangeBundle

Step 4: Configure the Bundle

Configure the currencies you need in config.yml file.

# app/config/config.yml
    es_manager: default
    default_currency: EUR
        decimal: ','
        thousands: '.'
        EUR: "%s €"    # %s stands for the price itself
        USD: "$ %s"

That's it for setup, jump to the next chapter to learn how to use this bundle.


The main parts of this bundle are a command to update currency rates and Twig helpers to display price in various currencies.

Before converting prices you need to fetch the latest currency rates:

$ app/console ongr:currency:update

Tip: setup a cron job to update currencies daily in your production environment.

Now you are ready to use currency conversion logic in your templates. Here is a simple example how to convert currency:

    <li>Price in default currency: {{ 123.123|ongr_price(2) }}
    <li>Price in US dollars: {{ 123.123|ongr_price(2, 'USD') }}

In this example the number 2 represents the number of decimal points. It will print the following information:

Price in default currency: 123.12 €
Price in US dollars: $ 123.12 

To learn more read about provided Twig helpers or check example currency switching implementation.


This package is licensed under the MIT license. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.