User Guide | Setting Currency Session Data

Data is set to the cart session by using functions primarily from flexi carts standard library.

The data that can be set in the cart session includes data of items added to the cart, user localisation data and cart configuration settings.

Since many of flexi carts features can be set using either manually submitted data, or data retrieved from the database; there are often two versions of a function to set session data. Functions that update session data using the database are prefixed with the function name 'update_xxx', whilst functions that use manually set data are prefixed with the name 'set_xxx'.

Set Currency Session Data

Currency Function Index | Currency Config | Get Currency Session Data | Get Currency Helper Data | Currency Admin Data
Set Currency Data to Session

update_currency() | set_currency()

Help with Setting Session Data Functions

Show / Hide Help

Name: The name of the function (method).

Data Type: The data type that is expected by the function.

  • bool : Requires a boolean value of 'TRUE' or 'FALSE'.
  • string : Requires a textual value.
  • int : Requires a numeric value. It does not matter whether the value is an integer, float, decimal etc.
  • array : Requires an array.

Required: Defines whether the parameter requires a value to be submitted.

Default: Defines the default parameter value that is used if no other value is submitted.

update_currency()

Looks-up the currency database table and tries to match a currency with the submitted currency id or name.


Library and Requirements

Available via the standard library only.

Requires currency database table to be enabled.

Function Parameters
update_currency(currency_identifier) Help
Name Data Type Required Default Description
currency_identifier string | int No FALSE The id or name of the currency.
How it Works

The function will check if the 'currency_identifier' is numeric or a string and run an SQL SELECT query filtered to match the identifier either with a currency id or name.

Notes

This function can also be set via the 'update_cart()' function.

Return Values

Failure:FALSE | An error message will be set.

Success:TRUE | A status message will be set.

Examples
// Example #1 : Update the currency using a currency id.

$currency_identifier = 101;

$this->flexi_cart->update_currency($currency_identifier);
// Example #2 : Update the currency using a currency name.

$currency_identifier = 'GBP';

$this->flexi_cart->update_currency($currency_identifier);

set_currency()

Manually sets the cart currency without querying a database table.


Library and Requirements

Available via the standard library only.

Does not require any database tables to be enabled.

Function Parameters
set_currency(currency_data) Help
Name Data Type Required Default Description
currency_data array Yes FALSE The array contains the data that is to update the carts currency data.
See the documentation and examples below for further information.
How it Works

The function loops through the 'currency_data' array and sets any data from the following array keys to the cart currency data.

The valid array keys are 'name', 'exchange_rate', 'symbol', 'symbol_suffix', 'thousand_separator' and 'decimal_separator'.

  • 'name' - The name of the currency.
  • 'exchange_rate' - The exchange rate between the currency and the carts internal currency.
  • 'symbol' - The currency sybmol.
  • 'symbol_suffix' - Define whether to suffix the currency symbol rather than prefix it.
  • 'thousand_separator' - Define the 'thousand' separator character.
  • 'decimal_separator' - Define the 'decimal' separator character.
Notes

This function can also be set via the 'update_cart()' function.

Return Values

Failure:FALSE | An error message will be set.

Success:TRUE | A status message will be set.

Example
$currency_data = array(
'name' => 'example_name',
'exchange_rate' => 1.65,
'symbol' => '£',
'symbol_suffix' => FALSE,
'thousand_separator' => ',',
'decimal_separator' => '.'
);

$this->flexi_cart->set_currency($currency_data);