User Guide | Admin Discount 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 Discount Functions

Discount Function Index | Discount Config | Get Discount Session Data | Get Discount Helper Data | Set Discount Session 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.

check_code_available()

Validates whether a discount/voucher code already exists in the database.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
check_code_available(code, omit_discount_id) Help
Name Data Type Required Default Description
code string | int Yes FALSE Defines the order number to be checked.
omit_discount_id int No FALSE Defines the id of a discount that should not be checked.
The purpose of this parameter is so that if updating an existing discount, the query does not match its own row, which would falsely indicate the code already existed in another discount.
How it Works

The function runs an SQL query on the 'Discounts' table looking for any discounts or vouchers with the same code.

If updating an existing discount, the table row id of the to-be-updated discount can be filtered out of the SQL query to prevent the function matching the discounts own code.

Return Values

Unavailable:FALSE

Available:TRUE

Example
	$code = 'example_discount_code';

	$omit_discount_id = 101;

	$this->flexi_cart->check_code_available($code, $omit_discount_id);
	

add_discount_usage()

Adds the submitted usage quantity to the discount tables usage column.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
add_discount_usage(discount_id, usage_quantity) Help
Name Data Type Required Default Description
discount_id int Yes FALSE Defines the id of the discount to be updated.
usage_quantity int Yes 0 Sets the quantity of usages to be added to the existing discount usage limit.
How it Works

The function runs an SQL UPDATE statement to add the defined 'usage_quantity' to the current usage limit.

Return Values

Failure:FALSE

Success:TRUE

Example
	$discount_id = 101;
	$usage_quantity = 7;

	$this->flexi_cart->add_discount_usage($discount_id, $usage_quantity);
	

remove_discount_usage()

Removes the submitted usage quantity from the discount tables usage column.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
remove_discount_usage(discount_id, usage_quantity) Help
Name Data Type Required Default Description
discount_id int Yes FALSE Defines the id of the discount to be updated.
usage_quantity int Yes 0 Sets the quantity of usages to be removed to the existing discount usage limit.
How it Works

The function runs an SQL UPDATE statement to remove the defined 'usage_quantity' from the current usage limit.

Return Values

Failure:FALSE

Success:TRUE

Example
	$discount_id = 101;
	$usage_quantity = 7;

	$this->flexi_cart->remove_discount_usage($discount_id, $usage_quantity);
	

check_item_in_discount_group()

Looks-up the discount group item table to check if an item id already exists within a specific discount group.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
check_item_in_discount_group(group, item) Help
Name Data Type Required Default Description
group int Yes FALSE Defines the group id to be checked.
item int Yes FALSE Defines the item id to be checked.
How it Works

The function runs an SQL SELECT statement on the 'Discount Group Items' table, and checks if the 'item' exists in the defined discount group.

Return Values

Not in Group:FALSE

In Group:TRUE

Example
	$group_id = 4;
	$item_id = 101;

	$this->flexi_cart->check_item_in_discount_group($group_id, $item_id);
	

get_db_discount()

Gets records from the discount table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
get_db_discount(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, filtering out any reward voucher records.

By default, the SQL statement is NOT joined to any of the 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_discount($sql_select, $sql_where)->result();
	

insert_db_discount()

Inserts a new record into the discount table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
insert_db_discount(sql_insert) Help
Name Data Type Required Default Description
sql_insert array Yes FALSE Set the SQL INSERT statement used to insert data into the database.
Read the defining SQL documentation for further information.
How it Works

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

Return Values

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

Success:int | id of the inserted record.

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

	$this->flexi_cart_admin->insert_db_discount($sql_insert);
	

update_db_discount()

Updates records in the discount table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
update_db_discount(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_discount($sql_update, $sql_where);
	

delete_db_discount()

Deletes records from the discount table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
delete_db_discount(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_discount($sql_where);
	

get_db_discount_group()

Gets records from the discount group table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
get_db_discount_group(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 'Discount Groups' table.

By default, the SQL statement is NOT joined to any of the 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_discount_group($sql_select, $sql_where)->result();
	

insert_db_discount_group()

Inserts a new record to the discount group table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
insert_db_discount_group(sql_insert) Help
Name Data Type Required Default Description
sql_insert array Yes FALSE Set the SQL INSERT statement used to insert data into the database.
Read the defining SQL documentation for further information.
How it Works

The function runs an SQL INSERT statement on the 'Discount Groups' table, inserting data defined via the 'sql_insert' parameter.

Return Values

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

Success:int | id of the inserted record.

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

	$this->flexi_cart_admin->insert_db_discount_group($sql_insert);
	

update_db_discount_group()

Updates records in the discount group table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
update_db_discount_group(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 'Discount Groups' 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_discount_group($sql_update, $sql_where);
	

delete_db_discount_group()

Deletes records from the discount group table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
delete_db_discount_group(sql_where, delete_children) 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.
delete_children string No FALSE Define whether to also delete all related discount group item records.
As a precaution, 'delete' must be submitted to delete child records.
How it Works

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

If the 'delete_children' parameter is set, then all related records from the 'Discount Group Items' table will also be deleted.

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_discount_group($sql_where);
	

get_db_discount_group_item()

Gets records from the discount group items table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
get_db_discount_group_item(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 'Discount Group Items' table.

By default, the SQL statement is NOT joined to any of the 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_discount_group_item($sql_select, $sql_where)->result();
	

insert_db_discount_group_item()

Inserts a new record to the discount group item table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
insert_db_discount_group_item(sql_insert) Help
Name Data Type Required Default Description
sql_insert array Yes FALSE Set the SQL INSERT statement used to insert data into the database.
Read the defining SQL documentation for further information.
How it Works

The function checks that the 'sql_insert' data contains a 'group' and an 'item' array key and then runs an SQL query to check if the item already exists within the discount group.

If no match is found, the function runs an SQL INSERT statement on the 'Discount Group Items' table, inserting data defined via the 'sql_insert' parameter.

Return Values

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

Success:int | id of the inserted record.

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

	$this->flexi_cart_admin->insert_db_discount_group_item($sql_insert);
	

update_db_discount_group_item()

Updates records in the discount group item table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
update_db_discount_group_item(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 'Discount Group Items' 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_discount_group_item($sql_update, $sql_where);
	

delete_db_discount_group_item()

Deletes records from the discount group item table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
delete_db_discount_group_item(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 'Discount Group Items' 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_discount_group_item($sql_where);
	

get_db_discount_type()

Gets records from the discount type table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
get_db_discount_type(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 'Discount Types' table.

By default, the SQL statement is NOT joined to any of the 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_discount_type($sql_select, $sql_where)->result();
	

get_db_discount_method()

Gets records from the discount method table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
get_db_discount_method(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 'Discount Methods' table.

By default, the SQL statement is NOT joined to any of the 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_discount_method($sql_select, $sql_where)->result();
	

get_db_discount_tax_method()

Gets records from the discount tax method table.


Library and Requirements

Available via the admin library only.

Requires all discount database tables to be enabled.

Function Parameters
get_db_discount_tax_method(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 'Discount Tax Methods' table.

By default, the SQL statement is NOT joined to any of the 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

Read the discount tax method config documentation for further information on the types of tax methods that can be applied to discounts.


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_discount_tax_method($sql_select, $sql_where)->result();