A carrier module is a regular PrestaShop module, except that it extends the CarrierModule
class instead of the Module
class:
class MyOwnCarrier extends CarrierModule |
It can be attached to the following hooks:
extraCarrier:
to display the shipping price depending on the ranges that were set in the back office.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Ā getOrderShippingCost()
method can also be used to compute the shipping price depending on the products:
$shipping_cost = $module->getPackageShippingCost($cart, $shipping_cost, $products); |
One module can be used to create more than one carrier. |
The module must handle:
Note about deletion:
deleted=true
).To control the change of the carrier's ID (id_carrier), the module must use the updateCarrier
hook.
For instance:
public function hookUpdateCarrier($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 of the float
type.
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 } |