Quick Search:

View

Revision:

Diff

Diff from 637 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 637 2006-07-18 16:30:55Z 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
443
23       if (isset($_SESSION['osC_Shipping_data']) === false) {
24         $_SESSION['osC_Shipping_data'] = array('quotes' => array(),
25                                                'cartID' => null);
26       }
hpdl
1
27
hpdl
443
28       $this->_quotes =& $_SESSION['osC_Shipping_data']['quotes'];
29       $this->_cartID =& $_SESSION['osC_Shipping_data']['cartID'];
hpdl
1
30
hpdl
443
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();
35
36       while ($Qmodules->next()) {
37         $this->_modules[] = $Qmodules->value('code');
38       }
39
40       $Qmodules->freeResult();
41
42       if (empty($this->_modules) === false) {
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
410
48         $osC_Language->load('modules-shipping');
49
hpdl
443
50         foreach ($this->_modules as $module) {
51           $module_class = 'osC_Shipping_' . $module;
hpdl
1
52
hpdl
443
53           if (class_exists($module_class) === false) {
54             include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
55           }
56
57           $GLOBALS[$module_class] = new $module_class();
58           $GLOBALS[$module_class]->initialize();
hpdl
1
59         }
hpdl
443
60
61         usort($this->_modules, array('osC_Shipping', '_usortModules'));
hpdl
1
62       }
hpdl
443
63
64       $this->_calculate();
hpdl
1
65     }
66
hpdl
443
67 // class methods
68     function getCode() {
69       return $this->_code;
70     }
hpdl
1
71
hpdl
443
72     function getTitle() {
73       return $this->_title;
74     }
hpdl
1
75
hpdl
443
76     function getDescription() {
77       return $this->_description;
78     }
hpdl
1
79
hpdl
637
80     function isEnabled() {
hpdl
443
81       return $this->_status;
82     }
83
84     function getSortOrder() {
85       return $this->_sort_order;
86     }
87
88     function hasQuotes() {
89       return !empty($this->_quotes);
90     }
91
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
102     function getQuotes() {
103       return $this->_quotes;
104     }
105
106     function getQuote($module = '') {
107       if (empty($module)) {
108         $module = $this->_selected_module;
109       }
110
111       list($module_id, $method_id) = explode('_', $module);
112
113       $rate = array();
114
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']);
123
124               break 2;
125             }
126           }
hpdl
1
127         }
hpdl
443
128       }
hpdl
1
129
hpdl
443
130       return $rate;
131     }
132
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);
144           }
hpdl
1
145         }
hpdl
443
146       }
hpdl
1
147
hpdl
443
148       return $rate;
149     }
hpdl
1
150
hpdl
443
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
637
158           if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
443
159             $has_active = true;
160             break;
hpdl
1
161           }
162         }
hpdl
443
163       }
hpdl
1
164
hpdl
443
165       return $has_active;
166     }
167
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
637
179           if (defined('MODULE_SHIPPING_FREE_STATUS') && (MODULE_SHIPPING_FREE_STATUS == 'True') && $GLOBALS['osC_Shipping_free']->isEnabled()) {
hpdl
443
180             $include_quotes[] = 'osC_Shipping_free';
181           } else {
182             foreach ($this->_modules as $module) {
hpdl
637
183               if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
443
184                 $include_quotes[] = 'osC_Shipping_' . $module;
hpdl
1
185               }
186             }
187           }
188
hpdl
443
189           foreach ($include_quotes as $module) {
190             $quotes = $GLOBALS[$module]->quote();
191
192             if (is_array($quotes)) {
193               $this->_quotes[] = $quotes;
hpdl
1
194             }
195           }
196         }
hpdl
443
197       }
198     }
hpdl
1
199
hpdl
443
200     function _usortModules($a, $b) {
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
1
203       }
hpdl
443
204
205       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
1
206     }
207   }
208 ?>