Shipment
in package
Useful methods to handle everything related to shipments
Tags
Table of Contents
Constants
- TEXT_NAME = 'shipper_name'
- Text keys
Properties
- $arrShipments : array<string|int, mixed>
- Array of active shipment conditions
- $arrShippers : array<string|int, mixed>
- Array of active shippers
Methods
- add_shipments() : bool
- Adds new shipment conditions
- add_shipper() : bool
- Adds a new shipper
- calculateShipmentPrice() : float
- Calculate the shipment price for the given Shipper ID, order price and total weight.
- delete_shipment() : bool
- Deletes the Shipment with its ID present in $_GET['delete_shipment_id'], if any
- delete_shipper() : bool
- Deletes the Shipper with its ID present in $_GET['delete_shipper_id'], if any
- errorHandler() : bool
- Handles database errors
- getCountries() : array<string|int, mixed>
- Fetch data of countries that are available as shipping target
- getCountriesRelatedShippingIdArray() : array<string|int, mixed>
- Returns an array of shipper ids relevant for the country specified by the argument $countryId.
- getCountryMenu() : string
- Get shipping country select dropdown menu
- getCountryMenuOptions() : string
- Get shippping country select dropdown options
- getJSArrays() : string
- Returns the shipment arrays (shippers and shipment costs) in JavaScript syntax.
- getNameById() : mixed
- Get the shipper name for the ID given
- getShipmentConditions() : array<string|int, mixed>
- Returns an array containing all the active shipment conditions.
- getShipmentsArray() : array<string|int, mixed>
- Access method. Returns the arrShipments array.
- getShipperMenu() : string
- Returns the shipper dropdown menu string.
- getShipperName() : string
- Returns the name of the shipper with the given ID
- getShippersArray() : array<string|int, mixed>
- Access method. Returns the arrShippers array.
- init() : void
- Initialize shippers and shipment conditions
- reset() : mixed
- Clears the Shippers and Shipments stored in the class
- update_shipments_from_post() : bool
- Updates shippers and shipments that have been changed in the form
- _add_shipper() : int
- Adds a Shipper to the database
- _add_shipment() : bool
- Adds a Shipment entry to the database
- _delete_shipment() : bool
- Deletes a Shipment entry from the database
- _delete_shipper() : bool
- Deletes a Shipper from the database
- _rename_shipper() : bool
- Update the Shipper name in the current frontend language
- _update_shipment() : bool
- Update a Shipment entry
- _update_shipper() : bool
- Update the Shipper active status
Constants
TEXT_NAME
Text keys
public
mixed
TEXT_NAME
= 'shipper_name'
Properties
$arrShipments
Array of active shipment conditions
private
static array<string|int, mixed>
$arrShipments
= null
Tags
$arrShippers
Array of active shippers
private
static array<string|int, mixed>
$arrShippers
= null
Tags
Methods
add_shipments()
Adds new shipment conditions
public
static add_shipments() : bool
Backend use only.
Tags
Return values
bool —True on success, false on failure, or null on noop
add_shipper()
Adds a new shipper
public
static add_shipper([int $localeId = 0 ]) : bool
Backend use only.
Parameters
- $localeId : int = 0
-
Optional locale ID.
Tags
Return values
bool —True on success, false on failure, or null on noop
calculateShipmentPrice()
Calculate the shipment price for the given Shipper ID, order price and total weight.
public
static calculateShipmentPrice(int $shipperId, float $price, int $weight) : float
Returns the shipment price in default currency, or -1 if there is any kind of problem with the shipment conditions. The weight is converted from string using to make sure that grams are used. Note: You have to convert the returned value to the customers' currency using !
Parameters
- $shipperId : int
-
The Shipper ID
- $price : float
-
The total order price
- $weight : int
-
The total order weight in grams.
Tags
Return values
float —The cost for shipping in the default currency, or -1.
delete_shipment()
Deletes the Shipment with its ID present in $_GET['delete_shipment_id'], if any
public
static delete_shipment() : bool
Tags
Return values
bool —True on success, false on failure, or null on noop
delete_shipper()
Deletes the Shipper with its ID present in $_GET['delete_shipper_id'], if any
public
static delete_shipper() : bool
Return values
bool —True on success, false on failure, or null on noop
errorHandler()
Handles database errors
public
static errorHandler() : bool
Also migrates old names to the new structure
Tags
Return values
bool —False. Always.
getCountries()
Fetch data of countries that are available as shipping target
public
static getCountries() : array<string|int, mixed>
Return values
array<string|int, mixed> —List of countries fetched from \Cx\Core\Country\Controller\Country::getData() and filtered by available countries for shipping.
getCountriesRelatedShippingIdArray()
Returns an array of shipper ids relevant for the country specified by the argument $countryId.
public
static getCountriesRelatedShippingIdArray([int $countryId = 0 ]) : array<string|int, mixed>
Parameters
- $countryId : int = 0
-
The optional country ID
Tags
Return values
array<string|int, mixed> —Array of shipment IDs on success, false otherwise
getCountryMenu()
Get shipping country select dropdown menu
public
static getCountryMenu([string $menuName = 'countryId' ][, int $selected = 0 ][, string $onchange = '' ]) : string
Parameters
- $menuName : string = 'countryId'
-
Name of the select menu
- $selected : int = 0
-
Selected option
- $onchange : string = ''
-
Javascript on change callback function
Return values
string —Select Menu
getCountryMenuOptions()
Get shippping country select dropdown options
public
static getCountryMenuOptions([int $selected = 0 ]) : string
Parameters
- $selected : int = 0
-
Selected option
Return values
string —Select options
getJSArrays()
Returns the shipment arrays (shippers and shipment costs) in JavaScript syntax.
public
static getJSArrays() : string
Backend use only.
Tags
Return values
string —The Shipment arrays definition
getNameById()
Get the shipper name for the ID given
public
static getNameById(int $shipperId) : mixed
Parameters
- $shipperId : int
-
The shipper ID
Tags
Return values
mixed —The shipper name on success, false otherwise
getShipmentConditions()
Returns an array containing all the active shipment conditions.
public
static getShipmentConditions() : array<string|int, mixed>
The array has the form array( Shipper name => array( 'countries' => array( country ID => Country name, [...] ), 'conditions' => array( Maximum weight => array( 'max_weight' => maximum weight (formatted, or "unlimited"), 'free_from' => no charge lower limit (amount), 'fee' => shipping fee (amount), ), [... more ...] ), ), [... more ...] ) Countries are ordered by ascending names. Conditions are ordered by ascending maximum weight.
Tags
Return values
array<string|int, mixed> —Countries and conditions array on success, false otherwise
getShipmentsArray()
Access method. Returns the arrShipments array.
public
static getShipmentsArray() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —The array of shipments
getShipperMenu()
Returns the shipper dropdown menu string.
public
static getShipperMenu([mixed $countryId = 0 ][, string $selectedId = 0 ][, string $onchange = "" ]) : string
For the admin zone (order edit page), you MUST specify $onchange, so that both the onchange call and the
Parameters
- $countryId : mixed = 0
- $selectedId : string = 0
-
Optional preselected shipment ID
- $onchange : string = ""
-
Optional onchange javascript callback
Tags
Return values
string —Dropdown menu string
getShipperName()
Returns the name of the shipper with the given ID
public
static getShipperName(int $shipperId) : string
Parameters
- $shipperId : int
-
The shipper ID
Tags
Return values
string —The shipper name
getShippersArray()
Access method. Returns the arrShippers array.
public
static getShippersArray([bool $all = false ]) : array<string|int, mixed>
Parameters
- $all : bool = false
-
Include inactive Shippers if true. Defaults to false.
Tags
Return values
array<string|int, mixed> —The array of shippers
init()
Initialize shippers and shipment conditions
public
static init([bool $all = false ][, int $localeId = 0 ]) : void
Use $all=true for the backend settings. Reads the shipping options from the shipper (s) and shipment_cost (c) tables. For each shipper, creates array entries like: arrShippers[s.id] = array ( name => s.name, status => s.status ) arrShipments[s.id][c.id] = array ( max_weight => c.max_weight, free_from => c.free_from, fee => c.fee ) Note that the table module_shop_shipment has been replaced by module_shop_shipper (id, name, status) and module_shop_shipment_cost (id, shipper_id, max_weight, fee, free_from) as of version 1.1.
Parameters
- $all : bool = false
-
If true, includes inactive records. Defaults to false.
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
reset()
Clears the Shippers and Shipments stored in the class
public
static reset() : mixed
Call this after updating the database. The data will be reinitialized on demand.
update_shipments_from_post()
Updates shippers and shipments that have been changed in the form
public
static update_shipments_from_post([int $localeId = 0 ]) : bool
Backend use only.
Parameters
- $localeId : int = 0
-
Optional locale ID
Tags
Return values
bool —True on success, false an failure, null on noop.
_add_shipper()
Adds a Shipper to the database
protected
static _add_shipper(string $name[, bool $active = false ][, int $localeId = 0 ]) : int
Parameters
- $name : string
-
The Shipper name
- $active : bool = false
-
If true, the Shipper is made active. Defaults to false
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
Return values
int —The ID of the new Shipper on success, false otherwise
_add_shipment()
Adds a Shipment entry to the database
private
static _add_shipment(int $shipper_id, float $fee, float $free_from, int $max_weight) : bool
Parameters
- $shipper_id : int
-
The associated Shipper ID
- $fee : float
-
The fee for delivery
- $free_from : float
-
The minimum order value to get a free delivery
- $max_weight : int
-
The maximum weight of the delivery
Tags
Return values
bool —True on success, false otherwise
_delete_shipment()
Deletes a Shipment entry from the database
private
static _delete_shipment(int $shipment_id) : bool
Parameters
- $shipment_id : int
-
The Shipment ID
Tags
Return values
bool —True on success, false otherwise
_delete_shipper()
Deletes a Shipper from the database
private
static _delete_shipper(int $shipper_id) : bool
Deletes related Text, shipment cost, and zone relation records as well.
Parameters
- $shipper_id : int
-
The Shipper ID
Tags
Return values
bool —True on success, false on failure, null on noop.
_rename_shipper()
Update the Shipper name in the current frontend language
private
static _rename_shipper(mixed $shipper_id, string $name[, int $localeId = 0 ]) : bool
Parameters
- $shipper_id : mixed
- $name : string
-
The new Shipper name
- $localeId : int = 0
-
Optional locale ID. If not set FRONTEND_LANG_ID will be used.
Tags
Return values
bool —True on success, false otherwise
_update_shipment()
Update a Shipment entry
private
static _update_shipment(int $shipment_id, int $shipper_id, float $fee, float $free_from, int $max_weight) : bool
Parameters
- $shipment_id : int
-
The Shipment ID
- $shipper_id : int
-
The associated Shipper ID
- $fee : float
-
The fee for delivery
- $free_from : float
-
The minimum order value to get a free delivery
- $max_weight : int
-
The maximum weight of the delivery
Tags
Return values
bool —True on success, false otherwise
_update_shipper()
Update the Shipper active status
private
static _update_shipper(mixed $shipper_id[, bool $active = false ]) : bool
Parameters
- $shipper_id : mixed
- $active : bool = false
-
If true, the Shipper is made active. Defaults to false
Tags
Return values
bool —True on success, false otherwise