Quick Search:

View

Revision:

Diff

Diff from 830 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 830 2006-08-29 12:44:39Z 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
421
23       if (isset($_SESSION['osC_Shipping_data']) === false) {
hpdl
439
24         $_SESSION['osC_Shipping_data'] = array('quotes' => array(),
25                                                'cartID' => null);
hpdl
421
26       }
hpdl
1
27
hpdl
421
28       $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
hpdl
439
29       $this->_cartID =& $_SESSION['osC_Shipping_data']['cartID'];
hpdl
421
30
hpdl
425
31       $Qmodules = $osC_Database->query('select code from :table_templates_boxes where modules_group = "shipping"');
32       $Qmodules->bindTable(':table_templates_boxes', TABLE_TEMPLATES_BOXES);
33       $Qmodules->setCache('modules-shipping');
34       $Qmodules->execute();
hpdl
421
35
hpdl
425
36       while ($Qmodules->next()) {
37         $this->_modules[] = $Qmodules->value('code');
38       }
39
40       $Qmodules->freeResult();
41
42       if (empty($this->_modules) === false) {
hpdl
439
43         if ((empty($module) === false) && in_array(substr($module, 0, strpos($module, '_')), $this->_modules)) {
44           $this->_selected_module = $module;
45           $this->_modules = array(substr($module, 0, strpos($module, '_')));
hpdl
1
46         }
47
hpdl
404
48         $osC_Language->load('modules-shipping');
49
hpdl
427
50         foreach ($this->_modules as $module) {
51           $module_class = 'osC_Shipping_' . $module;
52
hpdl
439
53           if (class_exists($module_class) === false) {
54             include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
55           }
56
hpdl
427
57           $GLOBALS[$module_class] = new $module_class();
58           $GLOBALS[$module_class]->initialize();
hpdl
1
59         }
hpdl
427
60
61         usort($this->_modules, array('osC_Shipping', '_usortModules'));
hpdl
1
62       }
hpdl
439
63
64       $this->_calculate();
hpdl
1
65     }
66
hpdl
432
67 // class methods
68     function getCode() {
69       return $this->_code;
70     }
71
72     function getTitle() {
73       return $this->_title;
74     }
75
76     function getDescription() {
77       return $this->_description;
78     }
79
hpdl
620
80     function isEnabled() {
hpdl
432
81       return $this->_status;
82     }
83
84     function getSortOrder() {
85       return $this->_sort_order;
86     }
87
hpdl
421
88     function hasQuotes() {
89       return !empty($this->_quotes);
hpdl
1
90     }
91
hpdl
422
92     function numberOfQuotes() {
93       $total_quotes = 0;
94
95       foreach ($this->_quotes as $quotes) {
96         $total_quotes += sizeof($quotes['methods']);
97       }
98
99       return $total_quotes;
100     }
101
hpdl
439
102     function getQuotes() {
103       return $this->_quotes;
104     }
hpdl
425
105
hpdl
439
106     function getQuote($module = '') {
107       if (empty($module)) {
108         $module = $this->_selected_module;
hpdl
421
109       }
110
hpdl
439
111       list($module_id, $method_id) = explode('_', $module);
hpdl
421
112
hpdl
439
113       $rate = array();
hpdl
1
114
hpdl
439
115       foreach ($this->_quotes as $quote) {
116         if ($quote['id'] == $module_id) {
117           foreach ($quote['methods'] as $method) {
118             if ($method['id'] == $method_id) {
119               $rate = array('id' => $module,
120                             'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
121                             'cost' => $method['cost'],
hpdl
830
122                             'tax_class_id' => $quote['tax_class_id'],
123                             'is_cheapest' => null);
hpdl
421
124
hpdl
439
125               break 2;
hpdl
1
126             }
127           }
128         }
hpdl
439
129       }
hpdl
1
130
hpdl
439
131       return $rate;
132     }
hpdl
421
133
hpdl
439
134     function getCheapestQuote() {
135       $rate = array();
136
137       foreach ($this->_quotes as $quote) {
138         foreach ($quote['methods'] as $method) {
139           if (empty($rate) || ($method['cost'] < $rate['cost'])) {
140             $rate = array('id' => $quote['id'] . '_' . $method['id'],
141                           'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
142                           'cost' => $method['cost'],
143                           'tax_class_id' => $quote['tax_class_id'],
144                           'is_cheapest' => true);
hpdl
1
145           }
146         }
147       }
hpdl
439
148
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() {
170       global $osC_ShoppingCart;
171
172       if ($this->_cartID != $osC_ShoppingCart->getCartID()) {
173         $this->_cartID = $osC_ShoppingCart->getCartID();
174
175         $this->_quotes = array();
176
177         if (is_array($this->_modules)) {
178           $include_quotes = array();
179
hpdl
620
180           if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && $GLOBALS['osC_Shipping_free']->isEnabled()) {
hpdl
439
181             $include_quotes[] = 'osC_Shipping_free';
182           } else {
183             foreach ($this->_modules as $module) {
hpdl
620
184               if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
439
185                 $include_quotes[] = 'osC_Shipping_' . $module;
186               }
187             }
188           }
189
190           foreach ($include_quotes as $module) {
191             $quotes = $GLOBALS[$module]->quote();
192
193             if (is_array($quotes)) {
194               $this->_quotes[] = $quotes;
195             }
196           }
197         }
198       }
199     }
200
hpdl
427
201     function _usortModules($a, $b) {
hpdl
432
202       if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
203         return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
hpdl
427
204       }
205
hpdl
432
206       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
427
207     }
hpdl
1
208   }
209 ?>