Creating Your Own Shipping Module

From Zen Cart(tm) Wiki
Jump to: navigation, search

This is my experience with creating a Shipping Module called mycourier

To follow the existing structure you should declare all constants in:

\includes\languages\english\modules\shipping\mycourier.php


Make a copy of the Store Pickup module and rename it:

\includes\modules\shipping\mycourier.php


Change the class name to mycourier.


Change the function function storepickup() {

to

function mycourier() {


Redo the mycourier() function to:

function mycourier() {
global $order, $db;

$this->code = 'mycourier';
$this->title = MODULE_SHIPPING_MYCOURIER_TEXT_TITLE;
$this->description = MODULE_SHIPPING_MYCOURIER_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_MYCOURIER_SORT_ORDER;
$this->icon = '';
$this->tax_class = MODULE_SHIPPING_MYCOURIER_TAX_CLASS;
$this->tax_basis = MODULE_SHIPPING_ITEM_MYCOURIER_BASIS;
$this->enabled = ((MODULE_SHIPPING_MYCOURIER_STATUS == 'True') ? true : false);

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_MYCOURIER_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . "
where geo_zone_id = '" . MODULE_SHIPPING_MYCOURIER_ZONE . "'
and zone_country_id = '" . $order->delivery['country']['id'] . "'
order by zone_id");
while (!$check->EOF) {
if ($check->fields['zone_id'] < 1) {
$check_flag = true;
break;
} elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
$check_flag = true;
break;
}
$check->MoveNext();
}

if ($check_flag == false) {
$this->enabled = false;
}
}
}

The $this->code = 'mycourier'; in lowercase is important.


Now in the Quote method you can change:

$mycalc = 1; //set this to the result of your calculation or whatever you want
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_MYCOURIER_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_MYCOURIER_TEXT_WAY,
'cost' => $mycalc)));


And now your module should appear correctly and be useable.

Personal tools