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

Order Helper Functions

Order Function Index | Order Config | Set Order Session Data | Order Admin Data
Order Number Helper Functions

generate_order_number() | check_order_number_available()

Email Order

email_order()

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.

generate_order_number()

Generates an order number.


Library and Requirements

Available via the admin library only.

Requires all order database tables to be enabled.

Function Parameters
generate_order_number(prefix, suffix) Help
Name Data Type Required Default Description
prefix string | int No FALSE Sets a value that is prefixed to the start of the generated order number.
suffix string | int No FALSE Sets a value that is suffixed to the end of the generated order number.
How it Works

The function checks whether to generate a random order number or to increment the order number from the last saved order.

If the order number is to be incremented, the functions calls a SQL query to retrieve the last saved order number and increments the number by one, including any defined 'prefix' or 'suffix'.

If a random number is to be generated, the function generates a number between 00000001-99999999, includes any defined 'prefix' or 'suffix', and checks the order number does not already exist in the order table.

The order number is then saved to the cart session data and returned from the function.

Return Values

Failure:FALSE

Success:string | Generated order number.

Example
$prefix = 'XY';
$suffix = 'YZ';

$this->flexi_cart_admin->generate_order_number($prefix, $suffix);

// Could Produce: 'XY00000001YZ'

check_order_number_available()

Checks whether an order has already been saved with the submitted order number.


Library and Requirements

Available via the admin library only.

Requires all order database tables to be enabled.

Function Parameters
check_order_number_available(order_number) Help
Name Data Type Required Default Description
order_number string | int No FALSE Defines the order number to be checked.
How it Works

The function runs an SQL SELECT statement on the 'Order Summary' table, filtered by the 'order_number' value.

The function then returns a boolean value on whether the order number already exists.

Return Values

Unavailable:FALSE

Available:TRUE

Example
$order_number = '00000001';

$this->flexi_cart_admin->check_order_number_available($order_number);

email_order()

Sends an email populated with data from a saved cart order using the flexi cart email template.


Library and Requirements

Available via the admin library only.

Requires all order database tables to be enabled.

Function Parameters
email_order(order_number, email_to, email_subject, custom_data) Help
Name Data Type Required Default Description
order_number string | int Yes FALSE Defines the unique order number of the order to get data from.
email_to string | array Yes FALSE Sets the email address of the email recipient
Multiple recipients can be set by setting the email addresses in an array.
email_subject string No FALSE Sets the emails subject title. If not set, a default title is set.
See the notes below for further information.
custom_data string | int | array No FALSE Sets additional data that will be accessible from the email template file.
See the notes below for further information.
How it Works

The function runs an SQL SELECT statement on the 'Order Summary' table, filtered by the 'order_number' value.

If the order is returned, the function then runs another SQL query to return all itemised details of the order and creates an array containing data from the order summary table, the order detail table and from the 'custom_data' data.

The email is then sent using the email template and settings defined via the config file, to all recipients defined via the 'email_to' parameter.

Notes

The variables that are accessible via the email template file will be set in three different arrays.

  • $summary_data : Contains all columns from the order summary table.
  • $item_data : Contains all columns from the order details table.
  • $custom_data : Contains any data defined via the functions 'custom_data' parameter. Only available if 'custom_data' parameter is set.

If an email subject is not defined, the email will be titled with the 'site_title' defined via the config file, and append the words ' : Order Details'.
Example: If $config['email']['site_title'] = 'flexi cart' (See config file), the email title would be 'flexi cart : Order Details'.

Return Values

Failure:FALSE | An error message will be set.

Success:TRUE | A status message will be set.

Examples
// Example of sending an email of a saved order.

$order_number = 'example_order_number';

// The email recipient(s) can either be set as a string, or as an array like below.
$email_to = array(
'example_1@recipient_email.com',
'example_2@recipient_email.com'
);

$email_subject = 'Example Email Subject Title';

// Example of defining custom data to be available in the email.
$custom_data = array(
'example_data_1' => 'example_data_1_value',
'example_data_2' => 'example_data_2_value'
);

$this->flexi_cart_admin->email_order($order_number, $email_to, $email_subject, $custom_data);
// Example of calling variables available via the email template file (Using default table column names).

<h1> Order Number : <?php echo $summary_data["ord_order_number"];?> </h1>

<ul>
<?php foreach( $item_data as $row ) { ?>
<li>
	<?php echo $row["ord_det_item_name"]." @ ".$row["ord_det_price"]; ?>
</li>
<?php } ?>
</ul>

<p> <?php echo $custom_data["custom_data"]; ?> </p>