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

Item Stock Function Index | Item Stock Config | Get Item Stock 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.

add_item_stock_quantity()

Adds the submitted stock quantity to the databases item stock table.


Library and Requirements

Available via the admin library only.

Requires the item stock database table to be enabled.

Function Parameters
add_item_stock_quantity(item_id, stock_quantity) Help
Name Data Type Required Default Description
item_id int Yes FALSE Defines the id of the item to be updated.
stock_quantity int Yes 0 Sets the quantity of items to be added to the existing item stock.
How it Works

The function runs an SQL UPDATE statement to add the defined 'stock_quantity' to the current stock level.

Return Values

Failure:FALSE

Success:TRUE

Example
$item_id = 101;
$stock_quantity = 7;

$this->flexi_cart->add_item_stock_quantity($item_id, $stock_quantity);

remove_item_stock_quantity()

Removes the submitted stock quantity from the databases item stock table.


Library and Requirements

Available via the admin library only.

Requires the item shipping database table to be enabled.

Function Parameters
remove_item_stock_quantity(item_id, stock_quantity) Help
Name Data Type Required Default Description
item_id int Yes FALSE Defines the id of the item to be updated.
stock_quantity int Yes 0 Sets the quantity of items to be removed to the existing item stock.
How it Works

The function runs an SQL UPDATE statement to remove the defined 'stock_quantity' from the current stock level.

Return Values

Failure:FALSE

Success:TRUE

Example
$item_id = 101;
$stock_quantity = 7;

$this->flexi_cart->remove_item_stock_quantity($item_id, $stock_quantity);

get_db_item_stock()

Gets records from the item stock table.


Library and Requirements

Available via the admin library only.

Requires the item shipping database table to be enabled.

Function Parameters
get_db_item_stock(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 'Item Stock' table.

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.

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

insert_db_item_stock()

Inserts a new record to the item stock table.


Library and Requirements

Available via the admin library only.

Requires the item shipping database table to be enabled.

Function Parameters
insert_db_item_stock(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 'Item Stock' 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_item_stock($sql_insert);

update_db_item_stock()

Updates records in the item stock table.


Library and Requirements

Available via the admin library only.

Requires the item shipping database table to be enabled.

Function Parameters
update_db_item_stock(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 'Item Stock' 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_item_stock($sql_update, $sql_where);

delete_db_item_stock()

Deletes records from the item stock table.


Library and Requirements

Available via the admin library only.

Requires the item shipping database table to be enabled.

Function Parameters
delete_db_item_stock(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 'Item Stock' 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_item_stock($sql_where);