Quick Search:

View

Revision:

Diff

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