User Guide | Setting Tax Session Data

Data is set to the cart session by using functions primarily from flexi carts standard library.

The data that can be set in the cart session includes data of items added to the cart, user localisation data and cart configuration settings.

Since many of flexi carts features can be set using either manually submitted data, or data retrieved from the database; there are often two versions of a function to set session data. Functions that update session data using the database are prefixed with the function name 'update_xxx', whilst functions that use manually set data are prefixed with the name 'set_xxx'.

Set Tax Session Data

Tax Function Index | Tax Config | Get Tax Session Data | Tax Admin Data
Set Tax Data to Session

update_tax() | set_tax()

Set Tax Location Data to Session

update_tax_location()

Help with Setting Session Data 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.

update_tax()

Updates the carts tax rate to match the current tax location.


Library and Requirements

Available via the standard library only.

Requires the tax database table to be enabled.

Function Parameters
update_tax(recalculate_cart) Help
Name Data Type Required Default Description
recalculate_cart bool No TRUE Define if all cart totals must be recalculated on success, regardless of whether the function has determined to do so or not.
The purpose of this is prevent multiple unnecessary recalculations of the cart if this function is used with other cart updating functions.
How it Works

The function will filter all tax rates that match the current tax location, ordering them by the most specific location first, the first tax rate is then applied to the cart session data.

If no tax rate can still be matched, the function will fall back to the default tax rate defined via the database and then the default tax rate values set via the config file.

Notes

This function would not typically need to be called as the tax rate can be set when updating the tax location via the 'update_tax_location()' function.

Return Values

Failure:FALSE | An error message will be set.

Success:TRUE | A status message will be set.

Example
$this->flexi_cart->update_tax();

set_tax()

Manually sets tax data without querying a database table.
The data that can be set is the tax rate and name.


Library and Requirements

Available via the standard library only.

Does not require any database tables to be enabled.

Function Parameters
set_tax(tax_data, recalculate_cart) Help
Name Data Type Required Default Description
tax_data array Yes FALSE The array contains the tax data that is to update the carts tax data.
See the notes and examples below for further information.
recalculate_cart bool No TRUE Define if all cart totals must be recalculated on success, regardless of whether the function has determined to do so or not.
The purpose of this is prevent multiple unnecessary recalculations of the cart if this function is used with other cart updating functions.
How it Works

The function loops through the 'tax_data' array and sets any data from the following array keys to the cart tax data.

The valid array keys are 'rate' and 'name'.

  • 'rate' - The tax rate to apply to the cart. Submitted values must be numeric.
  • 'name' - The name of the tax rate.
Notes

This function can also be set via the 'update_cart()' function.

Return Values

Failure:FALSE | An error message will be set.

Success:TRUE | A status message will be set.

Example
$tax_data = array(
'rate' => 20, // 20% tax
'name' => 'Example Tax Rate'
);

$this->flexi_cart->set_tax($tax_data);