Admin Cart Data Functions
Cart Data Function Index |
Cart Data Config
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_cart_data()
Gets records from the cart data table.
Library and Requirements
Available via the admin library only.
Requires the cart data database table to be enabled.
Function Parameters
get_db_cart_data(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 'Cart Data' table.
The query can be customised by submitting 'sql_select' and 'sql_where' data to the functions parameters.
Notes
Note: The cart data will be returned as a serialized string, to convert the string back to an array, use the standard PHP function 'unserialize()'.
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
$sql_select = array(...);
$sql_where = array(...);
$this->flexi_cart_admin->get_db_cart_data($sql_select, $sql_where)->result();
unserialize_cart_data()
Returns an unserialized cart data array from the cart data table.
Library and Requirements
Available via the admin library only.
Requires the cart data database table to be enabled.
Function Parameters
unserialize_cart_data(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 return.
Read the defining SQL documentation for further information.
|
How it Works
The function runs an SQL SELECT statement on the 'Cart Data' table.
The function then uses PHP's standard 'unserialize()' function to convert the cart data from a string, back into an array.
The query can be customised by submitting 'sql_where' data to the functions parameters.
Notes
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
Success:array
Example
$sql_where = array(...);
$this->flexi_cart_admin->unserialize_cart_data($sql_where);
save_cart_data()
Saves a carbon copy of the users current cart data array to the database.
Library and Requirements
Available via the admin library only.
Requires the cart data database table to be enabled.
Function Parameters
save_cart_data(user, set_readonly_status, sql_update, force_overwrite)
Help
Name |
Data Type |
Required |
Default |
Description |
user |
int |
No |
0 |
Defines the id of the user that is saving the cart.
Relating the cart data to a user means that the data can be filtered by user for other SQL SELECT queries.
|
set_readonly_status |
bool |
No |
FALSE |
Sets whether the cart data is from a completed order.
If set as TRUE, the cart data cannot be later overwritten unless the 'force_overwrite' parameter is set.
|
sql_update |
array |
No |
FALSE |
Set the SQL UPDATE statement used to set additional data to the database.
Read the defining SQL documentation for further information.
|
force_overwrite |
bool |
No |
FALSE |
Sets whether the cart data can be resaved over the existing cart data of a completed order. |
How it Works
The function first checks whether the current cart session data was originally loaded from the 'Cart Data' table.
If the cart data has not already been saved, it inserts a new row to the table, and updates the current cart session data with the id.
The function then serializes the carts session data and runs an SQL UPDATE statement to update the existing/newly inserted table record.
If the 'set_readonly_status' value has been set, the function will set the cart data as being related to a completed order. As a precaution to prevent order data being overwritten, it is then only possible to re-update the record if 'force_overwrite' is set.
The SQL UPDATE query can be customised by submitting 'sql_update' data to the functions parameters.
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
$user_id = 201;
$set_readonly_status = FALSE;
$sql_update = array(...);
$force_overwrite = FALSE
$this->flexi_cart_admin->save_cart_data($user_id, $set_readonly_status, $sql_update, $force_overwrite);
load_cart_data()
Loads a saved cart data array from the database.
The data is then used to update the users current cart data array with the saved/submitted data.
Library and Requirements
Available via the admin library only.
Requires the cart data database table to be enabled.
Function Parameters
load_cart_data(sql_where, set_admin_data, reset_locations, reset_discounts, reset_surcharges)
Help
Name |
Data Type |
Required |
Default |
Description |
sql_where |
string | int | array |
Yes |
FALSE |
Set the SQL WHERE statement used to filter the database record to return.
Read the defining SQL documentation for further information.
|
set_admin_data |
bool |
No |
FALSE |
Define whether to load the cart data and store specific data in the current cart session data as 'admin data'.
Read the 'admin data' documentation for further information.
|
reset_locations |
bool |
No |
FALSE |
Defines whether the cart should reset the loaded cart data back to the default location. |
reset_discounts |
bool |
No |
FALSE |
Defines whether the cart should remove any discount or reward voucher codes from the loaded cart data. |
reset_surcharges |
bool |
No |
FALSE |
Defines whether the cart should remove any surcharges from the loaded cart data. |
How it Works
The function runs an SQL query on the 'Cart Data' table, filtered via the 'sql_where' parameter. The returned cart data is then unserialized from a string, into an array.
If the 'set_admin_data' parameter has been set, then the function will set specific item and discount data as 'admin data', that can then be used internally by the cart when re-saving a previously saved order.
The function then checks through the rest of the saved data for cart items, locations, discounts, reward vouchers and surcharges. If the 'reset_locations', 'reset_discounts' and 'reset_surcharges' parameters permit, the data is then copied to the current cart data.
Lastly, the function then runs the 'update_shipping()' and 'update_tax()' functions to ensure current shipping and tax rates are used.
Notes
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
Success:TRUE
Example
$sql_where = array(...);
$this->flexi_cart_admin->load_cart_data($sql_where);
delete_db_cart_data()
Deletes cart data from the database.
Library and Requirements
Available via the admin library only.
Requires the cart data database table to be enabled.
Function Parameters
delete_db_cart_data(sql_where, force_delete)
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.
|
force_delete |
bool |
No |
FALSE |
Defines whether to delete cart data that is related to a completed order. |
How it Works
The function runs an SQL SELECT query on the 'Cart Data' table, filtered via the 'sql_where' parameter to get the id's of all records that are to be deleted.
If the current cart session data has a matching cart data id, then the sessions cart data id is reset, to ensure if it is later resaved, that it is issued a new row id.
The function runs an SQL DELETE statement on the 'Cart Data' table filtered via the 'sql_where' parameter.
As a precaution, unless the 'force_delete' parameter is set, no records related to saved orders can be deleted.
Notes
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.
Success:TRUE | A status message will be set.
Example
$sql_where = array(...);
$this->flexi_cart_admin->delete_db_cart_data($sql_where);