Set Shipping Session Data
Shipping Function Index |
Shipping Config |
Get Shipping Session Data |
Get Shipping Helper Data |
Shipping Admin Data
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_shipping()
Looks-up the shipping database table and tries to match shipping rate options with the current shipping id and shipping location.
Library and Requirements
Available via the standard library only.
Requires the shipping database tables to be enabled.
Function Parameters
update_shipping(shipping_id, location, recalculate_cart)
Help
Name |
Data Type |
Required |
Default |
Description |
shipping_id |
int |
No |
FALSE |
The shipping option id that the cart will use to try and to match a suitable shipping rate tier against the current cart totals. |
location |
string | int | array |
No |
FALSE |
Can be either a string, int, or an array of values matching either the id or name of locations in the location table.
The data will be used to update the carts current shipping location.
|
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
If location data is submitted, the function will first update the carts current shipping location.
The function will then filter the shipping id against all shipping options that match the current shipping location, ordering them by the most specific location first.
On success, it will then check the current weight and total value of the cart against the shipping rate tiers, when a match is found, the shipping rate is applied to the cart.
If no shipping rates can be found, the function will disregard the shipping id and apply the first shipping option that matches the current location and cart weight and value.
If no shipping option can still be matched, the function will fall back to the default shipping option defined via the database and then the default shipping values set via the config file.
Notes
If setting location data as a location name, ensure the value is of a string data type.
If a location name is numeric, like a zip code, the function may confuse the zip code as a location id.
This can be prevented by type casting the location name like this (string)'10101'
, see the example section below.
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.
Examples
$shipping_id = $this->input->post('shipping_id');
$this->flexi_cart->update_shipping($shipping_id);
$shipping_id = $this->input->post('shipping_id');
$location_data = 'New York';
$this->flexi_cart->update_shipping($shipping_id, $location_data);
$shipping_id = $this->input->post('shipping_id');
$location_data = array(
'New York',
(string)'10101',
10
);
$this->flexi_cart->update_shipping($shipping_id, $location_data);
set_shipping()
Manually sets shipping data without querying a database table.
Library and Requirements
Available via the standard library only.
Does not require any database tables to be enabled.
Function Parameters
set_shipping(shipping_data, recalculate_cart)
Help
Name |
Data Type |
Required |
Default |
Description |
shipping_data |
array |
Yes |
FALSE |
The array contains the data that is to update the carts shipping data.
See the documentation 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 'shipping_data' array and sets any data from the following array keys to the cart shipping data.
The valid array keys are 'id', 'value', 'tax_rate' 'name' and 'description'.
- 'id' - The id to reference the shipping option by when updating shipping.
- 'value' - The value of the shipping option. Submitted values must be numeric.
- 'tax_rate' - Tax rate applied to the shipping rate, the carts tax value is used if no value is submitted. Submitted values must be numeric.
- 'name' - The name of the shipping option.
- 'description' - The description of the shipping option.
Notes
Return Values
Failure:FALSE | An error message will be set.
Success:TRUE | A status message will be set.
Example
$shipping_data = array(
'id' => 'example_id',
'value' => 4.95,
'tax_rate' => 20,
'name' => 'Example Shipping Option',
'description' => 'Example Description'
);
$this->flexi_cart->set_shipping($shipping_data);