User Guide | Admin Reward Point and Voucher Functions

Admin functions are available from the flexi cart admin library and are primarily used to manage data within flexi carts database tables.

Many of the functions perform CRUD functionality returning SELECT queries and running INSERT, UPDATE and DELETE statements.
The CRUD functions are automatically joined to other related tables and allow custom statements to be run, with minimal configuration required.

Admin Reward Point and Voucher Functions

Reward Function Index | Reward Config | Get Reward Session Data | Get Reward Helper Data

Help with Admin 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_db_reward_points()

Gets records from the reward points table.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
get_db_reward_points(sql_select, sql_where) Help
Name Data Type Required Default Description
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.
How it Works

The function runs a joined SQL SELECT statement on the 'Reward Points' (pseudo table), 'Reward Points Converted' and 'Order Status' tables.

The function then loops through the results and calculates an itemised summary for the number of reward points that are 'active', 'pending', 'expired', 'converted' and 'cancelled' per row.

  • Total - Points earnt from ordered item.
  • Active - Points earnt from ordered items that are marked as shipped; are within their expiry date and that have not been converted.
  • Pending - Points earnt from ordered items that are yet to be marked as shipped.
  • Expired - Points that were not converted to reward vouchers within their expiry date.
  • Converted - Points that have been converted to reward vouchers.
  • Cancelled - Points earnt from ordered items that have been cancelled or returned.

The query can be customised by submitting 'sql_select' and 'sql_where' data to the functions parameters.

Note that the names of these itemised summary columns are defined via the config file are always returned by the function, regardless of the 'sql_select' values. Read the Itemised Pseudo Column documentation for further information on setting aliases via the config file.

Notes

This function is compatible with flexi carts 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi cart and CodeIgniter functions that are available.


If an int value is submitted to the 'sql_where' parameter, the function will automatically match the value against the tables primary key.
Example: If 'sql_where' is submitted as an int of '101', the SQL WHERE statement will be "WHERE 'primary_key_column' = 101".

Return Values

Failure:FALSE | An error message will be set if a required table/feature is disabled.

Success:object

Example
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_cart_admin->get_db_reward_points($sql_select, $sql_where)->result();

get_db_reward_point_summary()

Gets a summary of a users reward points stating the number of points that are pending, active, expired, cancelled and that have been converted to vouchers.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
get_db_reward_point_summary(sql_where) Help
Name Data Type Required Default Description
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.
How it Works

The function runs a joined SQL SELECT statement on the 'Reward Points' (pseudo table), 'Reward Points Converted' and 'Order Status' tables.

The function then loops through the results and calculates an totalised summary for the number of reward points that are 'active', 'pending', 'expired', 'converted' and 'cancelled' per user.

  • Total - Total Points earnt from ordered items.
  • Active - Points earnt from ordered items that are marked as shipped; are within their expiry date and that have not been converted.
  • Pending - Points earnt from ordered items that are yet to be marked as shipped.
  • Expired - Points that were not converted to reward vouchers within their expiry date.
  • Converted - Points that have been converted to reward vouchers.
  • Cancelled - Points earnt from ordered items that have been cancelled or returned.

The query can be customised by submitting 'sql_where' data to the functions parameters.

Note that the names of these totalised summary columns are defined via the config file. Read the Summary Pseudo Column documentation for further information on setting aliases via the config file.

Notes

If an int value is submitted to the 'sql_where' parameter, the function will automatically match the value against the user id (NOT the usual primary key).
Example: If 'sql_where' is submitted as an int of '101', the SQL WHERE statement will be "WHERE 'user' = 101".

Return Values

Failure:FALSE | An error message will be set if a required table/feature is disabled.

Success:array

Example
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_where = array(...);

$this->flexi_cart_admin->get_db_reward_point_summary($sql_where);

get_db_converted_reward_points()

Gets records from the converted reward points table.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
get_db_converted_reward_points(sql_select, sql_where) Help
Name Data Type Required Default Description
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.
How it Works

The function runs a joined SQL SELECT statement on the 'Reward Points' (pseudo table), 'Reward Points Converted' and 'Discount' tables.

The returned results are ordered by the date the reward points were earnt (From an order).

The query can be customised by submitting 'sql_select' and 'sql_where' data to the functions parameters.

Notes

This function is compatible with flexi carts 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi cart and CodeIgniter functions that are available.


If an int value is submitted to the 'sql_where' parameter, the function will automatically match the value against the tables primary key.
Example: If 'sql_where' is submitted as an int of '101', the SQL WHERE statement will be "WHERE 'primary_key_column' = 101".

Return Values

Failure:FALSE | An error message will be set if a required table/feature is disabled.

Success:object

Example
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_cart_admin->get_db_converted_reward_points($sql_select, $sql_where)->result();

get_db_voucher()

Gets reward voucher records from the discount table.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
get_db_voucher(sql_select, sql_where) Help
Name Data Type Required Default Description
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.
How it Works

The function runs an SQL SELECT statement on the 'Discounts' table.

By default, the SQL statement is NOT joined to any other discount tables, but can be by using flexi carts 'Query Builder - SQL JOIN' function.

The query can be customised by submitting 'sql_select' and 'sql_where' data to the functions parameters.

Notes

This function is compatible with flexi carts 'Query Builder' functions.


This function can be chained with CodeIgniters query functions 'result()', 'row()' etc.

Read the Query Result documentation for further information on all the combined flexi cart and CodeIgniter functions that are available.


If an int value is submitted to the 'sql_where' parameter, the function will automatically match the value against the tables primary key.
Example: If 'sql_where' is submitted as an int of '101', the SQL WHERE statement will be "WHERE 'primary_key_column' = 101".

Return Values

Failure:FALSE | An error message will be set if a required table/feature is disabled.

Success:object

Example
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_select = array(...);
$sql_where = array(...);

// Example of chaining CI's query function 'result()'.
// Read the Query Result documentation for further information on available functions.
$this->flexi_cart_admin->get_db_voucher($sql_select, $sql_where)->result();

insert_db_voucher()

Inserts a new record to the discounts table.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
insert_db_voucher(user, points_to_convert, code, description, expire_days) Help
Name Data Type Required Default Description
user int Yes FALSE Sets the id of the user that the reward voucher belongs to.
The id has no affect on the functioning of the reward voucher, but is required to relate a voucher to the reward points it was converted from.
points_to_convert int Yes FALSE Sets the number of reward points that are being converted into the reward voucher.
code string | int No FALSE Sets the redeem code of the reward voucher.
description string No FALSE Sets a description of the reward voucher that can be displayed when applied to the cart.
expire_days int No FALSE Set the number of days until the reward voucher expires.
How it Works

The function runs an SQL INSERT statement on the 'Discounts' table, inserting data defined via the functions parameters.

If the 'code' parameter is not set, a random 15 character code is generated.

If the 'description' parameter is not set, a default description of 'Reward Voucher: [code]' will be set.

If the 'expire_days' parameter is not set, the carts default expiry time set via the cart configuration will be set.

Return Values

Failure:FALSE | An error message will be set.

Success:int | id of the inserted record.

Example
$user_id = 201;
$points_to_convert = 500;
$code = 'EXAMPLE-VOUCHER-CODE';
$description = 'Example Voucher Description';
$expire_days = 60;

$this->flexi_cart_admin->insert_db_voucher($user_id, $points_to_convert, $code, $description, $expire_days);

update_db_voucher()

Updates records in the discounts table.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
update_db_voucher(sql_update, sql_where) Help
Name Data Type Required Default Description
sql_update array Yes FALSE Set the SQL UPDATE statement used to update data into the database.
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 update.
Read the defining SQL documentation for further information.
How it Works

The function runs an SQL UPDATE statement on the 'Discounts' table, updating data defined via the 'sql_update' parameter and filtered via the 'sql_where' parameter.

Notes

This function is compatible with flexi carts 'Query Builder' functions.


If an int value is submitted to the 'sql_where' parameter, the function will automatically match the value against the tables primary key.
Example: If 'sql_where' is submitted as an int of '101', the SQL WHERE statement will be "WHERE 'primary_key_column' = 101".

Return Values

Failure:FALSE | An error message will be set if a required table/feature is disabled.

Success:int | The number of affected rows.

Example
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_update = array(...);
$sql_where = array(...);

$this->flexi_cart_admin->update_db_voucher($sql_update, $sql_where);

delete_db_voucher()

Deletes records from the discount table.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
delete_db_voucher(sql_where) Help
Name Data Type Required Default Description
sql_where string | int | array Yes FALSE Set the SQL WHERE statement used to filter the database records to delete.
Read the defining SQL documentation for further information.
How it Works

The function runs an SQL DELETE statement on the 'Discounts' table filtered via the 'sql_where' parameter.

Notes

This function is compatible with flexi carts 'Query Builder' functions.


If an int value is submitted to the 'sql_where' parameter, the function will automatically match the value against the tables primary key.
Example: If 'sql_where' is submitted as an int of '101', the SQL WHERE statement will be "WHERE 'primary_key_column' = 101".

Return Values

Failure:FALSE | An error message will be set if a required table/feature is disabled.

Success:int | The number of affected rows.

Example
// Read the defining SQL documentation for further information on setting SQL statements.
$sql_where = array(...);

$this->flexi_cart_admin->delete_db_voucher($sql_where);

get_reward_point_conversion_tiers()

Returns an array of reward point tiers required to convert points to a voucher.
For example, with 825 points and a conversion ratio of 250 points per voucher, the array would return 250, 500 and 750.
The remaining 75 points would not be able to be converted until another 175 points were earnt.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
get_reward_point_conversion_tiers(reward_points, points_limit) Help
Name Data Type Required Default Description
reward_points int Yes FALSE Defines the number of reward points that are active and available to convert.
points_limit int No FALSE Defines a maximum limit of reward points that can be converted to one voucher.
How it Works

The function uses the reward point to voucher conversion ratio defined via the config settings and calculates the number of tier brackets that could be applied to the submitted 'reward_points' value.

If a 'points_limit' value is set, the 'reward_points' value is capped to that limit.

Return Values

Failure:FALSE

Success:array

Example
// Example #1 : Converting 960 points with no limit set, using a points to voucher ratio of 250.

$reward_points = 960;

$this->flexi_cart_admin->get_reward_point_conversion_tiers($reward_points);

// Produces:
Array
(
 [0] => 250
 [1] => 500
 [2] => 750
)
// Example #2 : Converting 960 points with a points limit of 500, using a points to voucher ratio of 250.

$reward_points = 960;
$points_limit = 500;

$this->flexi_cart_admin->get_reward_point_conversion_tiers($reward_points, $points_limit);

// Produces:
Array
(
 [0] => 250
 [1] => 500
)

calculate_conversion_reward_points()

Rounds a submitted amount of reward points to the maximum number of reward points that can be converted into a voucher.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
calculate_conversion_reward_points(reward_points, points_limit) Help
Name Data Type Required Default Description
reward_points int Yes FALSE Defines the number of reward points that are active and available to convert.
points_limit int No FALSE Defines a maximum limit of reward points that can be converted to one voucher.
How it Works

The function uses the reward point to voucher conversion ratio defined via the config settings and the submitted 'reward_points' value, to calculate the total number of reward points that can be converted.

If a 'points_limit' value is set, the 'reward_points' value is capped to that limit.

Return Values

Failure:int | '0'

Success:int

Example
// Example #1 : Converting 960 points with no limit set, using a points to voucher ratio of 250.

$reward_points = 960;

$this->flexi_cart_admin->calculate_conversion_reward_points($reward_points);

// Produces: '750'
// Example #2 : Converting 960 points with a points limit of 500, using a points to voucher ratio of 250.

$reward_points = 960;
$points_limit = 500;

$this->flexi_cart_admin->calculate_conversion_reward_points($reward_points, $points_limit);

// Produces: '500'

calculate_reward_point_value()

Returns the monetary value of a submitted amount of reward points.


Library and Requirements

Available via the admin library only.

Requires all reward point, discount and order database tables to be enabled.

Function Parameters
calculate_reward_point_value(reward_points) Help
Name Data Type Required Default Description
reward_points int Yes FALSE Defines the number of reward points to calculate the monetary value of.
How it Works

The function uses the reward voucher multiplier value defined via the config settings and the submitted 'reward_points' value, to calculate the monetary value of the reward points if they were converted to a voucher.

Return Values

Failure:int | '0'

Success:int

Example
// Using a reward voucher multipler value of '0.01' per reward point.

$reward_points = 960;

$this->flexi_cart_admin->calculate_reward_point_value($reward_points);

// Produces: '9.60' (Currency value)