| [ Index ] | osCommerce
Docs :: PHP Cross Reference For osCommerce 2.2 MS2 Provided By OSCdox.com |
1 <?php 2 /* 3 $Id: ups.php,v 1.54 2003/04/08 23:23:42 dgw_ 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 ups { 14 var $code, $title, $descrption, $icon, $enabled, $types; 15 16 // class constructor 17 function ups() { 18 global $order; 19 20 $this->code = 'ups'; 21 $this->title = MODULE_SHIPPING_UPS_TEXT_TITLE; 22 $this->description = MODULE_SHIPPING_UPS_TEXT_DESCRIPTION; 23 $this->sort_order = MODULE_SHIPPING_UPS_SORT_ORDER; 24 $this->icon = DIR_WS_ICONS . 'shipping_ups.gif'; 25 $this->tax_class = MODULE_SHIPPING_UPS_TAX_CLASS; 26 $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false); 27 28 if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_UPS_ZONE > 0) ) { 29 $check_flag = false; 30 $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_UPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); 31 while ($check = tep_db_fetch_array($check_query)) { 32 if ($check['zone_id'] < 1) { 33 $check_flag = true; 34 break; 35 } elseif ($check['zone_id'] == $order->delivery['zone_id']) { 36 $check_flag = true; 37 break; 38 } 39 } 40 41 if ($check_flag == false) { 42 $this->enabled = false; 43 } 44 } 45 46 $this->types = array('1DM' => 'Next Day Air Early AM', 47 '1DML' => 'Next Day Air Early AM Letter', 48 '1DA' => 'Next Day Air', 49 '1DAL' => 'Next Day Air Letter', 50 '1DAPI' => 'Next Day Air Intra (Puerto Rico)', 51 '1DP' => 'Next Day Air Saver', 52 '1DPL' => 'Next Day Air Saver Letter', 53 '2DM' => '2nd Day Air AM', 54 '2DML' => '2nd Day Air AM Letter', 55 '2DA' => '2nd Day Air', 56 '2DAL' => '2nd Day Air Letter', 57 '3DS' => '3 Day Select', 58 'GND' => 'Ground', 59 'GNDCOM' => 'Ground Commercial', 60 'GNDRES' => 'Ground Residential', 61 'STD' => 'Canada Standard', 62 'XPR' => 'Worldwide Express', 63 'XPRL' => 'worldwide Express Letter', 64 'XDM' => 'Worldwide Express Plus', 65 'XDML' => 'Worldwide Express Plus Letter', 66 'XPD' => 'Worldwide Expedited'); 67 } 68 69 // class methods 70 function quote($method = '') { 71 global $HTTP_POST_VARS, $order, $shipping_weight, $shipping_num_boxes; 72 73 if ( (tep_not_null($method)) && (isset($this->types[$method])) ) { 74 $prod = $method; 75 } else { 76 $prod = 'GNDRES'; 77 } 78 79 if ($method) $this->_upsAction('3'); // return a single quote 80 81 $this->_upsProduct($prod); 82 83 $country_name = tep_get_countries(SHIPPING_ORIGIN_COUNTRY, true); 84 $this->_upsOrigin(SHIPPING_ORIGIN_ZIP, $country_name['countries_iso_code_2']); 85 $this->_upsDest($order->delivery['postcode'], $order->delivery['country']['iso_code_2']); 86 $this->_upsRate(MODULE_SHIPPING_UPS_PICKUP); 87 $this->_upsContainer(MODULE_SHIPPING_UPS_PACKAGE); 88 $this->_upsWeight($shipping_weight); 89 $this->_upsRescom(MODULE_SHIPPING_UPS_RES); 90 $upsQuote = $this->_upsGetQuote(); 91 92 if ( (is_array($upsQuote)) && (sizeof($upsQuote) > 0) ) { 93 $this->quotes = array('id' => $this->code, 94 'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)'); 95 96 $methods = array(); 97 $qsize = sizeof($upsQuote); 98 for ($i=0; $i<$qsize; $i++) { 99 list($type, $cost) = each($upsQuote[$i]); 100 $methods[] = array('id' => $type, 101 'title' => $this->types[$type], 102 'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes); 103 } 104 105 $this->quotes['methods'] = $methods; 106 107 if ($this->tax_class > 0) { 108 $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 109 } 110 } else { 111 $this->quotes = array('module' => $this->title, 112 'error' => 'An error occured with the UPS shipping calculations.<br>' . $upsQuote . '<br>If you prefer to use UPS as your shipping method, please contact the store owner.'); 113 } 114 115 if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); 116 117 return $this->quotes; 118 } 119 120 function check() { 121 if (!isset($this->_check)) { 122 $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_UPS_STATUS'"); 123 $this->_check = tep_db_num_rows($check_query); 124 } 125 return $this->_check; 126 } 127 128 function install() { 129 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable UPS Shipping', 'MODULE_SHIPPING_UPS_STATUS', 'True', 'Do you want to offer UPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); 130 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Pickup Method', 'MODULE_SHIPPING_UPS_PICKUP', 'CC', 'How do you give packages to UPS? CC - Customer Counter, RDP - Daily Pickup, OTP - One Time Pickup, LC - Letter Center, OCA - On Call Air', '6', '0', now())"); 131 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Packaging?', 'MODULE_SHIPPING_UPS_PACKAGE', 'CP', 'CP - Your Packaging, ULE - UPS Letter, UT - UPS Tube, UBE - UPS Express Box', '6', '0', now())"); 132 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Residential Delivery?', 'MODULE_SHIPPING_UPS_RES', 'RES', 'Quote for Residential (RES) or Commercial Delivery (COM)', '6', '0', now())"); 133 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_UPS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())"); 134 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_UPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())"); 135 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_UPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); 136 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_SHIPPING_UPS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())"); 137 } 138 139 function remove() { 140 tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); 141 } 142 143 function keys() { 144 return array('MODULE_SHIPPING_UPS_STATUS', 'MODULE_SHIPPING_UPS_PICKUP', 'MODULE_SHIPPING_UPS_PACKAGE', 'MODULE_SHIPPING_UPS_RES', 'MODULE_SHIPPING_UPS_HANDLING', 'MODULE_SHIPPING_UPS_TAX_CLASS', 'MODULE_SHIPPING_UPS_ZONE', 'MODULE_SHIPPING_UPS_SORT_ORDER'); 145 } 146 147 function _upsProduct($prod){ 148 $this->_upsProductCode = $prod; 149 } 150 151 function _upsOrigin($postal, $country){ 152 $this->_upsOriginPostalCode = $postal; 153 $this->_upsOriginCountryCode = $country; 154 } 155 156 function _upsDest($postal, $country){ 157 $postal = str_replace(' ', '', $postal); 158 159 if ($country == 'US') { 160 $this->_upsDestPostalCode = substr($postal, 0, 5); 161 } else { 162 $this->_upsDestPostalCode = $postal; 163 } 164 165 $this->_upsDestCountryCode = $country; 166 } 167 168 function _upsRate($foo) { 169 switch ($foo) { 170 case 'RDP': 171 $this->_upsRateCode = 'Regular+Daily+Pickup'; 172 break; 173 case 'OCA': 174 $this->_upsRateCode = 'On+Call+Air'; 175 break; 176 case 'OTP': 177 $this->_upsRateCode = 'One+Time+Pickup'; 178 break; 179 case 'LC': 180 $this->_upsRateCode = 'Letter+Center'; 181 break; 182 case 'CC': 183 $this->_upsRateCode = 'Customer+Counter'; 184 break; 185 } 186 } 187 188 function _upsContainer($foo) { 189 switch ($foo) { 190 case 'CP': // Customer Packaging 191 $this->_upsContainerCode = '00'; 192 break; 193 case 'ULE': // UPS Letter Envelope 194 $this->_upsContainerCode = '01'; 195 break; 196 case 'UT': // UPS Tube 197 $this->_upsContainerCode = '03'; 198 break; 199 case 'UEB': // UPS Express Box 200 $this->_upsContainerCode = '21'; 201 break; 202 case 'UW25': // UPS Worldwide 25 kilo 203 $this->_upsContainerCode = '24'; 204 break; 205 case 'UW10': // UPS Worldwide 10 kilo 206 $this->_upsContainerCode = '25'; 207 break; 208 } 209 } 210 211 function _upsWeight($foo) { 212 $this->_upsPackageWeight = $foo; 213 } 214 215 function _upsRescom($foo) { 216 switch ($foo) { 217 case 'RES': // Residential Address 218 $this->_upsResComCode = '1'; 219 break; 220 case 'COM': // Commercial Address 221 $this->_upsResComCode = '2'; 222 break; 223 } 224 } 225 226 function _upsAction($action) { 227 /* 3 - Single Quote 228 4 - All Available Quotes */ 229 230 $this->_upsActionCode = $action; 231 } 232 233 function _upsGetQuote() { 234 if (!isset($this->_upsActionCode)) $this->_upsActionCode = '4'; 235 236 $request = join('&', array('accept_UPS_license_agreement=yes', 237 '10_action=' . $this->_upsActionCode, 238 '13_product=' . $this->_upsProductCode, 239 '14_origCountry=' . $this->_upsOriginCountryCode, 240 '15_origPostal=' . $this->_upsOriginPostalCode, 241 '19_destPostal=' . $this->_upsDestPostalCode, 242 '22_destCountry=' . $this->_upsDestCountryCode, 243 '23_weight=' . $this->_upsPackageWeight, 244 '47_rate_chart=' . $this->_upsRateCode, 245 '48_container=' . $this->_upsContainerCode, 246 '49_residential=' . $this->_upsResComCode)); 247 $http = new httpClient(); 248 if ($http->Connect('www.ups.com', 80)) { 249 $http->addHeader('Host', 'www.ups.com'); 250 $http->addHeader('User-Agent', 'osCommerce'); 251 $http->addHeader('Connection', 'Close'); 252 253 if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) $body = $http->getBody(); 254 255 $http->Disconnect(); 256 } else { 257 return 'error'; 258 } 259 260 $body_array = explode("\n", $body); 261 262 $returnval = array(); 263 $errorret = 'error'; // only return error if NO rates returned 264 265 $n = sizeof($body_array); 266 for ($i=0; $i<$n; $i++) { 267 $result = explode('%', $body_array[$i]); 268 $errcode = substr($result[0], -1); 269 switch ($errcode) { 270 case 3: 271 if (is_array($returnval)) $returnval[] = array($result[1] => $result[8]); 272 break; 273 case 4: 274 if (is_array($returnval)) $returnval[] = array($result[1] => $result[8]); 275 break; 276 case 5: 277 $errorret = $result[1]; 278 break; 279 case 6: 280 if (is_array($returnval)) $returnval[] = array($result[3] => $result[10]); 281 break; 282 } 283 } 284 if (empty($returnval)) $returnval = $errorret; 285 286 return $returnval; 287 } 288 } 289 ?>
title
Description
Body
title
Description
Body
| Generated: Tue Nov 4 23:53:39 2003 | Hosted By :: AABox.com |
Cross-referenced by PHPXref 0.4 |