Quick Search:

View

Revision:

Diff

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