Notice: You are browsing the documentation for PrestaShop 9, which is currently in development.
You might want to read the documentation for the current version, PrestaShop 8. Read the current version of this page
A carrier module is a regular PrestaShop module, except that it extends the CarrierModule class instead of the Module class:
class MyOwnCarrier extends CarrierModule
A carrier module must use the following methods:
getOrderShippingCost()
: to compute the shipping price depending on the ranges that were set in the back office.getOrderShippingCostExternal()
: to compute the shipping price without using the ranges.The getPackageShippingCost()
method can also be used to compute the shipping price depending on the products:
$shipping_cost = $module->getPackageShippingCost($cart, $shipping_cost, $products);
id_carrier
of the new entry is different from the original . If you want to create a module related to a specific carrier, make sure to use the id_reference
field which does not change upon edition. If you need to monitor the changes of the id of this carrier, make sure to read “Controlling the change of the carrier’s ID” section.The module must handle:
Note about deletion:
To control the change of the carrier’s ID (id_carrier), the module must use the actionCarrierUpdate
hook.
For instance:
public function hookActionCarrierUpdate($params)
{
$id_carrier_old = (int) $params['id_carrier'];
$id_carrier_new = (int) $params['carrier']->id;
if ($id_carrier_old === (int) Configuration::get('MYCARRIER_CARRIER_ID')) {
Configuration::updateValue('MYCARRIER_CARRIER_ID', $id_carrier_new);
}
}
To compute the shipping price, PrestaShop needs to call the module’s getOrderShippingCost()
or getOrderShippingCostExternal()
.
The returned value must be a float or false if the carrier is not known or disabled.
For instance:
public function getOrderShippingCost($params, $shipping_cost)
{
if (
$this->id_carrier === (int)(Configuration::get('MYCARRIER_CARRIER_ID'))
&& Configuration::get('MYCARRIER_OVERCOST') > 1
) {
return (float)(Configuration::get('MYCARRIER1_OVERCOST'));
}
return false; // carrier is not known
}