Quick Search:

View

Revision:

Diff

Diff from 1 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 /*
3   $Id: shipping.php,v 1.25 2004/04/13 07:32:51 hpdl Exp $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2003 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class shipping {
14     var $modules;
15
16 // class constructor
17     function shipping($module = '') {
18       if (PHP_VERSION < 4.1) {
19         global $_SERVER;
20       }
21
22       global $osC_Session;
23
24       if (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {
25         $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
26
27         $include_modules = array();
28
29         if ( (tep_not_null($module)) && (in_array(substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)), $this->modules)) ) {
30           $include_modules[] = array('class' => substr($module['id'], 0, strpos($module['id'], '_')), 'file' => substr($module['id'], 0, strpos($module['id'], '_')) . '.' . substr($_SERVER['PHP_SELF'], (strrpos($_SERVER['PHP_SELF'], '.')+1)));
31         } else {
32           reset($this->modules);
33           while (list(, $value) = each($this->modules)) {
34             $class = substr($value, 0, strrpos($value, '.'));
35             $include_modules[] = array('class' => $class, 'file' => $value);
36           }
37         }
38
39         for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
40           include(DIR_WS_LANGUAGES . $osC_Session->value('language') . '/modules/shipping/' . $include_modules[$i]['file']);
41           include(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);
42
43           $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
44         }
45       }
46     }
47
48     function quote($method = '', $module = '') {
49       global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
50
51       $quotes_array = array();
52
53       if (is_array($this->modules)) {
54         $shipping_quoted = '';
55         $shipping_num_boxes = 1;
56         $shipping_weight = $total_weight;
57
58         if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
59           $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
60         } else {
61           $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
62         }
63
64         if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
65           $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
66           $shipping_weight = $shipping_weight/$shipping_num_boxes;
67         }
68
69         $include_quotes = array();
70
71         reset($this->modules);
72         while (list(, $value) = each($this->modules)) {
73           $class = substr($value, 0, strrpos($value, '.'));
74           if (tep_not_null($module)) {
75             if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
76               $include_quotes[] = $class;
77             }
78           } elseif ($GLOBALS[$class]->enabled) {
79             $include_quotes[] = $class;
80           }
81         }
82
83         $size = sizeof($include_quotes);
84         for ($i=0; $i<$size; $i++) {
85           $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
86           if (is_array($quotes)) $quotes_array[] = $quotes;
87         }
88       }
89
90       return $quotes_array;
91     }
92
93     function cheapest() {
94       if (is_array($this->modules)) {
95         $rates = array();
96
97         reset($this->modules);
98         while (list(, $value) = each($this->modules)) {
99           $class = substr($value, 0, strrpos($value, '.'));
100           if ($GLOBALS[$class]->enabled) {
101             $quotes = $GLOBALS[$class]->quotes;
102             for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
103               if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
104                 $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
105                                  'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
106                                  'cost' => $quotes['methods'][$i]['cost']);
107               }
108             }
109           }
110         }
111
112         $cheapest = false;
113         for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
114           if (is_array($cheapest)) {
115             if ($rates[$i]['cost'] < $cheapest['cost']) {
116               $cheapest = $rates[$i];
117             }
118           } else {
119             $cheapest = $rates[$i];
120           }
121         }
122
123         return $cheapest;
124       }
125     }
126   }
127 ?>