Quick Search:

View

Revision:

Diff

Diff from 199 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 199 2005-09-22 15:56:13Z hpdl $
hpdl
1
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 (defined('MODULE_SHIPPING_INSTALLED') && tep_not_null(MODULE_SHIPPING_INSTALLED)) {
19         $this->modules = explode(';', MODULE_SHIPPING_INSTALLED);
20
21         $include_modules = array();
22
23         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)) ) {
24           $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)));
25         } else {
26           reset($this->modules);
27           while (list(, $value) = each($this->modules)) {
28             $class = substr($value, 0, strrpos($value, '.'));
29             $include_modules[] = array('class' => $class, 'file' => $value);
30           }
31         }
32
33         for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
hpdl
199
34           include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/shipping/' . $include_modules[$i]['file']);
hpdl
1
35           include(DIR_WS_MODULES . 'shipping/' . $include_modules[$i]['file']);
36
37           $GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
38         }
39       }
40     }
41
42     function quote($method = '', $module = '') {
43       global $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes;
44
45       $quotes_array = array();
46
47       if (is_array($this->modules)) {
48         $shipping_quoted = '';
49         $shipping_num_boxes = 1;
50         $shipping_weight = $total_weight;
51
52         if (SHIPPING_BOX_WEIGHT >= $shipping_weight*SHIPPING_BOX_PADDING/100) {
53           $shipping_weight = $shipping_weight+SHIPPING_BOX_WEIGHT;
54         } else {
55           $shipping_weight = $shipping_weight + ($shipping_weight*SHIPPING_BOX_PADDING/100);
56         }
57
58         if ($shipping_weight > SHIPPING_MAX_WEIGHT) { // Split into many boxes
59           $shipping_num_boxes = ceil($shipping_weight/SHIPPING_MAX_WEIGHT);
60           $shipping_weight = $shipping_weight/$shipping_num_boxes;
61         }
62
63         $include_quotes = array();
64
65         reset($this->modules);
66         while (list(, $value) = each($this->modules)) {
67           $class = substr($value, 0, strrpos($value, '.'));
68           if (tep_not_null($module)) {
69             if ( ($module == $class) && ($GLOBALS[$class]->enabled) ) {
70               $include_quotes[] = $class;
71             }
72           } elseif ($GLOBALS[$class]->enabled) {
73             $include_quotes[] = $class;
74           }
75         }
76
77         $size = sizeof($include_quotes);
78         for ($i=0; $i<$size; $i++) {
79           $quotes = $GLOBALS[$include_quotes[$i]]->quote($method);
80           if (is_array($quotes)) $quotes_array[] = $quotes;
81         }
82       }
83
84       return $quotes_array;
85     }
86
87     function cheapest() {
88       if (is_array($this->modules)) {
89         $rates = array();
90
91         reset($this->modules);
92         while (list(, $value) = each($this->modules)) {
93           $class = substr($value, 0, strrpos($value, '.'));
94           if ($GLOBALS[$class]->enabled) {
95             $quotes = $GLOBALS[$class]->quotes;
96             for ($i=0, $n=sizeof($quotes['methods']); $i<$n; $i++) {
97               if (isset($quotes['methods'][$i]['cost']) && tep_not_null($quotes['methods'][$i]['cost'])) {
98                 $rates[] = array('id' => $quotes['id'] . '_' . $quotes['methods'][$i]['id'],
99                                  'title' => $quotes['module'] . ' (' . $quotes['methods'][$i]['title'] . ')',
100                                  'cost' => $quotes['methods'][$i]['cost']);
101               }
102             }
103           }
104         }
105
106         $cheapest = false;
107         for ($i=0, $n=sizeof($rates); $i<$n; $i++) {
108           if (is_array($cheapest)) {
109             if ($rates[$i]['cost'] < $cheapest['cost']) {
110               $cheapest = $rates[$i];
111             }
112           } else {
113             $cheapest = $rates[$i];
114           }
115         }
116
117         return $cheapest;
118       }
119     }
120   }
121 ?>