Basic Usage¶

Danger

We’re sorry but this documentation section is outdated. Please have that in mind when trying to use it. You can help us making documentation up to date via Sylius Github. Thank you!

Getting a Currency name¶

<?php

use Sylius\Component\Currency\Model\Currency;

$currency = new Currency();
$currency->setCode('USD');

$currency->getName(); // Returns 'US Dollar'.

The getName method uses Symfony’s Intl class to convert currency’s code into a human friendly form.

Note

The output of getName may vary as the name is generated accordingly to the set locale.

CurrencyConverter¶

The CurrencyConverter allows you to convert a value accordingly to the exchange rate of specified currency.

This behaviour is used just for displaying the approximate value in another currency than the base currency of the channel.

Note

This service implements the CurrencyConverterInterface.

CurrencyProvider¶

The CurrencyProvider allows you to get all available currencies.

<?php

use Sylius\Component\Currency\Provider\CurrencyProvider;
use Sylius\Component\Resource\Repository\InMemoryRepository;

$currencyRepository = new InMemoryRepository();
$currencyProvider = new CurrencyProvider($currencyRepository);

$currencyProvider->getAvailableCurrencies(); // Returns an array of Currency objects.

The getAvailableCurrencies method retrieves all currencies which enabled property is set to true and have been inserted in the given repository.

Note

This service implements the CurrencyProviderInterface.