Skip to content

About

A CakePHP plugin to convert your price from a currency to another

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

 
 

Repository files navigation

cakephp-currency-converter V 2.2.2

Scrutinizer Code Quality Code Coverage Latest Stable Version License Build Status Total Downloads

A CakePHP plugin to convert your price from a currency to another currency


Background

Is very frequently that inside your sites you need to convert your price from a currency to another currency. This library convert your price in every currency of the world.

It works with fixer.io and can store currency rates inside a database if you would like. You can configure time updates to get new conversion from fixer.io, if you don't want to use database, rates are updated every time with the current conversion.

If you have set to use database, for example, you can set to update currency rates every hour, this library get the currency conversion from fixer.io the first time, store it inside the database and for the next hour it takes conversion rates from the database if exist. In this way reduce the request time to convert and every hour currency rates are updated.

If you haven't set to use database, instead, every time you call the library it makes a request to fixer.io and gets the actual conversion rate. This solution is great if you haven't a lot of request. Instead, if you have a lot of request conversions is better to use the database configuration.


Requirements

  • CakePHP 3.x
  • PHP 5.x

For cakephp 2.x you can download version 1.1.4


Installation

To install the plugin inside your cakephp project you can do this:

[Composer]

  • Open your console
  • Inside your application folder
  • Execute
$ composer require "alessandrominoccheri/cakephp-currency-converter"

[Manual]

[GIT Clone]

In your Plugin directory type:

$ git clone https://github.com/AlessandroMinoccheri/cakephp-currency-converter.git CurrencyConverter

Enable plugin

In cakephp 3.x you need to enable the plugin your config/bootstrap.php file:

Plugin::load('CurrencyConverter');

But if you don0t want to use composer you can load plugin in this way:

Plugin::load('CurrencyConverter', ['autoload' => true]);

If you are already using Plugin::loadAll();, then this is not necessary.


Usage

To convert your price form your controller you need to load the plugin (view section Enable plugin) and type something like this:

$price = $this->CurrencyConverter->convert('GBP', 'EUR', '2100,00', true, 1);

With this call you have inside variable "price" the new price converter from GBP to EUR.

To get a list of currency code you can check here:

List of available currency code

To view an example of usage you can clone this repository that I have created with this plugin installed inside and already works: Example

If you have some kind of problem like this issue: AlessandroMinoccheri#1 (comment)

Try to give 777 to the plugin folder


Params

The function declaration to retrieve your converted price is:

function convert($from_currency, $to_currency, $amount, $save_into_db = 1, $hour_difference = 1)
  • from_currency: is the actual price currency (Example: EUR, GBP)
  • to_currency: is the currency that you want to convert your price (Example: EUR, GBP)
  • amount: is the price to convert (Example: 200,20)
  • save_into_db: is the variable that configure to use the database or not, if not hour_difference params is escaped
  • hour_difference: is the hour difference to update your currency conversion. For example if you have set to update currency rates every hour, this library get the currency conversion from fixer.io the first time, store it inside the database and for the next hour it takes conversion rates from the database if exist.

For cakephp 2.x you can download version 1.1.4


License

The MIT License (MIT)

Copyright (c) 2014 Alessandro Minoccheri

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A CakePHP plugin to convert your price from a currency to another

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages