Quick Search:

View

Revision:

Diff

Diff from 1420 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/shipping.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
153
3   $Id: shipping.php 1420 2007-03-08 00:21:12Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
404
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
421
13   class osC_Shipping {
14     var $_modules = array(),
hpdl
439
15         $_selected_module,
hpdl
421
16         $_quotes = array(),
hpdl
432
17         $_group = 'shipping';
hpdl
1
18
19 // class constructor
hpdl
421
20     function osC_Shipping($module = '') {
hpdl
425
21       global $osC_Database, $osC_Language;
hpdl
377
22
hpdl
1420
23       $this->_quotes =& $_SESSION['osC_ShoppingCart_data']['shipping_quotes'];
hpdl
1
24
hpdl
425
25       $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"');
26       $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
27       $Qmodules->setCache('modules-shipping');
28       $Qmodules->execute();
hpdl
421
29
hpdl
425
30       while ($Qmodules->next()) {
31         $this->_modules[] = $Qmodules->value('code');
32       }
33
34       $Qmodules->freeResult();
35
36       if (empty($this->_modules) === false) {
hpdl
439
37         if ((empty($module) === false) && in_array(substr($module, 0, strpos($module, '_')), $this->_modules)) {
38           $this->_selected_module = $module;
39           $this->_modules = array(substr($module, 0, strpos($module, '_')));
hpdl
1
40         }
41
hpdl
404
42         $osC_Language->load('modules-shipping');
43
hpdl
427
44         foreach ($this->_modules as $module) {
45           $module_class = 'osC_Shipping_' . $module;
46
hpdl
439
47           if (class_exists($module_class) === false) {
48             include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
49           }
50
hpdl
427
51           $GLOBALS[$module_class] = new $module_class();
52           $GLOBALS[$module_class]->initialize();
hpdl
1
53         }
hpdl
427
54
55         usort($this->_modules, array('osC_Shipping', '_usortModules'));
hpdl
1
56       }
hpdl
439
57
hpdl
1420
58       if ( empty($this->_quotes) ) {
59         $this->_calculate();
60       }
hpdl
1
61     }
62
hpdl
432
63 // class methods
64     function getCode() {
65       return $this->_code;
66     }
67
68     function getTitle() {
69       return $this->_title;
70     }
71
72     function getDescription() {
73       return $this->_description;
74     }
75
hpdl
620
76     function isEnabled() {
hpdl
432
77       return $this->_status;
78     }
79
80     function getSortOrder() {
81       return $this->_sort_order;
82     }
83
hpdl
421
84     function hasQuotes() {
85       return !empty($this->_quotes);
hpdl
1
86     }
87
hpdl
422
88     function numberOfQuotes() {
89       $total_quotes = 0;
90
91       foreach ($this->_quotes as $quotes) {
92         $total_quotes += sizeof($quotes['methods']);
93       }
94
95       return $total_quotes;
96     }
97
hpdl
439
98     function getQuotes() {
99       return $this->_quotes;
100     }
hpdl
425
101
hpdl
439
102     function getQuote($module = '') {
103       if (empty($module)) {
104         $module = $this->_selected_module;
hpdl
421
105       }
106
hpdl
439
107       list($module_id, $method_id) = explode('_', $module);
hpdl
421
108
hpdl
439
109       $rate = array();
hpdl
1
110
hpdl
439
111       foreach ($this->_quotes as $quote) {
112         if ($quote['id'] == $module_id) {
113           foreach ($quote['methods'] as $method) {
114             if ($method['id'] == $method_id) {
115               $rate = array('id' => $module,
116                             'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
117                             'cost' => $method['cost'],
hpdl
830
118                             'tax_class_id' => $quote['tax_class_id'],
119                             'is_cheapest' => null);
hpdl
421
120
hpdl
439
121               break 2;
hpdl
1
122             }
123           }
124         }
hpdl
439
125       }
hpdl
1
126
hpdl
439
127       return $rate;
128     }
hpdl
421
129
hpdl
439
130     function getCheapestQuote() {
131       $rate = array();
132
133       foreach ($this->_quotes as $quote) {
134         foreach ($quote['methods'] as $method) {
135           if (empty($rate) || ($method['cost'] < $rate['cost'])) {
136             $rate = array('id' => $quote['id'] . '_' . $method['id'],
137                           'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
138                           'cost' => $method['cost'],
139                           'tax_class_id' => $quote['tax_class_id'],
hpdl
864
140                           'is_cheapest' => false);
hpdl
1
141           }
142         }
143       }
hpdl
439
144
hpdl
864
145       if (!empty($rate)) {
146         $rate['is_cheapest'] = true;
147       }
148
hpdl
439
149       return $rate;
hpdl
1
150     }
hpdl
425
151
152     function hasActive() {
153       static $has_active;
154
155       if (isset($has_active) === false) {
156         $has_active = false;
157
158         foreach ($this->_modules as $module) {
hpdl
620
159           if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
425
160             $has_active = true;
161             break;
162           }
163         }
164       }
165
166       return $has_active;
167     }
168
hpdl
439
169     function _calculate() {
hpdl
1420
170       $this->_quotes = array();
hpdl
439
171
hpdl
1420
172       if (is_array($this->_modules)) {
173         $include_quotes = array();
hpdl
439
174
hpdl
1420
175         if (defined('MODULE_SHIPPING_FREE_STATUS') && isset($GLOBALS['osC_Shipping_free']) && $GLOBALS['osC_Shipping_free']->isEnabled()) {
176           $include_quotes[] = 'osC_Shipping_free';
177         } else {
178           foreach ($this->_modules as $module) {
179             if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
180               $include_quotes[] = 'osC_Shipping_' . $module;
hpdl
439
181             }
182           }
hpdl
1420
183         }
hpdl
439
184
hpdl
1420
185         foreach ($include_quotes as $module) {
186           $quotes = $GLOBALS[$module]->quote();
hpdl
439
187
hpdl
1420
188           if (is_array($quotes)) {
189             $this->_quotes[] = $quotes;
hpdl
439
190           }
191         }
192       }
193     }
194
hpdl
427
195     function _usortModules($a, $b) {
hpdl
432
196       if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
197         return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
hpdl
427
198       }
199
hpdl
432
200       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
427
201     }
hpdl
1
202   }
203 ?>