Heystack\Ecommerce\Currency\CurrencyService
CurrencyService default implementation
This handles all the operations needed keep track of and calculate currencies and their values
- Author: Glenn Bautista <glenn@heyday.co.nz>
- Copyright: Heyday
Synopsis
class CurrencyService
implements
CurrencyServiceInterface
{
- // constants
- const ACTIVE_CURRENCY_KEY = 'currencyservice.activecurrency';
- // members
- protected $currencies;
- protected CurrencyInterface $activeCurrency;
- protected CurrencyInterface $defaultCurrency;
- // methods
- public void __construct()
- protected void setCurrencies()
- protected void addCurrency()
- public void restoreState()
- public void saveState()
- public bool setActiveCurrency()
- public CurrencyInterface getActiveCurrency()
- public string getActiveCurrencyCode()
- public array getCurrencies()
- public Money convert()
- public CurrencyInterface|null getCurrency()
- public bool hasCurrency()
- public CurrencyInterface getDefaultCurrency()
- public void setDefaultCurrency()
- public Money getZeroMoney()
Hierarchy
Uses
- Heystack\Core\Traits\HasEventServiceTrait
- Heystack\Core\Traits\HasStateServiceTrait
Implements
Constants
Name | Value |
---|---|
ACTIVE_CURRENCY_KEY | 'currencyservice.activecurrency' |
Members
protected
- $activeCurrency — \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface
- $currencies
—
array
An array of currencies - $defaultCurrency — \Heystack\Ecommerce\Currency\Interfaces\CurrencyInterface
Methods
protected
public
- __construct()
- convert() — Converts amount from one currency to another using the currency's identifier
- getActiveCurrency() — Retrieves the currently active currency
- getActiveCurrencyCode() — Retrieves the currently active currency code
- getCurrencies() — Retrieves all the available currencies
- getCurrency()
- getDefaultCurrency() — Returns the default currency object
- getZeroMoney()
- hasCurrency()
- restoreState() — Uses the State service to retrieve the active currency's identifier and sets the active currency.
- saveState() — Saves the data array on the State service
- setActiveCurrency()
- setDefaultCurrency() — Sets the default currency