Quick Search:

View

Revision:

Diff

Diff from 620 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 620 2006-07-13 10:48:54Z 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'],
122                             'tax_class_id' => $quote['tax_class_id']);
hpdl
421
123
hpdl
439
124               break 2;
hpdl
1
125             }
126           }
127         }
hpdl
439
128       }
hpdl
1
129
hpdl
439
130       return $rate;
131     }
hpdl
421
132
hpdl
439
133     function getCheapestQuote() {
134       $rate = array();
135
136       foreach ($this->_quotes as $quote) {
137         foreach ($quote['methods'] as $method) {
138           if (empty($rate) || ($method['cost'] < $rate['cost'])) {
139             $rate = array('id' => $quote['id'] . '_' . $method['id'],
140                           'title' => $quote['module'] . ((empty($method['title']) === false) ? ' (' . $method['title'] . ')' : ''),
141                           'cost' => $method['cost'],
142                           'tax_class_id' => $quote['tax_class_id'],
143                           'is_cheapest' => true);
hpdl
1
144           }
145         }
146       }
hpdl
439
147
148       return $rate;
hpdl
1
149     }
hpdl
425
150
151     function hasActive() {
152       static $has_active;
153
154       if (isset($has_active) === false) {
155         $has_active = false;
156
157         foreach ($this->_modules as $module) {
hpdl
620
158           if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
425
159             $has_active = true;
160             break;
161           }
162         }
163       }
164
165       return $has_active;
166     }
167
hpdl
439
168     function _calculate() {
169       global $osC_ShoppingCart;
170
171       if ($this->_cartID != $osC_ShoppingCart->getCartID()) {
172         $this->_cartID = $osC_ShoppingCart->getCartID();
173
174         $this->_quotes = array();
175
176         if (is_array($this->_modules)) {
177           $include_quotes = array();
178
hpdl
620
179           if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && $GLOBALS['osC_Shipping_free']->isEnabled()) {
hpdl
439
180             $include_quotes[] = 'osC_Shipping_free';
181           } else {
182             foreach ($this->_modules as $module) {
hpdl
620
183               if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
439
184                 $include_quotes[] = 'osC_Shipping_' . $module;
185               }
186             }
187           }
188
189           foreach ($include_quotes as $module) {
190             $quotes = $GLOBALS[$module]->quote();
191
192             if (is_array($quotes)) {
193               $this->_quotes[] = $quotes;
194             }
195           }
196         }
197       }
198     }
199
hpdl
427
200     function _usortModules($a, $b) {
hpdl
432
201       if ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() == $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) {
202         return strnatcasecmp($GLOBALS['osC_Shipping_' . $a]->getTitle(), $GLOBALS['osC_Shipping_' . $a]->getTitle());
hpdl
427
203       }
204
hpdl
432
205       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
427
206     }
hpdl
1
207   }
208 ?>