Quick Search:

View

Revision:

Diff

Diff from 1739 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/oscommerce2/trunk/catalog/includes/modules/shipping/table.php

Annotated File View

hpdl
477
1 <?php
2 /*
hpdl
1739
3   $Id: table.php 1739 2007-12-20 00:52:16Z hpdl $
hpdl
477
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2003 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class table {
14     var $code, $title, $description, $icon, $enabled;
15
16 // class constructor
17     function table() {
18       global $order;
19
20       $this->code = 'table';
21       $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE;
22       $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION;
23       $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER;
24       $this->icon = '';
25       $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS;
26       $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);
27
28       if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE_ZONE > 0) ) {
29         $check_flag = false;
30         $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
31         while ($check = tep_db_fetch_array($check_query)) {
32           if ($check['zone_id'] < 1) {
33             $check_flag = true;
34             break;
35           } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
36             $check_flag = true;
37             break;
38           }
39         }
40
41         if ($check_flag == false) {
42           $this->enabled = false;
43         }
44       }
45     }
46
47 // class methods
48     function quote($method = '') {
49       global $order, $cart, $shipping_weight, $shipping_num_boxes;
50
51       if (MODULE_SHIPPING_TABLE_MODE == 'price') {
52         $order_total = $cart->show_total();
53       } else {
54         $order_total = $shipping_weight;
55       }
56
57       $table_cost = split("[:,]" , MODULE_SHIPPING_TABLE_COST);
58       $size = sizeof($table_cost);
59       for ($i=0, $n=$size; $i<$n; $i+=2) {
60         if ($order_total <= $table_cost[$i]) {
61           $shipping = $table_cost[$i+1];
62           break;
63         }
64       }
65
66       if (MODULE_SHIPPING_TABLE_MODE == 'weight') {
67         $shipping = $shipping * $shipping_num_boxes;
68       }
69
70       $this->quotes = array('id' => $this->code,
71                             'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE,
72                             'methods' => array(array('id' => $this->code,
73                                                      'title' => MODULE_SHIPPING_TABLE_TEXT_WAY,
74                                                      'cost' => $shipping + MODULE_SHIPPING_TABLE_HANDLING)));
75
76       if ($this->tax_class > 0) {
77         $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
78       }
79
80       if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
81
82       return $this->quotes;
83     }
84
85     function check() {
86       if (!isset($this->_check)) {
87         $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE_STATUS'");
88         $this->_check = tep_db_num_rows($check_query);
89       }
90       return $this->_check;
91     }
92
93     function install() {
94       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Table Method', 'MODULE_SHIPPING_TABLE_STATUS', 'True', 'Do you want to offer table rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
95       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Table', 'MODULE_SHIPPING_TABLE_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc', '6', '0', now())");
96       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Table Method', 'MODULE_SHIPPING_TABLE_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())");
97       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TABLE_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
98       tep_db_query("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_TABLE_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
99       tep_db_query("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_TABLE_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
100       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_TABLE_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
101     }
102
103     function remove() {
104       tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
105     }
106
107     function keys() {
108       return array('MODULE_SHIPPING_TABLE_STATUS', 'MODULE_SHIPPING_TABLE_COST', 'MODULE_SHIPPING_TABLE_MODE', 'MODULE_SHIPPING_TABLE_HANDLING', 'MODULE_SHIPPING_TABLE_TAX_CLASS', 'MODULE_SHIPPING_TABLE_ZONE', 'MODULE_SHIPPING_TABLE_SORT_ORDER');
109     }
110   }
111 ?>