Quick Search:

View

Revision:

Diff

Diff from 1498 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 1498 2007-03-29 14:04:50Z 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
hpdl
1498
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
443
15   class osC_Shipping {
16     var $_modules = array(),
17         $_selected_module,
18         $_quotes = array(),
19         $_group = 'shipping';
hpdl
1
20
21 // class constructor
hpdl
443
22     function osC_Shipping($module = '') {
23       global $osC_Database, $osC_Language;
hpdl
383
24
hpdl
1421
25       $this->_quotes =& $_SESSION['osC_ShoppingCart_data']['shipping_quotes'];
hpdl
1
26
hpdl
443
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();
31
32       while ($Qmodules->next()) {
33         $this->_modules[] = $Qmodules->value('code');
34       }
35
36       $Qmodules->freeResult();
37
38       if (empty($this->_modules) === false) {
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
410
44         $osC_Language->load('modules-shipping');
45
hpdl
443
46         foreach ($this->_modules as $module) {
47           $module_class = 'osC_Shipping_' . $module;
hpdl
1
48
hpdl
443
49           if (class_exists($module_class) === false) {
50             include('includes/modules/shipping/' . $module . '.' . substr(basename(__FILE__), (strrpos(basename(__FILE__), '.')+1)));
51           }
52
53           $GLOBALS[$module_class] = new $module_class();
54           $GLOBALS[$module_class]->initialize();
hpdl
1
55         }
hpdl
443
56
57         usort($this->_modules, array('osC_Shipping', '_usortModules'));
hpdl
1
58       }
hpdl
443
59
hpdl
1421
60       if ( empty($this->_quotes) ) {
61         $this->_calculate();
62       }
hpdl
1
63     }
64
hpdl
443
65 // class methods
66     function getCode() {
67       return $this->_code;
68     }
hpdl
1
69
hpdl
443
70     function getTitle() {
71       return $this->_title;
72     }
hpdl
1
73
hpdl
443
74     function getDescription() {
75       return $this->_description;
76     }
hpdl
1
77
hpdl
637
78     function isEnabled() {
hpdl
443
79       return $this->_status;
80     }
81
82     function getSortOrder() {
83       return $this->_sort_order;
84     }
85
86     function hasQuotes() {
87       return !empty($this->_quotes);
88     }
89
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
100     function getQuotes() {
101       return $this->_quotes;
102     }
103
104     function getQuote($module = '') {
105       if (empty($module)) {
106         $module = $this->_selected_module;
107       }
108
109       list($module_id, $method_id) = explode('_', $module);
110
111       $rate = array();
112
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
831
120                             'tax_class_id' => $quote['tax_class_id'],
121                             'is_cheapest' => null);
hpdl
443
122
123               break 2;
124             }
125           }
hpdl
1
126         }
hpdl
443
127       }
hpdl
1
128
hpdl
443
129       return $rate;
130     }
131
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
865
142                           'is_cheapest' => false);
hpdl
443
143           }
hpdl
1
144         }
hpdl
443
145       }
hpdl
1
146
hpdl
865
147       if (!empty($rate)) {
148         $rate['is_cheapest'] = true;
149       }
150
hpdl
443
151       return $rate;
152     }
hpdl
1
153
hpdl
443
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
637
161           if ($GLOBALS['osC_Shipping_' . $module]->isEnabled()) {
hpdl
443
162             $has_active = true;
163             break;
hpdl
1
164           }
165         }
hpdl
443
166       }
hpdl
1
167
hpdl
443
168       return $has_active;
169     }
170
171     function _calculate() {
hpdl
1421
172       $this->_quotes = array();
hpdl
443
173
hpdl
1421
174       if (is_array($this->_modules)) {
175         $include_quotes = array();
hpdl
443
176
hpdl
1421
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
1
183             }
184           }
hpdl
1421
185         }
hpdl
1
186
hpdl
1421
187         foreach ($include_quotes as $module) {
188           $quotes = $GLOBALS[$module]->quote();
hpdl
443
189
hpdl
1421
190           if (is_array($quotes)) {
191             $this->_quotes[] = $quotes;
hpdl
1
192           }
193         }
hpdl
443
194       }
195     }
hpdl
1
196
hpdl
443
197     function _usortModules($a, $b) {
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
1
200       }
hpdl
443
201
202       return ($GLOBALS['osC_Shipping_' . $a]->getSortOrder() < $GLOBALS['osC_Shipping_' . $b]->getSortOrder()) ? -1 : 1;
hpdl
1
203     }
204   }
205 ?>