User Guide | Cart Helper Data

Helper functions are used to provide value formatting and calculation functionality, or to return data from the carts database tables.

The functions can act independently of data within the cart session, using database table ids or custom data directly submitted to the function to return values, rather than for example requiring the row id of an item in the cart.

This independence from data within the cart session means the functions can be used on pages across a site that do not display cart data, or even on items that have not been added to the cart.

The data within the carts session can then be accessed and in many cases, formatted and customised using the large range of functions that are available from the lite and standard libraries.

Cart Helper Functions

List all Cart Functions | Get Cart Item Session Data | Get Cart Summary Session Data | Get Cart Session Data | Set Cart Session Data
Date and Time Helper Functions

get_date_time()

Weight Helper Functions

weight_name() | weight_symbol() | convert_weight() | format_weight() | get_weight_types()

Get Real Database Names

db_table() | db_column()

Help with Cart 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.

get_date_time()

Returns either an SQL DATETIME formatted time stamp or a UNIX timestamp.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
get_date_time(apply_time, date_time, force_unix) Help
Name Data Type Required Default Description
apply_time int No 0 Defines the number of seconds to apply to the to-be-returned time.
Example: Add 2 hours = 7200 (60 Sec x 60 Min x 2 Hours).
date_time string | int No FALSE Defines the date/time to base the returned time value on.
The submitted date can be formatted as either a UNIX timestamp, or a MySQL DATE or DATETIME string.
force_unix bool No FALSE Defines whether to force the function to return a UNIX timestamp, regardless of whether the cart is set to use MySQL DATETIME.
Notes

The type of date value returned is based on the value in the config files '$config['settings']['date_time']', which can either be in a MySQL DATETIME, or UNIX timestamp format.

Return Values

Failure:n/a

Success:string (MySQL DATETIME) | int (UNIX Timestamp)

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_date_time(FALSE, FALSE, FALSE) What is the current date and time? 2021-06-13 20:34:24
get_date_time(3600, FALSE, FALSE) What is the current date and time, plus 1 hour? (60 seconds * 60 minutes = 3600 seconds) 2021-06-13 21:34:24
get_date_time(-3600, FALSE, FALSE) What is the current date and time, minus 1 hour? (60 * 60 = 3600 seconds) 2021-06-13 19:34:24
get_date_time(43200, '2010-01-01 09:00:00', FALSE) What was the date and time on 1st January 2010 @ 9am, plus 12 hours? (60 * 60 * 12 = 43200 seconds) 2010-01-01 21:00:00
get_date_time(43200, '2010-01-01 09:00:00', TRUE) What was the date and time on 1st January 2010 @ 9am, plus 12 hours, as a UNIX timestamp? (60 * 60 * 12 = 43200 seconds) 1262340000

weight_name()

Returns the name of the carts default weight type.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Return Values

Failure:FALSE

Success:string

Examples
Note: The returned example values below are displaying live data from the current cart session data.
weight_name() What is the name for the carts default weight? Gram

weight_symbol()

Returns the symbol of the carts default weight type.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Return Values

Failure:FALSE

Success:string

Examples
Note: The returned example values below are displaying live data from the current cart session data.
weight_symbol() What is the symbol for the carts default weight? g

convert_weight()

Returns a weight converted from one weight type to another.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
convert_weight(value, convert_from, convert_to, format, decimals) Help
Name Data Type Required Default Description
value int Yes 0 The value to be converted.
convert_from string No FALSE Defines the weight type to convert the value 'from'.
If no valid weight type is submitted, the carts default is used.
convert_to string No FALSE Defines the weight type to convert the value 'to'.
If no valid weight type is submitted, the carts default is used.
format bool No TRUE Define whether to format the returned value as a weight.
decimals int No FALSE Defines the number of decimals to return the value with.
Return Values

Failure:int (0)

Success:int | (string if value if formatted)

Examples
Note: The returned example values below are displaying live data from the current cart session data.
convert_weight(10, 'gram', 'kilogram', TRUE, 2) Convert 10 grams to kilograms, displayed to 2 decimals. 0.01kg
convert_weight(10, 'kilogram', 'gram', TRUE, 0) Convert 10 kilograms to grams, displayed to 0 decimals. 10,000g

format_weight()

Returns the submitted value formatted as a weight.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
format_weight(value, weight_type, format, decimals, internal_format) Help
Name Data Type Required Default Description
value int Yes 0 The value to be formatted.
weight_type string No FALSE Defines the weight type to format the weight as.
If no value is submitted, the carts default is used.
format bool No TRUE Define whether to format the returned value with a weight symbol and a 'thousand' separator.
decimals int No FALSE Defines the number of decimals to return the value with.
internal_format bool No FALSE Defines whether to format the weight using the carts internal default settings, or the users current session settings.
Return Values

Failure:int (0)

Success:int | (string if value is formatted)

Examples
Note: The returned example values below are displaying live data from the current cart session data.
format_weight(10, FALSE, TRUE, FALSE, FALSE) Format '10' to the carts default weight type, using the format settings (thousand, decimal separators) for the current currency. 10g
format_weight(10.5, 'kilogram', TRUE, 2, FALSE) Format '10.5' to a 2 decimal kilogram weight, using the format settings (thousand, decimal separators) for the current currency. 10.50kg
format_weight(10, FALSE, TRUE, FALSE, TRUE) Format '10' to the carts default weight type, using the format settings (thousand, decimal separators) for the internal currency. 10g

get_weight_types()

Returns either an array of data for a specific weight type or a multi-dimensional array all weight types and their data.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
get_weight_types(name) Help
Name Data Type Required Default Description
name string No FALSE Defines the weight type to return for.
Available weight types are 'gram', 'kilogram', 'avoir_ounce', 'avoir_pound', 'troy_ounce', 'troy_pound' and 'carat'.
Return Values

Failure:n/a

Success:array | (Single dimensional if 'name' submitted, multi-dimensional otherwise)

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_weight_types(FALSE) Return an array of all weight types that are available in flexi cart. Show / Hide Array
Array
(
    [gram] => Array
        (
            [name] => Gram
            [conversion] => 1
            [symbol] => g
        )

    [kilogram] => Array
        (
            [name] => Kilogram
            [conversion] => 1000
            [symbol] => kg
        )

    [avoir_ounce] => Array
        (
            [name] => Avoir Ounce
            [conversion] => 28.3495
            [symbol] => oz
        )

    [avoir_pound] => Array
        (
            [name] => Avoir Pound
            [conversion] => 453.5924
            [symbol] => lb
        )

    [troy_ounce] => Array
        (
            [name] => Troy Ounce
            [conversion] => 31.1035
            [symbol] => t oz
        )

    [troy_pound] => Array
        (
            [name] => Troy Pound
            [conversion] => 373.2417
            [symbol] => t lb
        )

    [carat] => Array
        (
            [name] => Carat
            [conversion] => 0.2
            [symbol] => ct
        )

)
get_weight_types('kilogram') Return an array of data for the kilogram weight type that is available in flexi cart. Show / Hide Array
Array
(
    [name] => Kilogram
    [conversion] => 1000
    [symbol] => kg
)

db_table()

Returns the actual name of a table defined in the config file by referencing the tables internal name.

By using this function to reference database table names on pages throughout a site, if the table name is ever changed, the new name only has to be updated once via the config file, rather than updating the usage of the original name throughout a site.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
db_table(table) Help
Name Data Type Required Default Description
table string Yes FALSE The internal name of the table.
Return Values

Failure:FALSE

Success:string

Examples
Note: The returned example values below are displaying live data from the current cart session data.
db_table('item_shipping') What is the actual table name for the 'item_shipping' table alias? shipping_item_rules

db_column()

Returns the actual name of a table column defined in the config file by referencing the table columns internal name.

By using this function to reference database column names on pages throughout a site, if the column name is ever changed, the new name only has to be updated once via the config file, rather than updating the usage of the original name throughout a site.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
db_column(table, column) Help
Name Data Type Required Default Description
table string Yes FALSE The internal name of the table.
column string Yes FALSE The internal name of the tables column.
Return Values

Failure:FALSE

Success:string

Examples
Note: The returned example values below are displaying live data from the current cart session data.
db_column('item_shipping', 'id') What is the actual column name for the 'id' column alias in the 'item_shipping' table alias? ship_item_id