Multiple Currency Laravel Service: Manage product prices in multiple currencies

Recommend this page to a friend!
  Info   Documentation   View files (15)   Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-03-04 (5 months ago) Not yet rated by the usersTotal: 41 All time: 9,885 This week: 306
Version License PHP version Categories
laravel-currency 1.0.0Custom (specified...5PHP 5, E-Commerce, Finances
Description Author

This package can manage product prices in multiple currencies.

It comes with a Laravel service provider and a trait to allow making product prices appear customized for each user in a given currency.

The list of supported currencies for the product prices is determined from the values set in a configuration script.

Innovation Award
PHP Programming Innovation award nominee
March 2020
Number 11
International e-commerce sites that show products with prices in the currency that the current buyer uses in his country tend to sell more because it is easier for the buyer to understand the product price than if the price was in a foreign currency.

This package provides a solution to retrieve product prices expressed in the currency of the current user country.

Manuel Lemos
Picture of Moamen Eltouny
  Performance   Level  
Name: Moamen Eltouny <contact>
Classes: 11 packages by
Country: Egypt Egypt
Innovation award
Innovation award
Nominee: 5x

Details

[RaggiTech] Laravel >= 6.0 - Currency.

Latest Stable Version Total Downloads License

Laravel Currency provides a quick and easy methods with 150+ Currency.

Example:

// Create/Update Currency
$product->setCurrency(15.59, 'USD');

// Retrieve Currency's Value
echo $product->currency('USD'); 			// 15.59
echo $product->currencyWithSymbol('USD'); 	// $15.59
echo $product->currencyWithCode('USD'); 	// 15.59 USD

Install

Install the latest version using Composer:

$ composer require raggitech/laravel-currency

then publish the migration & config files

$ php artisan vendor:publish --tag=laravel-currency
$ php artisan migrate

Usage

<a name="config"></a>

Configurations

Default Currency & Only List

use RaggiTech\Laravel\Currency\Currency;

Currency::setDefault('USD'); // Setting USD as a default currency.
Currency::setOnly(['USD', 'EGP']); // Allow using only USD, EGP.

<a name="list"></a>

Currencies List

$list = currenciesList();
/
*	"USD" => "US Dollar"
* 	"CAD" => "Canadian Dollar"
* 	"EUR" => "Euro"
* 	"AED" => "United Arab Emirates Dirham"
* 	...
*/

<a name="cu"></a>

Create / Update Currency's Value

$product->setCurrency(15.59, 'USD');

<a name="get"></a>

Retrieve Currency's Value

// 15.59 if USD is the default currency
// NULL if there's no value for the default currency.
echo $product->currency();

echo $product->currency('USD'); 			// 15.59		|| NULL
echo $product->currencyWithSymbol('USD'); 	// $15.59		|| NULL
echo $product->currencyWithCode('USD'); 	// 15.59 USD	|| NULL

<a name="dc"></a>

Delete a single currency || Clear all model's currencies

$product->deleteCurrency('EGP'); 	// Delete EGP Currency
$product->clearCurrencies();		// Clear all currencies

<a name="relationship"></a>

Relationship

$product->currencies; 	// All currencies list of a single model

<a name="scopes"></a>

Scopes

// Get every element has no currency.
$p1 = Product::withoutCurrencies()->get();

// Get every element has EGP currency.
$p2 = Product::withCurrency('EGP')->get();

// Get every element has [EGP or USD or all] currency.
$p3 = Product::withAnyCurrency(['EGP', 'USD'])->get();

<a name="u"></a>

Creator

// Get User Model
$product->currency()->user;

License

MIT license

  Files  
File Role Description
src (4 files, 5 directories)
composer.json Data Auxiliary data
LICENSE Lic. License text
README.md Doc. Documentation

  Files  /  src  
File Role Description
config (1 file)
data (1 file)
database (1 directory)
Exceptions (2 files)
Traits (3 files)
   Currency.php Class Class source
   CurrencyServiceProvider.php Class Class source
   hasCurrency.php Class Class source
   Helpers.php Aux. Auxiliary script

  Files  /  src  /  config  
File Role Description
   currency.php Conf. Configuration script

  Files  /  src  /  data  
File Role Description
   currencies.php Conf. Configuration script

  Files  /  src  /  database  
File Role Description
migrations (1 file)

  Files  /  src  /  database  /  migrations  
File Role Description
   currencies.stub Class Class source

  Files  /  src  /  Exceptions  
File Role Description
   NotAllowedCurrencyException.php Class Class source
   UnknownCurrencyException.php Class Class source

  Files  /  src  /  Traits  
File Role Description
   Info.php Class Class source
   Relationships.php Class Class source
   Scopes.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:41
This week:0
All time:9,885
This week:306

For more information send a message to info at phpclasses dot org.