User Guide | Discount 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.

Discount Helper Functions

Discount Function Index | Discount Config | Get Discount Session Data | Set Discount Session Data | Discount Admin Data
Get Discount Data from Database

get_discount_requirements() | get_item_discounts()

Calculate Savings Values

get_saving_value() | get_saving_percentage()

Calculate Expire Time

get_expire_time()

Help with Helper 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_discount_requirements()

Looks-up the database and returns an array containing the quantity and value required to activate a specific discount.


Library and Requirements

Available via the lite, standard and admin libraries.

Requires the discount database tables to be enabled.

Function Parameters
get_discount_requirements(discount_id, format, internal_value) Help
Name Data Type Required Default Description
discount_id int Yes FALSE Defines the id of the discount to return requirement data for.
format bool No TRUE Define whether to format the returned value as a currency.
internal_value bool No FALSE Defines whether to return the monetary value using the carts internal currency instead of the users current currency.
Return Values

Failure:FALSE

Success:array

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_discount_requirements(4, TRUE, FALSE) Show the requirements to activate a specific discount (disc_id = 4), and the outstanding internal values until the discount is active. Show / Hide Array

						
get_discount_requirements(4, TRUE, TRUE) Show the requirements to activate a specific discount (disc_id = 4), and the outstanding current values until the discount is active. Show / Hide Array

						

get_item_discounts()

Looks-up the database and returns an array of discounts that can be applied to a specific item.


Library and Requirements

Available via the lite, standard and admin libraries.

Requires the discount database tables to be enabled.

Function Parameters
get_item_discounts(item_id, sql_select, sql_where) Help
Name Data Type Required Default Description
item_id int Yes FALSE Defines the id of the item to return data for.
sql_select string | array No FALSE Define the database fields returned via an SQL SELECT statement.
Read the defining SQL documentation for further information.
sql_where string | int | array No FALSE Set the SQL WHERE statement used to filter the database records to return.
Read the defining SQL documentation for further information.
Return Values

Failure:array (Empty)

Success:array

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_item_discounts($item_id, FALSE, FALSE) Using a database lookup, get all discounts that could be applied to this item and return them as an array. Show / Hide Array
Array
(
)
get_item_discounts($item_id, 'disc_id, disc_description', array('disc_item_fk' => 101)) Using a database lookup, get all discounts that could be applied to this item, but return only the id and description. Show / Hide Array
Array
(
)

get_saving_value()

Calculates the difference between two monetary values.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
get_saving_value(new_value, original_value, format) Help
Name Data Type Required Default Description
new_value int Yes 0 Defines the discounted/cheaper value.
original_value int Yes 0 Defines the original value.
format bool No TRUE Define whether to format the returned value as a currency.
Return Values

Failure:n/a

Success:int | (string if value is formatted)

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_saving_value(10, 25.50, TRUE) What is the monetary saving from a discount of "Was £25.50, now £10"? £15.50

get_saving_percentage()

Calculates the percentage difference between two monetary values.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
get_saving_percentage(new_value, original_value, suffix_delimiter, decimals) Help
Name Data Type Required Default Description
new_value int Yes 0 Defines the discounted/cheaper value.
original_value int Yes 0 Defines the original value.
suffix_delimiter string No % Defines a value that is suffixed to the end of the returned value.
decimals int No 0 Defines the number of decimals to return the value with.
Return Values

Failure:n/a

Success:int | (string if value is formatted)

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_saving_percentage(33.33, 100, '%', 1) What is the percentage saving from a discount of "Was £100, now £33.33"? 66.7%

get_expire_time()

Returns the number of seconds until a submitted date.
The returned value can then be used to generate a countdown timer.


Library and Requirements

Available via the lite, standard and admin libraries.

Does not require any database tables to be enabled.

Function Parameters
get_expire_time(expire_date) Help
Name Data Type Required Default Description
expire_date string | int Yes FALSE The expiry date to return a timestamp for.
The submitted date can be formatted as either a UNIX timestamp, or a MySQL DATE or DATETIME string.
Notes

Example 'expire_date' values:

  • UNIX timestamp : '1234567890'
  • MySQL DATE string : '2015-01-01'
  • MySQL DATETIME string : '2015-01-01 12:30:00'

Return Values

Failure:n/a

Success:int

Examples
Note: The returned example values below are displaying live data from the current cart session data.
get_expire_time('2015-01-01 00:00:00') How many seconds from now until January 1st 2015? -203548772
get_expire_time(date('Y-m-d H:i:s', strtotime('2 hours'))) How many seconds for a 2 hour countdown from now? 7200
A demo of using 'get_expire_time()' with the jQuery Countdown plugin, using the 2 hour countdown example.
2021-06-13 22:19:32