Toll Ipec Shipping by Postcode convert form oscommerce
I am trying to convert the following oscommerce shipping contribution to Zen Cart - "Toll Ipec Shipping by Postcode" for Australia: http://www.oscommerce.com/community/...s,4124/page,11
However I cannot get it to show up in the Shipping Estimator.
This is the code I have modified so far, I have commented the changes:
----------------------------------------------------------------------------------------
<?php
/*
Released under the GNU General Public License
Based on TNT Australia Shipping based on postcode V2 By Jay Bonaretti
Version 3.0 23 March 2006 by Brent Wesley
Converted from oscommerce Version 3.0 above by Brent Wesley for Zencart 03 May 2007 by Debra Morris
*/
class tollzipzones {
var $code, $title, $description, $enabled, $num_zones;
// class constructor:w
function tollzipzones() {
global $db, $order; // added for zencart
$this->code = 'tollzipzones';
$this->title = MODULE_SHIPPING_TOLLZIPZONES_TEXT_TITLE;
$this->description = MODULE_SHIPPING_TOLLZIPZONES_TEXT_DESCRIPTION;
$this->icon = DIR_WS_ICONS . '';
$this->tax_class = MODULE_SHIPPING_TOLLZIPZONES_TAX_CLASS;
$this->enabled = MODULE_SHIPPING_TOLLZIPZONES_STATUS;
$this->sort_order = MODULE_SHIPPING_TOLLZIPZONES_SORT_ORDER;
// Customize this setting for the number of zones needed (no change required by default)
$this->num_zones = 1;
//More options can be added later for Express, Overnight etc when someone codes it.
$this->types = array('Toll Off-Peak' => 'std');
}
// class methods
function quote($method = '') {
global $db, $order, $shipping_weight, $shipping_num_boxes;
// First get the dest zip and check the db for our dest zone
$zip = $order->delivery['postcode'];
if ( $zip == '' ){
// Something is wrong, we didn't find any zone
$this->quotes['error'] = MODULE_SHIPPING_TOLLZIPZONES_NO_ZIPCODE_FOUND;
return $this->quotes;
}
$sql = "SELECT *
FROM toll_zones
WHERE
$zip >= t_postcode and
$zip <= t_postcode";
// $qResult = tep_db_query($sql); // run the query
// $rec = tep_db_fetch_array($qResult); // get the first row of the result
$rec = $db->Execute($sql); // changed for zencart
$zone_id = $rec['t_zone'];
if ( $zone_id == '' ){
// Something is wrong, we didn't find any zone
$this->quotes['error'] = MODULE_SHIPPING_TOLLZIPZONES_NO_ZONE_FOUND;
return $this->quotes;
}
$sql = "SELECT t_rate
FROM toll_rates WHERE t_zone_id = '$zone_id'";
// $qResult = tep_db_query($sql); // oscommerce version
// while ($rec = tep_db_fetch_array($qResult)) {
// $retArr[] = $rec;
// } // oscommerce version
$qResult = $db->Execute($sql); // changed for zencart
while (!$rec->EOF) {
$retArr[] = $rec;
$rec->MoveNext();
} // changed for zencart
foreach($retArr as $aquote){
$cost = $aquote['t_rate'];
}
// Consignment charge insertion start
$sql = "SELECT t_ccharge
FROM toll_rates WHERE t_zone_id = '$zone_id'";
// $qResult = tep_db_query($sql); // oscommerce version
// while ($rec = tep_db_fetch_array($qResult)) { // oscommerce version
// $retArr[] = $rec; // oscommerce version
// }
$qResult = $db->Execute($sql); // changed for zencart
while (!$rec->EOF) { // changed for zencart
$retArr[] = $rec; // changed for zencart
$rec->MoveNext(); // changed for zencart
} // changed for zencart
foreach($retArr as $aquote){
$ccharge = $aquote['t_ccharge'];
// Consignment charge insertion end
}
//calculate the freight charge taking in the min consignment charge
$tmp_charge = (($cost * $shipping_weight + $ccharge) * MODULE_SHIPPING_TOLLZIPZONES_FUEL);
if ($tmp_charge <= MODULE_SHIPPING_TOLLZIPZONES_MINCHARGE) {
$freight_charge = MODULE_SHIPPING_TOLLZIPZONES_MINCHARGE;
} else {
$freight_charge = $tmp_charge;}
$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_TOLLZIPZONES_TEXT_TITLE,
'methods' => array(array('id' => $this_code,
'title' => MODULE_SHIPPING_TOLLZIPZONES_TEXT_DESCRIPTION,
'cost' => $freight_charge + MODULE_SHIPPING_TOLLZIPZONES_HANDLING)));
if ($this->tax_class > 0) {
// $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); //oscommerce version
$this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); // changed for zencart
}
if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_TOLLZIPZONES_INVALID_ZONE;
return $this->quotes;
}
function check() {
global $db; // added for zencart
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TOLLZIPZONES_STATUS'");
// $this->_check = tep_db_num_rows($check_query); //oscommerce version
$this->_check = $check_query->RecordCount(); // changed for zencart
}
return $this->_check;
}
function install() {
global $db; // added for zencart and changed tep_db_query below to $db->Execute
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Enable Toll Postcode Zones Method', 'MODULE_SHIPPING_TOLLZIPZONES_STATUS', '1', 'Do you want to offer Toll postcode/zone rate shipping?', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TOLLZIPZONES_HANDLING', '0', 'Handling Fee for this shipping method', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Fuel Levy', 'MODULE_SHIPPING_TOLLZIPZONES_FUEL', '0', 'Fuel Levey', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Minimum Consignment Charge', 'MODULE_SHIPPING_TOLLZIPZONES_MINCHARGE', '0', 'Minimum Consignment Charge (ex tax)', '6', '0', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_TOLLZIPZONES_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_TOLLZIPZONES_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
}
function remove() {
global $db; // added for zencart
$keys = '';
$keys_array = $this->keys();
for ($i=0; $i<sizeof($keys_array); $i++) {
$keys .= "'" . $keys_array[$i] . "',";
}
$keys = substr($keys, 0, -1);
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
}
function keys() {
$keys = array(
'MODULE_SHIPPING_TOLLZIPZONES_STATUS',
'MODULE_SHIPPING_TOLLZIPZONES_HANDLING',
'MODULE_SHIPPING_TOLLZIPZONES_FUEL',
'MODULE_SHIPPING_TOLLZIPZONES_MINCHARGE',
'MODULE_SHIPPING_TOLLZIPZONES_TAX_CLASS',
'MODULE_SHIPPING_TOLLZIPZONES_SORT_ORDER'
);
return $keys;
}
}
?>
-------------------------------------------------------
Would someone mind checking this to see where the code might need changing. I am not very good at php programming.
I am using Zen Cart 1.3.7
MySQL Version: 4.0.15
PHP Version: 4.3.3 (Zend: 1.3.0)
If I can get this working it could be added to the Downloads/Shipping Modules section.
Cheers
Deb
:frusty: