leowebguy / craft-currency-converter
Craft plugin to convert currency using API & local storage
Package info
github.com/leowebguy/craft-currency-converter
Type:craft-plugin
pkg:composer/leowebguy/craft-currency-converter
2.0.2
2024-07-31 12:48 UTC
Requires
- php: ^8.2
- craftcms/cms: ^5.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- craftcms/rector: dev-main
- laravel/pint: ^1.14.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Craft plugin to convert currency using API & local storage.
Requirements
This plugin requires:
- Craft CMS:
^5.0.0 - PHP:
^8.2 || ^8.3 || ^8.4 || ^8.5
Installation
Open your terminal and go to your Craft project:
cd /path/to/project
Then tell Composer to load the plugin:
composer require leowebguy/craft-currency-converter -w
In the Control Panel, go to Settings → Plugins and click the Install button for Currency Converter.
Configuration
- Go to RapidAPI Currency Converter and obtain your API Key.
- In the Control Panel, go to Settings → Currency Converter and paste your API Key.
- Alternatively, define an environment variable in your
.envfile:CC_KEY=aaa123bbb234
And reference it in the plugin settings as$CC_KEY. - Choose your preferred cache duration (1 to 24 hours). Rates are stored in Craft's storage folder (
storage/currency/) to minimize API requests.
Usage
The plugin exposes currency conversion helper methods via Twig:
{# Passing dynamic entry field value #} {% set amount = craft.entries.section('mySection').one().numberField %} {{ craft.currency.conversion('USD', 'EUR', amount) }}
{# Passing an integer or float #} {{ craft.currency.conversion('USD', 'EUR', 23.50) }}
{# Passing a numeric string #} {{ craft.currency.conversion('USD', 'EUR', '23') }}
Development & Testing
# Run PHPStan static analysis (Level 8) composer phpstan # Run PSR-12 code style check composer pint-test # Auto-fix code style issues composer pint # Run Rector Craft 5 migration checks composer rector
License
MIT License. See LICENSE.md for details.
