2017 © Pedro Peláez
 

symfony-bundle currency-exchange-bundle

ONGR currency exchange bundle

image

ongr/currency-exchange-bundle

ONGR currency exchange bundle

  • Thursday, November 24, 2016
  • by saimaz
  • Repository
  • 16 Watchers
  • 2 Stars
  • 3,393 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 14 Versions
  • 13 % Grown

The README.md

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., (*1)

Stable Release Build Status Coverage Status Quality Score, (*2)

Documentation

The documentation of the bundle can be found in Resources/doc/, (*3)

Installation

Follow 5 quick steps to setup this bundle., (*4)

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:, (*5)

$ 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., (*6)

Step 2: Enable the Bundle

Register bundles in app/AppKernel.php:, (*7)

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:, (*8)

# app/config/config.yml
ongr_elasticsearch:
    # ...
    managers:
        default:
            # ...
            mappings:
                # ...
                - AppBundle
                - ONGRCurrencyExchangeBundle

Step 4: Configure the Bundle

Configure the currencies you need in config.yml file., (*9)

# app/config/config.yml
ongr_currency_exchange:
    es_manager: default
    default_currency: EUR
    separators:
        decimal: ','
        thousands: '.'
    currencies:
        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., (*10)

Usage

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

Before converting prices you need to fetch the latest currency rates:, (*12)

$ app/console ongr:currency:update

Tip: setup a cron job to update currencies daily in your production environment., (*13)

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

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

In this example the number 2 represents the number of decimal points. It will print the following information:, (*15)

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][7] implementation., (*16)

License

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., (*17)

The Versions