Help needed for this shipping module, don't show shipping rate. I think this db query is wrong place or something is missing.
If I put query module after
"function quote($method = '') {
global $order;
I get price put not the query result to the drop down menu?

Thank you for help.


Demo shop: http://www.muisti.16mb.com/

Ouery Module
$places = array();

if (MODULE_SHIPPING_SMARTPOST_SHOW_LOCAL == "True") {
$places = $this->_quote($order->delivery['state'], $order->delivery['city']);
} else {
$places = $this->_quote();
}

$resultStr = "";
$resultStr .= '</label><select name="locker" id="locker" style="width: 500px;" onmousemove="if (document.getElementById(\''.$this->code.'_smartpost_begin\') != null) { document.getElementById(\''.$this->code.'_smartpost_begin\').style.display = \'none\';document.getElementById(\''.$this->code.'_smartpost_begin\').nextSibling.style.display = \'none\';}" onclick="this.parentNode.parentNode.getElementsByTagName(\'input\')[0].checked = true;this.parentNode.parentNode.getElementsByTagName(\'input\')[0].value = document.getElementById(\'locker\').value;" onchange="this.parentNode.parentNode.getElementsByTagName(\'input\')[0].checked = true;this.parentNode.parentNode.getElementsByTagName(\'input\')[0].value = document.getElementById(\'locker\').value;">';
foreach ($places as $place) {
$resultStr .= "<option value='"."".$this->code."_".$place['id']."'>".$place['title']."</option>\r\n";
}
$resultStr .= "</select>";
$resultStr .= "<label> &nbsp;&nbsp;&nbsp; ";
$resultStr .= '<script type="text/javascript">window.onload = function() {var v = document.getElementById(\'locker\').parentNode.parentNode.nextSibling; while(v && v.nodeType != 1) {v = v.nextSibling;} v.style.display = \'none\';document.getElementById(\'locker\').parentNode.parentNode.getElementsBy TagName(\'input\')[0].value = document.getElementById(\'locker\').value;};</script>';


$this->quotes['methods'] = array(
array(
'id' => $this->code,
'title' => $resultStr,
'cost' => $this->cost));


Smartpost Shipping module for Estonia

<?php
/**
* @package shippingMethod
* @copyright Copyright 2003-2009 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*/
// $Id: smartpost.php
//

class smartpost {
var $code, $title, $description, $icon, $enabled;

// class constructor
function smartpost() {
global $order, $db;

$this->code = 'smartpost';
$this->title = MODULE_SHIPPING_SMARTPOST_TEXT_TITLE;
$this->description = MODULE_SHIPPING_SMARTPOST_TEXT_DESCRIPTION;
$this->sort_order = MODULE_SHIPPING_SMARTPOST_SORT_ORDER;
$this->icon = ''; // add image filename here; must be uploaded to the /images/ subdirectory
$this->tax_class = MODULE_SHIPPING_SMARTPOST_TAX_CLASS;
$this->tax_basis = MODULE_SHIPPING_SMARTPOST_TAX_BASIS;

// disable only when entire cart is free shipping
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_SMARTPOST_STATUS == 'True') ? true : false);
}

if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_SMARTPOST_ZONE > 0) ) {
$check_flag = false;
$check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_SMARTPOST_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;
}
}
}

function quote($method = '') {
global $order;

$this->quotes = array('id' => $this->code,
'module' => MODULE_SHIPPING_SMARTPOST_TEXT_TITLE,
'methods' => array(array('id' => $this->code,
'title' => MODULE_SHIPPING_SMARTPOST_TEXT_WAY,
'cost' => MODULE_SHIPPING_SMARTPOST_COST)));

if ($this->tax_class > 0) {
$this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}

if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

$places = array();

if (MODULE_SHIPPING_SMARTPOST_SHOW_LOCAL == "True") {
$places = $this->_quote($order->delivery['state'], $order->delivery['city']);
} else {
$places = $this->_quote();
}

$resultStr = "";
$resultStr .= '</label><select name="locker" id="locker" style="width: 500px;" onmousemove="if (document.getElementById(\''.$this->code.'_smartpost_begin\') != null) { document.getElementById(\''.$this->code.'_smartpost_begin\').style.display = \'none\';document.getElementById(\''.$this->code.'_smartpost_begin\').nextSibling.style.display = \'none\';}" onclick="this.parentNode.parentNode.getElementsByTagName(\'input\')[0].checked = true;this.parentNode.parentNode.getElementsByTagName(\'input\')[0].value = document.getElementById(\'locker\').value;" onchange="this.parentNode.parentNode.getElementsByTagName(\'input\')[0].checked = true;this.parentNode.parentNode.getElementsByTagName(\'input\')[0].value = document.getElementById(\'locker\').value;">';
foreach ($places as $place) {
$resultStr .= "<option value='"."".$this->code."_".$place['id']."'>".$place['title']."</option>\r\n";
}
$resultStr .= "</select>";
$resultStr .= "<label> &nbsp;&nbsp;&nbsp; ";
$resultStr .= '<script type="text/javascript">window.onload = function() {var v = document.getElementById(\'locker\').parentNode.parentNode.nextSibling; while(v && v.nodeType != 1) {v = v.nextSibling;} v.style.display = \'none\';document.getElementById(\'locker\').parentNode.parentNode.getElementsBy TagName(\'input\')[0].value = document.getElementById(\'locker\').value;};</script>';


$this->quotes['methods'] = array(
array(
'id' => $this->code,
'title' => $resultStr,
'cost' => $this->cost));

return $this->quotes;
}

function check() {
global $db;
if (!isset($this->_check)) {
$check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_SMARTPOST_STATUS'");
$this->_check = $check_query->RecordCount();
}
return $this->_check;
}

function install() {
global $db;
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Flat Shipping', 'MODULE_SHIPPING_SMARTPOST_STATUS', 'False', 'Do you want to offer smartpost rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
$db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_SMARTPOST_COST', '5.00', 'The shipping cost for all orders using 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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_SMARTPOST_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, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_SMARTPOST_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', 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 ('Shipping Zone', 'MODULE_SHIPPING_SMARTPOST_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_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_SMARTPOST_SORT_ORDER', '10', 'Sort order of display.', '6', '0', now())");
}

function remove() {
global $db;
$db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_SHIPPING\_SMARTPOST\_%'");
}

function keys() {
return array('MODULE_SHIPPING_SMARTPOST_STATUS', 'MODULE_SHIPPING_SMARTPOST_COST', 'MODULE_SHIPPING_SMARTPOST_TAX_CLASS', 'MODULE_SHIPPING_SMARTPOST_TAX_BASIS', 'MODULE_SHIPPING_SMARTPOST_ZONE', 'MODULE_SHIPPING_SMARTPOST_SORT_ORDER');
}

function _quote($city = '', $state = '') {
$city = htmlentities($city);
$state = htmlentities($state);

if (file_exists("smpostcache.txt") && (time() - filemtime("smpostcache.txt")) < 86400) {
$body = file_get_contents("smpostcache.txt");
} else {
$body = file_get_contents("http://www.smartpost.ee/places.php");
if (is_writable("smpostcache.txt") || is_writable(getcwd())) {
file_put_contents("smpostcache.txt", $body);
}
}
$response = unserialize($body);
$result = array();
foreach ($response as $r) {
if ($r['active'] == 1) {
if (($city == '' && $state == '') ||
(($city != '' && $state != '') &&
(stripos(htmlentities($r['name'], ENT_COMPAT, "UTF-8"), $city) !== false || stripos(htmlentities($r['group_name'], ENT_COMPAT, "UTF-8"), $state) !== false))) {
if (MODULE_SHIPPING_SMARTPOST_SHOW_SHORT == 'True') {
$result[] = array('id' => $this->code."_".$r['place_id'],
'title' => htmlentities($r['name'], ENT_COMPAT, "UTF-8")."",
'group_sort' => $r['group_sort'],
'cost' => $this->cost);
} else {
$result[] = array('id' => $this->code."_".$r['place_id'],
'title' => htmlentities($r['city'].", ".$r['name'].", ".$r['description'].", ".$r['address']." ".$r['opened'].", ".$r['group_name'].".", ENT_COMPAT, "UTF-8")."",
'group_sort' => $r['group_sort'],
'cost' => $this->cost);
}

}
}
}
if (MODULE_SHIPPING_SMARTPOST_APPLY_SORT == 'True') {
usort($result, array('smartpost', 'sort'));
}
return $result;

}
public static function sort($a, $b) {
$a = str_pad(100 - $a['group_sort'], 3, "0", STR_PAD_LEFT).$a['title'];
$b = str_pad(100 - $b['group_sort'], 3, "0", STR_PAD_LEFT).$b['title'];
return strcmp($a, $b);
}

}
?>