Quick Search:

View

Revision:

Diff

Diff from 1421 to:

Annotations

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

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: shipping.php 1421 2007-03-08 00:24:29Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
410
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
443
13   class osC_Shipping {
14     var $_modules = array(),
15         $_selected_module,
16         $_quotes = array(),
17         $_group = 'shipping';
hpdl
1
18
19 // class constructor
hpdl
443
20     function osC_Shipping($module = '') {
21       global $osC_Database, $osC_Language;
hpdl
383
22
hpdl
1421
23       $this->_quotes =& $_SESSION['osC_ShoppingCart_data']['shipping_quotes'];
hpdl
1
24
hpdl
443
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();
29
30       while ($Qmodules->next()) {
31         $this->_modules[] = $Qmodules->value('code');
32       }
33
34       $Qmodules->freeResult();
35
36       if (empty($this->_modules) === false) {
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
410
42         $osC_Language->load('modules-shipping');
43
hpdl
443
44         foreach ($this->_modules as $module) {
45           $module_class = 'osC_Shipping_' . $module;
hpdl
1
46
hpdl
443
47           if (class_exists($module_class) === false) {
48             include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
49           }
50
51           $GLOBALS[$module_class] = new $module_class();
52           $GLOBALS[$module_class]->initialize();
hpdl
1
53         }
hpdl
443
54
55         usort($this->_modules, array('osC_Shipping', '_usortModules'));
hpdl
1
56       }
hpdl
443
57
hpdl
1421
58       if ( empty($this->_quotes) ) {
59         $this->_calculate();
60       }
hpdl
1
61     }
62
hpdl
443
63 // class methods
64     function getCode() {
65       return $this->_code;
66     }
hpdl
1
67
hpdl
443
68     function getTitle() {
69       return $this->_title;
70     }
hpdl
1
71
hpdl
443
72     function getDescription() {
73       return $this->_description;
74     }
hpdl
1
75
hpdl
637
76     function isEnabled() {
hpdl
443
77       return $this->_status;
78     }
79
80     function getSortOrder() {
81       return $this->_sort_order;
82     }
83
84     function hasQuotes() {
85       return !empty($this->_quotes);
86     }
87
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
98     function getQuotes() {
99       return $this->_quotes;
100     }
101
102     function getQuote($module = '') {
103       if (empty($module)) {
104         $module = $this->_selected_module;
105       }
106
107       list($module_id, $method_id) = explode('_', $module);
108
109       $rate = array();
110
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
831
118                             'tax_class_id' => $quote['tax_class_id'],
119                             'is_cheapest' => null);
hpdl
443
120
121               break 2;
122             }
123           }
hpdl
1
124         }
hpdl
443
125       }
hpdl
1
126
hpdl
443
127       return $rate;
128     }
129
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
865
140                           'is_cheapest' => false);
hpdl
443
141           }
hpdl
1
142         }
hpdl
443
143       }
hpdl
1
144
hpdl
865
145       if (!empty($rate)) {
146         $rate['is_cheapest'] = true;
147       }
148
hpdl
443
149       return $rate;
150     }
hpdl
1
151
hpdl
443
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
637
159           if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
443
160             $has_active = true;
161             break;
hpdl
1
162           }
163         }
hpdl
443
164       }
hpdl
1
165
hpdl
443
166       return $has_active;
167     }
168
169     function _calculate() {
hpdl
1421
170       $this->_quotes = array();
hpdl
443
171
hpdl
1421
172       if (is_array($this->_modules)) {
173         $include_quotes = array();
hpdl
443
174
hpdl
1421
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
1
181             }
182           }
hpdl
1421
183         }
hpdl
1
184
hpdl
1421
185         foreach ($include_quotes as $module) {
186           $quotes = $GLOBALS[$module]->quote();
hpdl
443
187
hpdl
1421
188           if (is_array($quotes)) {
189             $this->_quotes[] = $quotes;
hpdl
1
190           }
191         }
hpdl
443
192       }
193     }
hpdl
1
194
hpdl
443
195     function _usortModules($a, $b) {
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
1
198       }
hpdl
443
199
200       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
1
201     }
202   }
203 ?>