[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/modules/shipping/ -> fedex1.php (source)

   1  <?php
   2  /*

   3    Version 2.04 for MS2 and earlier

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax2002, 2003 Steve Fatula of Fatula Consulting

   9    [email protected]

  10  

  11    Released under the GNU General Public License

  12  */
  13  
  14  
  15    class fedex1 {
  16      var $code, $title, $description, $sort_order, $icon, $tax_class, $enabled, $meter, $intl;
  17  
  18  // class constructor

  19      function fedex1() {
  20        $this->code = 'fedex1';
  21        $this->title = MODULE_SHIPPING_FEDEX1_TEXT_TITLE;
  22        $this->description = MODULE_SHIPPING_FEDEX1_TEXT_DESCRIPTION;
  23        $this->sort_order = MODULE_SHIPPING_FEDEX1_SORT_ORDER;
  24        $this->icon = DIR_WS_ICONS . 'shipping_fedex.gif';
  25        $this->tax_class = MODULE_SHIPPING_FEDEX1_TAX_CLASS;
  26        $this->enabled = ((MODULE_SHIPPING_FEDEX1_STATUS == 'True') ? true : false);
  27        $this->meter = MODULE_SHIPPING_FEDEX1_METER;
  28  
  29  
  30  // You can comment out any methods you do not wish to quote by placing a // at the beginning of that line

  31  // If you comment out 92 in either domestic or international, be

  32  // sure and remove the trailing comma on the last non-commented line

  33        $this->domestic_types = array(
  34               '01' => 'Priority (by 10:30AM, later for rural)',
  35               '03' => '2 Day Air',
  36               '05' => 'Standard Overnight (by 3PM, later for rural)',
  37               '06' => 'First Overnight', 
  38               '20' => 'Express Saver (3 Day)',
  39               '90' => 'Home Delivery',
  40               '92' => 'Ground Service'
  41               );
  42  
  43        $this->international_types = array(
  44               '01' => 'International Priority (1-3 Days)',
  45               '03' => 'International Economy (4-5 Days)',
  46               '06' => 'International First',
  47               '90' => 'Home Delivery',
  48               '92' => 'Ground Service'
  49               );
  50      }
  51  
  52  // class methods

  53      function quote($method = '') {
  54        global $shipping_weight, $shipping_num_boxes, $cart, $order;
  55  
  56        if (tep_not_null($method)) {
  57          $this->_setService($method);
  58        }
  59  
  60        if (MODULE_SHIPPING_FEDEX1_ENVELOPE == 'True') {
  61          if ( ($shipping_weight <= .5 && MODULE_SHIPPING_FEDEX1_WEIGHT == 'LBS') ||
  62               ($shipping_weight <= .2 && MODULE_SHIPPING_FEDEX1_WEIGHT == 'KGS')) {
  63            $this->_setPackageType('06');
  64          } else {
  65            $this->_setPackageType('01');
  66          }
  67        } else {
  68          $this->_setPackageType('01');
  69        }
  70  
  71        if ($this->packageType == '01' && $shipping_weight < 1) {
  72          $this->_setWeight(1);
  73        } else {
  74          $this->_setWeight($shipping_weight);
  75        }
  76  
  77        $totals = $cart->show_total();
  78        $this->_setInsuranceValue($totals / $shipping_num_boxes);
  79  
  80        if (defined("SHIPPING_ORIGIN_COUNTRY")) {
  81          $countries_array = tep_get_countries(SHIPPING_ORIGIN_COUNTRY, true);
  82          $this->country = $countries_array['countries_iso_code_2'];
  83        } else {
  84          $this->country = STORE_ORIGIN_COUNTRY;
  85        }
  86  
  87        $fedexQuote = $this->_getQuote();
  88  
  89        if (is_array($fedexQuote)) {
  90          if (isset($fedexQuote['error'])) {
  91            $this->quotes = array('module' => $this->title,
  92                                  'error' => $fedexQuote['error']);
  93          } else {
  94            $this->quotes = array('id' => $this->code,
  95                                  'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . strtolower(MODULE_SHIPPING_FEDEX1_WEIGHT) . ')');
  96  
  97            $methods = array();
  98            foreach ($fedexQuote as $type => $cost) {
  99              $skip = FALSE;
 100              $this->surcharge = 0;
 101              if ($this->intl === FALSE) {
 102                if (strlen($type) > 2 && MODULE_SHIPPING_FEDEX1_TRANSIT == 'True') {
 103                  $service_descr = $this->domestic_types[substr($type,0,2)] . ' (' . substr($type,2,1) . ' days)';
 104                } else {
 105                  $service_descr = $this->domestic_types[substr($type,0,2)];
 106                }
 107                switch (substr($type,0,2)) {
 108                  case 90:
 109                    if ($order->delivery['company'] != '') {
 110                      $skip = TRUE;
 111                    }
 112                    break;
 113                  case 92:
 114                    if ($this->country == "CA") {
 115                      if ($order->delivery['company'] == '') {
 116                        $this->surcharge = MODULE_SHIPPING_FEDEX1_RESIDENTIAL;
 117                      }
 118                    } else {
 119                      if ($order->delivery['company'] == '') {
 120                        $skip = TRUE;
 121                      }
 122                    }
 123                    break;
 124                  default:
 125                    if ($this->country != "CA" && substr($type,0,2) < "90" && $order->delivery['company'] == '') {
 126                      $this->surcharge = MODULE_SHIPPING_FEDEX1_RESIDENTIAL;
 127                    }
 128                    break;
 129                }
 130              } else {
 131                if (strlen($type) > 2 && MODULE_SHIPPING_FEDEX1_TRANSIT == 'True') {
 132                  $service_descr = $this->international_types[substr($type,0,2)] . ' (' . substr($type,2,1) . ' days)';
 133                } else {
 134                  $service_descr = $this->international_types[substr($type,0,2)];
 135                }
 136              }
 137              if ($method) {
 138                if (substr($type,0,2) != $method) $skip = TRUE;
 139              }
 140              if (!$skip) {
 141                $methods[] = array('id' => substr($type,0,2),
 142                                   'title' => $service_descr,
 143                                   'cost' => (SHIPPING_HANDLING + MODULE_SHIPPING_FEDEX1_SURCHARGE + $this->surcharge + $cost) * $shipping_num_boxes);
 144              }
 145            }
 146  
 147            $this->quotes['methods'] = $methods;
 148  
 149            if ($this->tax_class > 0) {
 150              $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
 151            }
 152          }
 153        } else {
 154          $this->quotes = array('module' => $this->title,
 155                                'error' => 'An error occured with the fedex shipping calculations.<br>Fedex may not deliver to your country, or your postal code may be wrong.');
 156        }
 157  
 158        if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
 159  
 160        return $this->quotes;
 161      }
 162  
 163      function check() {
 164        if (!isset($this->_check)) {
 165          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FEDEX1_STATUS'");
 166          $this->_check = tep_db_num_rows($check_query);
 167        }
 168        return $this->_check;
 169      }
 170  
 171      function install() {
 172        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 Fedex Shipping', 'MODULE_SHIPPING_FEDEX1_STATUS', 'True', 'Do you want to offer Fedex shipping?', '6', '10', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 173        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 ('Display Transit Times', 'MODULE_SHIPPING_FEDEX1_TRANSIT', 'True', 'Do you want to show transit times for ground or home delivery rates?', '6', '10', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 174        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Your Fedex Account Number', 'MODULE_SHIPPING_FEDEX1_ACCOUNT', 'NONE', 'Enter the fedex Account Number assigned to you, required', '6', '11', now())");
 175        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Your Fedex Meter ID', 'MODULE_SHIPPING_FEDEX1_METER', 'NONE', 'Enter the Fedex MeterID assigned to you, set to NONE to obtain a new meter number', '6', '12', now())");
 176        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('cURL Path', 'MODULE_SHIPPING_FEDEX1_CURL', 'NONE', 'Enter the path to the cURL program, normally, leave this set to NONE to execute cURL using PHP', '6', '12', now())");
 177        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 ('Debug Mode', 'MODULE_SHIPPING_FEDEX1_DEBUG', 'False', 'Turn on Debug', '6', '19', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 178        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 ('Weight Units', 'MODULE_SHIPPING_FEDEX1_WEIGHT', 'LBS', 'Weight Units:', '6', '19', 'tep_cfg_select_option(array(\'LBS\', \'KGS\'), ', now())");
 179        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('First line of street address', 'MODULE_SHIPPING_FEDEX1_ADDRESS_1', 'NONE', 'Enter the first line of your ship from street address, required', '6', '13', now())");
 180        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Second line of street address', 'MODULE_SHIPPING_FEDEX1_ADDRESS_2', 'NONE', 'Enter the second line of your ship from street address, leave set to NONE if you do not need to specify a second line', '6', '14', now())");
 181        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('City name', 'MODULE_SHIPPING_FEDEX1_CITY', 'NONE', 'Enter the city name for the ship from street address, required', '6', '15', now())");
 182        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('State or Province name', 'MODULE_SHIPPING_FEDEX1_STATE', 'NONE', 'Enter the 2 letter state or province name for the ship from street address, required for Canada and US', '6', '16', now())");
 183        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Postal code', 'MODULE_SHIPPING_FEDEX1_POSTAL', 'NONE', 'Enter the postal code for the ship from street address, required', '6', '17', now())");
 184        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Phone number', 'MODULE_SHIPPING_FEDEX1_PHONE', 'NONE', 'Enter a contact phone number for your company, required', '6', '18', now())");
 185        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 ('Which server to use', 'MODULE_SHIPPING_FEDEX1_SERVER', 'production', 'You must have an account with Fedex', '6', '19', 'tep_cfg_select_option(array(\'test\', \'production\'), ', now())");
 186        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Drop off type', 'MODULE_SHIPPING_FEDEX1_DROPOFF', '1', 'Dropoff type (1 = Regular pickup, 2 = request courier, 3 = drop box, 4 = drop at BSC, 5 = drop at station)?', '6', '20', now())");
 187        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Fedex surcharge?', 'MODULE_SHIPPING_FEDEX1_SURCHARGE', '0', 'Surcharge amount to add to shipping charge?', '6', '21', now())");
 188        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 ('Show List Rates?', 'MODULE_SHIPPING_FEDEX1_LIST_RATES', 'False', 'Show LIST Rates?', '6', '21', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 189        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Residential surcharge?', 'MODULE_SHIPPING_FEDEX1_RESIDENTIAL', '0', 'Residential Surcharge (in addition to other surcharge) for Express packages within US, or ground packages within Canada?', '6', '21', now())");
 190        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Insurance?', 'MODULE_SHIPPING_FEDEX1_INSURE', 'NONE', 'Insure packages over what dollar amount?', '6', '22', now())");
 191        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 Envelope Rates?', 'MODULE_SHIPPING_FEDEX1_ENVELOPE', 'False', 'Do you want to offer Fedex Envelope rates? All items under 1/2 LB (.23KG) will quote using the envelope rate if True.', '6', '10', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 192        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 ('Sort rates: ', 'MODULE_SHIPPING_FEDEX1_WEIGHT_SORT', 'High to Low', 'Sort rates top to bottom: ', '6', '19', 'tep_cfg_select_option(array(\'High to Low\', \'Low to High\'), ', now())");
 193        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Timeout in Seconds', 'MODULE_SHIPPING_FEDEX1_TIMEOUT', 'NONE', 'Enter the maximum time in seconds you would wait for a rate request from Fedex? Leave NONE for default timeout.', '6', '22', now())");
 194        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_FEDEX1_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '23', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
 195        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', 'MODULE_SHIPPING_FEDEX1_SORT_ORDER', '0', 'Sort order of display.', '6', '24', now())");
 196      }
 197  
 198      function remove() {
 199        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 200      }
 201  
 202      function keys() {
 203        return array('MODULE_SHIPPING_FEDEX1_STATUS', 'MODULE_SHIPPING_FEDEX1_ACCOUNT', 'MODULE_SHIPPING_FEDEX1_METER', 'MODULE_SHIPPING_FEDEX1_CURL', 'MODULE_SHIPPING_FEDEX1_DEBUG', 'MODULE_SHIPPING_FEDEX1_WEIGHT', 'MODULE_SHIPPING_FEDEX1_SERVER', 'MODULE_SHIPPING_FEDEX1_ADDRESS_1', 'MODULE_SHIPPING_FEDEX1_ADDRESS_2', 'MODULE_SHIPPING_FEDEX1_CITY', 'MODULE_SHIPPING_FEDEX1_STATE', 'MODULE_SHIPPING_FEDEX1_POSTAL', 'MODULE_SHIPPING_FEDEX1_PHONE', 'MODULE_SHIPPING_FEDEX1_DROPOFF', 'MODULE_SHIPPING_FEDEX1_TRANSIT', 'MODULE_SHIPPING_FEDEX1_SURCHARGE', 'MODULE_SHIPPING_FEDEX1_LIST_RATES', 'MODULE_SHIPPING_FEDEX1_INSURE', 'MODULE_SHIPPING_FEDEX1_RESIDENTIAL', 'MODULE_SHIPPING_FEDEX1_ENVELOPE', 'MODULE_SHIPPING_FEDEX1_WEIGHT_SORT', 'MODULE_SHIPPING_FEDEX1_TIMEOUT', 'MODULE_SHIPPING_FEDEX1_TAX_CLASS','MODULE_SHIPPING_FEDEX1_SORT_ORDER');
 204      }
 205  
 206      function _setService($service) {
 207        $this->service = $service;
 208      }
 209  
 210      function _setWeight($pounds) {
 211        $this->pounds = sprintf("%01.1f", $pounds);
 212      }
 213  
 214      function _setPackageType($type) {
 215        $this->packageType = $type;
 216      }
 217  
 218      function _setInsuranceValue($order_amount) {
 219        if ($order_amount > MODULE_SHIPPING_FEDEX1_INSURE) {
 220          $this->insurance = sprintf("%01.2f",$order_amount);
 221        } else {
 222          $this->insurance = 0;
 223        }
 224      }
 225  
 226      function _AccessFedex($data) {
 227  
 228        if (MODULE_SHIPPING_FEDEX1_SERVER == 'production') {
 229          $this->server = 'gateway.fedex.com/GatewayDC';
 230        } else {
 231          $this->server = 'gatewaybeta.fedex.com/GatewayDC';
 232        }
 233        if (MODULE_SHIPPING_FEDEX1_CURL == "NONE") {
 234          $ch = curl_init();
 235          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 236          curl_setopt($ch, CURLOPT_URL, 'https://' . $this->server);
 237          if (MODULE_SHIPPING_FEDEX1_TIMEOUT != 'NONE') curl_setopt($ch, CURLOPT_TIMEOUT, MODULE_SHIPPING_FEDEX1_TIMEOUT);
 238          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 239          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 240          curl_setopt($ch, CURLOPT_HTTPHEADER, array("Referer: " . STORE_NAME,
 241                                                     "Host: " . $this->server,
 242                                                     "Accept: image/gif,image/jpeg,image/pjpeg,text/plain,text/html,*/*",

 243                                                     "Pragma:",

 244                                                     "Content-Type:image/gif"));

 245          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

 246          $reply = curl_exec($ch);

 247          curl_close ($ch);

 248        } else {

 249          $this->command_line = MODULE_SHIPPING_FEDEX1_CURL . " " . (MODULE_SHIPPING_FEDEX1_TIMEOUT == 'NONE' ? '' : '-m ' . MODULE_SHIPPING_FEDEX1_TIMEOUT) . " -s -e '" . STORE_NAME . "' --url https://" . $this->server . " -H 'Host: " . $this->server . "' -H 'Accept: image/gif,image/jpeg,image/pjpeg,text/plain,text/html,*/*' -H 'Pragma:' -H 'Content-Type:image/gif' -d '" . $data . "' 'https://" . $this->server . "'";
 250          exec($this->command_line, $this->reply);
 251          $reply = $this->reply[0];
 252        }
 253          return $reply;
 254      }
 255  
 256      function _getMeter() {
 257        $data = '0,"211"'; // Transaction Code, required

 258        $data .= '10,"' . MODULE_SHIPPING_FEDEX1_ACCOUNT . '"'; // Sender Fedex account number

 259        $data .= '4003,"' . STORE_OWNER . '"'; // Subscriber contact name

 260        $data .= '4007,"' . STORE_NAME . '"'; // Subscriber company name

 261        $data .= '4008,"' . MODULE_SHIPPING_FEDEX1_ADDRESS_1 . '"'; // Subscriber Address line 1

 262        if (MODULE_SHIPPING_FEDEX1_ADDRESS_2 != 'NONE') {
 263          $data .= '4009,"' . MODULE_SHIPPING_FEDEX1_ADDRESS_2 . '"'; // Subscriber Address Line 2

 264        }
 265        $data .= '4011,"' . MODULE_SHIPPING_FEDEX1_CITY . '"'; // Subscriber City Name

 266        if (MODULE_SHIPPING_FEDEX1_STATE != 'NONE') {
 267          $data .= '4012,"' . MODULE_SHIPPING_FEDEX1_STATE . '"'; // Subscriber State code

 268        }
 269        $data .= '4013,"' . MODULE_SHIPPING_FEDEX1_POSTAL . '"'; // Subscriber Postal Code

 270        $data .= '4014,"' . $this->country . '"'; // Subscriber Country Code

 271        $data .= '4015,"' . MODULE_SHIPPING_FEDEX1_PHONE . '"'; // Subscriber phone number

 272        $data .= '99,""'; // End of Record, required

 273        if (MODULE_SHIPPING_FEDEX1_DEBUG == 'True') echo "Data sent to Fedex for Meter: " . $data . "<br>";
 274        $fedexData = $this->_AccessFedex($data);
 275        if (MODULE_SHIPPING_FEDEX1_DEBUG == 'True') echo "Data returned from Fedex for Meter: " . $fedexData . "<br>";
 276        $meterStart = strpos($fedexData,'"498,"');
 277  
 278        if ($meterStart === FALSE) {
 279          if (strlen($fedexData) == 0) {
 280            $this->error_message = 'No response to CURL from Fedex server, check CURL availability, or maybe timeout was set too low, or maybe the Fedex site is down';
 281          } else {
 282            $fedexData = $this->_ParseFedex($fedexData);
 283            $this->error_message = 'No meter number was obtained, check configuration. Error ' . $fedexData['2'] . ' : ' . $fedexData['3'];
 284          }
 285          return false;
 286        }
 287      
 288        $meterStart += 6;
 289        $meterEnd = strpos($fedexData, '"', $meterStart);
 290        $this->meter = substr($fedexData, $meterStart, $meterEnd - $meterStart);
 291        $meter_sql = "UPDATE configuration SET configuration_value=\"" . $this->meter . "\" where configuration_key=\"MODULE_SHIPPING_FEDEX1_METER\"";
 292        tep_db_query($meter_sql);
 293  
 294        return true;
 295      }
 296  
 297      function _ParseFedex($data) {
 298        $current = 0;
 299        $length = strlen($data);
 300        $resultArray = array();
 301        while ($current < $length) {
 302          $endpos = strpos($data, ',', $current);
 303          if ($endpos === FALSE) { break; }
 304          $index = substr($data, $current, $endpos - $current);
 305          $current = $endpos + 2;
 306          $endpos = strpos($data, '"', $current);
 307          $resultArray[$index] = substr($data, $current, $endpos - $current);
 308          $current = $endpos + 1;
 309        }
 310      return $resultArray;
 311      }
 312       
 313      function _getQuote() {
 314        global $order, $customer_id, $sendto;
 315  
 316        if (MODULE_SHIPPING_FEDEX1_ACCOUNT == "NONE" || strlen(MODULE_SHIPPING_FEDEX1_ACCOUNT) == 0) {
 317          return array('error' => 'You forgot to set up your Fedex account number, this can be set up in Admin -> Modules -> Shipping');
 318        }
 319        if (MODULE_SHIPPING_FEDEX1_ADDRESS_1 == "NONE" || strlen(MODULE_SHIPPING_FEDEX1_ADDRESS_1) == 0) {
 320          return array('error' => 'You forgot to set up your ship from street address line 1, this can be set up in Admin -> Modules -> Shipping');
 321        }
 322        if (MODULE_SHIPPING_FEDEX1_CITY == "NONE" || strlen(MODULE_SHIPPING_FEDEX1_CITY) == 0) {
 323          return array('error' => 'You forgot to set up your ship from City, this can be set up in Admin -> Modules -> Shipping');
 324        }
 325        if (MODULE_SHIPPING_FEDEX1_POSTAL == "NONE" || strlen(MODULE_SHIPPING_FEDEX1_POSTAL) == 0) {
 326          return array('error' => 'You forgot to set up your ship from postal code, this can be set up in Admin -> Modules -> Shipping');
 327        }
 328        if (MODULE_SHIPPING_FEDEX1_PHONE == "NONE" || strlen(MODULE_SHIPPING_FEDEX1_PHONE) == 0) {
 329          return array('error' => 'You forgot to set up your ship from phone number, this can be set up in Admin -> Modules -> Shipping');
 330        }
 331        if (MODULE_SHIPPING_FEDEX1_METER == "NONE") { 
 332          if ($this->_getMeter() === false) return array('error' => $this->error_message);
 333        }
 334  
 335        $data = '0,"25"'; // TransactionCode

 336        $data .= '10,"' . MODULE_SHIPPING_FEDEX1_ACCOUNT . '"'; // Sender fedex account number

 337        $data .= '498,"' . $this->meter . '"'; // Meter number

 338        $data .= '8,"' . MODULE_SHIPPING_FEDEX1_STATE . '"'; // Sender state code

 339        $orig_zip = str_replace(array(' ', '-'), '', MODULE_SHIPPING_FEDEX1_POSTAL);
 340        $data .= '9,"' . $orig_zip . '"'; // Origin postal code

 341        $data .= '117,"' . $this->country . '"'; // Origin country

 342        $dest_zip = str_replace(array(' ', '-'), '', $order->delivery['postcode']);
 343        $data .= '17,"' . $dest_zip . '"'; // Recipient zip code

 344        if ($order->delivery['country']['iso_code_2'] == "US" || $order->delivery['country']['iso_code_2'] == "CA" || $order->delivery['country']['iso_code_2'] == "PR") {
 345          $state .= tep_get_zone_code($order->delivery['country']['id'], $order->delivery['zone_id'], ''); // Recipient state

 346          if ($state == "QC") $state = "PQ";
 347          $data .= '16,"' . $state . '"'; // Recipient state

 348        }
 349        $data .= '50,"' . $order->delivery['country']['iso_code_2'] . '"'; // Recipient country

 350        $data .= '75,"' . MODULE_SHIPPING_FEDEX1_WEIGHT . '"'; // Weight units

 351        if (MODULE_SHIPPING_FEDEX1_WEIGHT == "KGS") {
 352          $data .= '1116,"C"'; // Dimension units

 353        } else {
 354          $data .= '1116,"I"'; // Dimension units

 355        }
 356        $data .= '1401,"' . $this->pounds . '"'; // Total weight

 357        $data .= '1529,"1"'; // Quote discounted rates

 358        if ($this->insurance > 0) {
 359          $data .= '1415,"' . $this->insurance . '"'; // Insurance value

 360          $data .= '68,"USD"'; // Insurance value currency

 361        }
 362        if ($order->delivery['company'] == '' && MODULE_SHIPPING_FEDEX1_RESIDENTIAL == 0) {
 363          $data .= '440,"Y"'; // Residential address

 364        }else {
 365          $data .= '440,"N"'; // Business address, use if adding a residential surcharge

 366        }
 367        $data .= '1273,"' . $this->packageType . '"'; // Package type

 368        $data .= '1333,"' . MODULE_SHIPPING_FEDEX1_DROPOFF . '"'; // Drop of drop off or pickup

 369        if (MODULE_SHIPPING_FEDEX1_LIST_RATES == 'True') {
 370          $data .= '1529,"2"'; // Also return list rates

 371        }
 372        $data .= '99,""'; // End of record

 373        if (MODULE_SHIPPING_FEDEX1_DEBUG == 'True') echo "Data sent to Fedex for Rating: " . $data . "<br>";
 374        $fedexData = $this->_AccessFedex($data);
 375        if (MODULE_SHIPPING_FEDEX1_DEBUG == 'True') echo "Data returned from Fedex for Rating: " . $fedexData . "<br>";
 376        if (strlen($fedexData) == 0) {
 377          $this->error_message = 'No data returned from Fedex, perhaps the Fedex site is down';
 378          return array('error' => $this->error_message);
 379        }
 380        $fedexData = $this->_ParseFedex($fedexData);
 381        $i = 1;
 382        if ($this->country == $order->delivery['country']['iso_code_2']) {
 383          $this->intl = FALSE;
 384        } else {
 385          $this->intl = TRUE;
 386        }
 387        $rates = NULL;
 388        while (isset($fedexData['1274-' . $i])) {
 389          if ($this->intl) {
 390            if (isset($this->international_types[$fedexData['1274-' . $i]])) {
 391              if (MODULE_SHIPPING_FEDEX1_LIST_RATES == 'False') {
 392                if (isset($fedexData['3058-' . $i])) {
 393                  $rates[$fedexData['1274-' . $i] . $fedexData['3058-' . $i]] = $fedexData['1419-' . $i];
 394                } else {
 395                  $rates[$fedexData['1274-' . $i]] = $fedexData['1419-' . $i];
 396                }
 397              } else {
 398                if (isset($fedexData['3058-' . $i])) {
 399                  $rates[$fedexData['1274-' . $i] . $fedexData['3058-' . $i]] = $fedexData['1528-' . $i];
 400                } else {
 401                  $rates[$fedexData['1274-' . $i]] = $fedexData['1528-' . $i];
 402                }
 403              }
 404            }
 405          } else {
 406            if (isset($this->domestic_types[$fedexData['1274-' . $i]])) {
 407              if (MODULE_SHIPPING_FEDEX1_LIST_RATES == 'False') {
 408                if (isset($fedexData['3058-' . $i])) {
 409                  $rates[$fedexData['1274-' . $i] . $fedexData['3058-' . $i]] = $fedexData['1419-' . $i];
 410                } else {
 411                  $rates[$fedexData['1274-' . $i]] = $fedexData['1419-' . $i];
 412                }
 413              } else {
 414                if (isset($fedexData['3058-' . $i])) {
 415                  $rates[$fedexData['1274-' . $i] . $fedexData['3058-' . $i]] = $fedexData['1528-' . $i];
 416                } else {
 417                  $rates[$fedexData['1274-' . $i]] = $fedexData['1528-' . $i];
 418                }
 419              }
 420            }
 421          }
 422          $i++;
 423        }
 424  
 425        if (is_array($rates)) {
 426          if (MODULE_SHIPPING_FEDEX1_WEIGHT_SORT == 'Low to High') {
 427            asort($rates);
 428          } else {
 429            arsort($rates);
 430          }
 431        } else {
 432          $this->error_message = 'No Rates Returned, ' . $fedexData['2'] . ' : ' . $fedexData['3']; 
 433          return array('error' => $this->error_message);
 434        }
 435  
 436        return ((sizeof($rates) > 0) ? $rates : false);
 437      }
 438    }
 439  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7