Quick Search:

View

Revision:

Diff

Diff from 1841 to:

Annotations

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

Annotated File View

hpdl
477
1 <?php
2 /*
hpdl
1739
3   $Id: item.php 1841 2008-12-12 13:25:49Z hpdl $
hpdl
477
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
1841
8   Copyright (c) 2008 osCommerce
hpdl
477
9
10   Released under the GNU General Public License
11 */
12
13   class item {
14     var $code, $title, $description, $icon, $enabled;
15
16 // class constructor
17     function item() {
18       global $order;
19
20       $this->code = 'item';
21       $this->title = MODULE_SHIPPING_ITEM_TEXT_TITLE;
22       $this->description = MODULE_SHIPPING_ITEM_TEXT_DESCRIPTION;
23       $this->sort_order = MODULE_SHIPPING_ITEM_SORT_ORDER;
24       $this->icon = '';
25       $this->tax_class = MODULE_SHIPPING_ITEM_TAX_CLASS;
26       $this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false);
27
28       if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_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_ITEM_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 = '') {
hpdl
1841
49       global $order;
hpdl
477
50
hpdl
1841
51       $number_of_items = $this->getNumberOfItems();
52
hpdl
477
53       $this->quotes = array('id' => $this->code,
54                             'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
55                             'methods' => array(array('id' => $this->code,
56                                                      'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
hpdl
1841
57                                                      'cost' => (MODULE_SHIPPING_ITEM_COST * $number_of_items) + MODULE_SHIPPING_ITEM_HANDLING)));
hpdl
477
58
59       if ($this->tax_class > 0) {
60         $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
61       }
62
63       if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
64
65       return $this->quotes;
66     }
67
68     function check() {
69       if (!isset($this->_check)) {
70         $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ITEM_STATUS'");
71         $this->_check = tep_db_num_rows($check_query);
72       }
73       return $this->_check;
74     }
75
76     function install() {
77       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 Item Shipping', 'MODULE_SHIPPING_ITEM_STATUS', 'True', 'Do you want to offer per item rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
78       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_ITEM_COST', '2.50', 'The shipping cost will be multiplied by the number of items in an order that uses this shipping method.', '6', '0', now())");
79       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_ITEM_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
80       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_ITEM_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())");
81       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_ITEM_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())");
82       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_ITEM_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
83     }
84
85     function remove() {
86       tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
87     }
88
89     function keys() {
90       return array('MODULE_SHIPPING_ITEM_STATUS', 'MODULE_SHIPPING_ITEM_COST', 'MODULE_SHIPPING_ITEM_HANDLING', 'MODULE_SHIPPING_ITEM_TAX_CLASS', 'MODULE_SHIPPING_ITEM_ZONE', 'MODULE_SHIPPING_ITEM_SORT_ORDER');
91     }
hpdl
1841
92
93     function getNumberOfItems() {
94       global $order, $total_count;
95
96       $number_of_items = $total_count;
97
98       if ($order->content_type == 'mixed') {
99         $number_of_items = 0;
100
101         for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
102           $number_of_items += $order->products[$i]['qty'];
103
104           if (isset($order->products[$i]['attributes'])) {
105             reset($order->products[$i]['attributes']);
106             while (list($option, $value) = each($order->products[$i]['attributes'])) {
107               $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$order->products[$i]['id'] . "' and pa.options_values_id = '" . (int)$value['value_id'] . "' and pa.products_attributes_id = pad.products_attributes_id");
108               $virtual_check = tep_db_fetch_array($virtual_check_query);
109
110               if ($virtual_check['total'] > 0) {
111                 $number_of_items -= $order->products[$i]['qty'];
112               }
113             }
114           }
115         }
116       }
117
118       return $number_of_items;
119     }
hpdl
477
120   }
121 ?>