Currency
in package
Currency related static methods
Tags
Table of Contents
Constants
- STYLE_NAME_ACTIVE = 'active'
- STYLE_NAME_INACTIVE = 'inactive'
- class suffixes for active/inactive currencies
- TEXT_NAME = 'currency_name'
- Text key
Properties
- $activeCurrencyId : int
- Active currency object id (default null).
- $arrCurrency : array<string|int, mixed>
- Array of available currencies (default null).
- $defaultCurrencyId : int
- Default currency object id (defaults to null).
Methods
- add() : bool
- Add a new currency
- delete() : bool
- Deletes a currency
- errorHandler() : bool
- Handles database errors
- formatCents() : int
- Returns the amount in a non-localized notation in cents, rounded to one cent.
- formatPrice() : float
- Returns the formatted amount in a non-localized notation
- get_known_currencies_increment_array() : array<string|int, mixed>
- Returns the array of increments for all known currencies indexed by ISO 4217 code
- get_known_currencies_name_array() : array<string|int, mixed>
- Returns the array of names for all known currencies indexed by ISO 4217 code
- getActiveCurrencyCode() : string
- Returns the active currency code
- getActiveCurrencyId() : int
- Returns the active currency ID
- getActiveCurrencySymbol() : string
- Returns the active currency symbol
- getCodeById() : mixed
- Return the currency code for the ID given
- getCurrencyArray() : array<string|int, mixed>
- Returns the currency array
- getCurrencyCodeById() : string
- Returns the currency code for the given ID
- getCurrencyNavbar() : string
- Set up the Currency navbar
- getCurrencyPrice() : string
- Returns the amount converted from the default to the active currency
- getCurrencySymbolById() : string
- Returns the currency symbol for the given ID
- getDefaultCurrencyCode() : string
- Returns the default currency code
- getDefaultCurrencyId() : int
- Returns the default currency ID
- getDefaultCurrencyPrice() : string
- Returns the amount converted from the active to the default currency
- getDefaultCurrencySymbol() : string
- Returns the default currency symbol
- getSymbolById() : mixed
- Return the currency symbol for the ID given
- init() : mixed
- Initialize currencies
- known_currencies() : array<string|int, mixed>
- Returns the array of known currencies
- reset() : mixed
- Resets the $arrCurrency class array to null to enforce reinitialisation
- setActiveCurrencyId() : mixed
- Set the active currency ID
- setDefault() : mixed
- store() : bool
- Store the currencies as present in the post request
- update() : bool
- Update currencies
Constants
STYLE_NAME_ACTIVE
public
mixed
STYLE_NAME_ACTIVE
= 'active'
STYLE_NAME_INACTIVE
class suffixes for active/inactive currencies
public
mixed
STYLE_NAME_INACTIVE
= 'inactive'
TEXT_NAME
Text key
public
mixed
TEXT_NAME
= 'currency_name'
Properties
$activeCurrencyId
Active currency object id (default null).
private
static int
$activeCurrencyId
= false
Tags
$arrCurrency
Array of available currencies (default null).
private
static array<string|int, mixed>
$arrCurrency
= null
Tags
$defaultCurrencyId
Default currency object id (defaults to null).
private
static int
$defaultCurrencyId
= false
Tags
Methods
add()
Add a new currency
public
static add([int $localeId = 0 ]) : bool
If the posted data is incomplete sets a message, and returns null. Returns false on database errors only.
Parameters
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
Return values
bool —Null if nothing was added, boolean true upon adding the currency successfully, or false otherwise
delete()
Deletes a currency
public
static delete() : bool
This method will fail if you try to delete the default Currency.
Return values
bool —Null if nothing was deleted, boolean true upon deleting the currency successfully, or false otherwise
errorHandler()
Handles database errors
public
static errorHandler() : bool
Also migrates old Currency names to the Text class, and inserts default Currencyes if necessary
Tags
Return values
bool —false Always!
formatCents()
Returns the amount in a non-localized notation in cents, rounded to one cent.
public
static formatCents(string $amount) : int
Note that the amount argument is supposed to be in decimal format with decimal separator and the appropriate number of decimal places, as returned by , but it also works for integer values like the ones returned by itself. Removes underscores (_) as well as decimal (.) and thousands (') separators, and replaces dashes (-) by zeroes (0).
Parameters
- $amount : string
-
The amount in decimal format
Tags
Return values
int —The amount in cents, rounded to one cent
formatPrice()
Returns the formatted amount in a non-localized notation
public
static formatPrice(float $price[, string $length = '' ][, string $padding = '' ][, float $increment = null ]) : float
The optional $length is inserted into the sprintf() format string and determines the maximum length of the number. If present, the optional $padding character is inserted into the sprintf() format string. The optional $increment parameter overrides the increment value of the active Currency, which is used by default. The $increment value limits the number of digits printed after the decimal point. Currently, the number is formatted as a float, using no thousands, and '.' as decimal separator.
Parameters
- $price : float
-
The amount
- $length : string = ''
-
The optional number length
- $padding : string = ''
-
The optional padding character
- $increment : float = null
-
The optional increment
Tags
Return values
float —The formatted amount
get_known_currencies_increment_array()
Returns the array of increments for all known currencies indexed by ISO 4217 code
public
static get_known_currencies_increment_array() : array<string|int, mixed>
Return values
array<string|int, mixed> —The currency increment array
get_known_currencies_name_array()
Returns the array of names for all known currencies indexed by ISO 4217 code
public
static get_known_currencies_name_array([string $format = null ]) : array<string|int, mixed>
You can specify a custom format for the names using the $format parameter. It defaults to '%2$s (%1$s)', that is the currency name (%2) followed by the ISO 4217 code (%1) in parentheses. Also, the number of decimals for the currency is available as %3.
Parameters
- $format : string = null
-
The optional sprintf() format
Return values
array<string|int, mixed> —The currency name array
getActiveCurrencyCode()
Returns the active currency code
public
static getActiveCurrencyCode() : string
This usually corresponds to the ISO 4217 code for the Currency, like CHF, or USD.
Tags
Return values
string —The string representing the active currency code
getActiveCurrencyId()
Returns the active currency ID
public
static getActiveCurrencyId() : int
Tags
Return values
int —The ID of the active currency
getActiveCurrencySymbol()
Returns the active currency symbol
public
static getActiveCurrencySymbol() : string
This is a custom Currency name that does not correspond to any ISO standard, like "sFr.", or "Euro".
Tags
Return values
string —The string representing the active currency
getCodeById()
Return the currency code for the ID given
public
static getCodeById(int $currencyId) : mixed
Mind that some methods rely on the return value being NULL for unknown Currencies, see PaymentProcessing::checkIn().
Parameters
- $currencyId : int
-
The currency ID
Tags
Return values
mixed —The currency code on success, NULL otherwise
getCurrencyArray()
Returns the currency array
public
static getCurrencyArray() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —The currency array
getCurrencyCodeById()
Returns the currency code for the given ID
public
static getCurrencyCodeById(mixed $currency_id) : string
Parameters
- $currency_id : mixed
Tags
Return values
string —The string representing the active currency code
getCurrencyNavbar()
Set up the Currency navbar
public
static getCurrencyNavbar() : string
Tags
Return values
string —The HTML code for the Currency navbar
getCurrencyPrice()
Returns the amount converted from the default to the active currency
public
static getCurrencyPrice(float $price) : string
Note that the amount is rounded to five cents before formatting.
Parameters
- $price : float
-
The amount in default currency
Tags
Return values
string —Formatted amount in the active currency
getCurrencySymbolById()
Returns the currency symbol for the given ID
public
static getCurrencySymbolById(mixed $currency_id) : string
Parameters
- $currency_id : mixed
Tags
Return values
string —The string representing the active currency
getDefaultCurrencyCode()
Returns the default currency code
public
static getDefaultCurrencyCode() : string
Tags
Return values
string —The string representing the default currency code
getDefaultCurrencyId()
Returns the default currency ID
public
static getDefaultCurrencyId() : int
Tags
Return values
int —The ID of the default currency
getDefaultCurrencyPrice()
Returns the amount converted from the active to the default currency
public
static getDefaultCurrencyPrice(float $price) : string
Note that the amount is rounded to five cents before formatting.
Parameters
- $price : float
-
The amount in active currency
Tags
Return values
string —Formated amount in default currency
getDefaultCurrencySymbol()
Returns the default currency symbol
public
static getDefaultCurrencySymbol() : string
Tags
Return values
string —The string representing the default currency
getSymbolById()
Return the currency symbol for the ID given
public
static getSymbolById(int $currencyId) : mixed
Parameters
- $currencyId : int
-
The currency ID
Tags
Return values
mixed —The currency symbol on success, false otherwise
init()
Initialize currencies
public
static init([mixed $active_currency_id = 0 ][, int $localeId = 0 ]) : mixed
Sets up the Currency array, and picks the selected Currency from the 'currency' request parameter, if available.
Parameters
- $active_currency_id : mixed = 0
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
known_currencies()
Returns the array of known currencies
public
static known_currencies() : array<string|int, mixed>
The array is of the form array( array( 0 => ISO 4217 code, 1 => Country and currency name, 2 => number of decimals, ), ... more ... ) Note that the code is unique, however, some currencies appear more than once with different codes that may be used. The number of decimals may be non-numeric if unknown. Ignore these.
Tags
Return values
array<string|int, mixed> —The known currencies array
reset()
Resets the $arrCurrency class array to null to enforce reinitialisation
public
static reset() : mixed
Call this after changing the database table
setActiveCurrencyId()
Set the active currency ID
public
static setActiveCurrencyId(int $currency_id) : mixed
Parameters
- $currency_id : int
-
The active Currency ID
Tags
setDefault()
public
static setDefault(mixed $currency_id) : mixed
Parameters
- $currency_id : mixed
store()
Store the currencies as present in the post request
public
static store() : bool
Return values
bool —The empty string if nothing was changed, boolean true upon storing everything successfully, or false otherwise
update()
Update currencies
public
static update([int $localeId = 0 ]) : bool
Parameters
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
Return values
bool —Null if nothing was changed, boolean true upon storing everything successfully, or false otherwise