function usps_shipping_methods() { /// this section of code needs to be tidied up and all references to "ereg" changed to "preg_match" or similar. global $wpdb; if (function_exists('curl_init')) { echo "<div id='usps_shipping_methods'>\n\r"; $dest = $_SESSION['delivery_country']; if ($dest == get_option('base_country')) { // $request = '<RateV3Request USERID="' . "221ALLEN1967" . '" PASSWORD="******"651AC00ZD570" . '">'; // $allowed_types = explode(", ", MODULE_SHIPPING_USPS_TYPES); // // while (list($key, $value) = each($this->types)) { // if ( !in_array($key, $allowed_types) ) continue; // // if ($key == 'FIRST CLASS'){ // $this->FirstClassMailType = '<FirstClassMailType>LETTER</FirstClassMailType>'; // } else { // $this->FirstClassMailType = ''; // } // // if ($key == 'PRIORITY'){ // $this->container = 'FLAT RATE ENVELOPE'; // } // // if ($key == 'EXPRESS'){ // $this->container = 'FLAT RATE ENVELOPE'; // } // // if ($key == 'PARCEL POST'){ // $this->container = 'REGULAR'; // $this->machinable = 'false'; // } // // $request .= '<Package ID="' . $services_count . '">' . // '<Service>' . $key . '</Service>' . // $this->FirstClassMailType . // '<ZipOrigination>' . SHIPPING_ORIGIN_ZIP . '</ZipOrigination>' . // '<ZipDestination>' . $dest_zip . '</ZipDestination>' . // '<Pounds>' . $this->pounds . '</Pounds>' . // '<Ounces>' . $this->ounces . '</Ounces>' . // '<Container>' . $this->container . '</Container>' . // '<Size>' . $this->size . '</Size>' . // '<Machinable>' . $this->machinable . '</Machinable>' . // '</Package>'; // // if ($transit) { // $transitreq = 'USERID="' . MODULE_SHIPPING_USPS_USERID . // '" PASSWORD="******">' . // '<OriginZip>' . STORE_ORIGIN_ZIP . '</OriginZip>' . // '<DestinationZip>' . $dest_zip . '</DestinationZip>'; // // switch ($key) { // case 'EXPRESS': $transreq[$key] = 'API=ExpressMail&XML=' . // urlencode( '<ExpressMailRequest ' . $transitreq . '</ExpressMailRequest>'); // break; // case 'PRIORITY': $transreq[$key] = 'API=PriorityMail&XML=' . // urlencode( '<PriorityMailRequest ' . $transitreq . '</PriorityMailRequest>'); // break; // case 'PARCEL': $transreq[$key] = 'API=StandardB&XML=' . // urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>'); // break; // default: $transreq[$key] = ''; // break; // } // } // // $services_count++; // } // $request .= '</RateV3Request>'; //'</RateRequest>'; //Changed by Greg Deeth April 30, 2008 // $request = 'API=RateV3&XML=' . urlencode($request); } else { $dest = $wpdb->get_var("SELECT country FROM " . $wpdb->prefix . "currency_list WHERE isocode='" . $dest . "'"); $weight = shopping_cart_total_weight(); $request = '<IntlRateRequest USERID="' . get_option('usps_user_id') . '" PASSWORD="******">' . '<Package ID="0">' . '<Pounds>' . $weight . '</Pounds>' . '<Ounces>' . '0' . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $dest . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } //$http = new httpClient(); $usps_server = 'production.shippingapis.com'; //'stg-production.shippingapis.com'; // or stg-secure.shippingapis.com //'production.shippingapis.com'; $api_dll = 'shippingapi.dll'; //'shippingapi.dll'; //if ($http->Connect($usps_server, 80)) { $url = 'http://' . $usps_server . '/' . $api_dll . '?' . $request; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_NOPROGRESS, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_USERAGENT, 'osCommerce'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $body = curl_exec($ch); //$error = curl_error($ch); curl_close($ch); // $http->addHeader('Host', $usps_server); // $http->addHeader('User-Agent', 'osCommerce'); // $http->addHeader('Connection', 'Close'); //if ($http->Get('/' . $api_dll . '?' . $request)) $body = $http->getBody(); // if ($transit && is_array($transreq) && ($order->delivery['country']['id'] == STORE_COUNTRY)) { // while (list($key, $value) = each($transreq)) { // if ($http->Get('/' . $api_dll . '?' . $value)) $transresp[$key] = $http->getBody(); // } // } //$http->Disconnect(); if ($body == '') { //return false; } $response = array(); while (true) { if ($start = strpos($body, '<Package ID=')) { $body = substr($body, $start); $end = strpos($body, '</Package>'); $response[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $rates = array(); if ($dest == get_option('base_country')) { if (sizeof($response) == '1') { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; //return array('error' => $number . ' - ' . $description); } } $n = sizeof($response); for ($i = 0; $i < $n; $i++) { if (strpos($response[$i], '<Rate>')) { $service = ereg('<MailService>(.*)</MailService>', $response[$i], $regs); $service = $regs[1]; $postage = ereg('<Rate>(.*)</Rate>', $response[$i], $regs); $postage = $regs[1]; $rates[] = array($service => $postage); if ($transit) { switch ($service) { case 'EXPRESS': $time = ereg('<MonFriCommitment>(.*)</MonFriCommitment>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = 'Estimated 1 - 2 ' . 'Days'; } else { $time = 'Tomorrow by ' . $time; } break; case 'PRIORITY': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = 'Estimated 1 - 3 ' . 'Days'; } elseif ($time == '1') { $time .= ' ' . 'Day'; } else { $time .= ' ' . 'Days'; } break; case 'PARCEL': $time = ereg('<Days>(.*)</Days>', $transresp[$service], $tregs); $time = $tregs[1]; if ($time == '' || $time == 'No Data') { $time = 'Estimated 2 - 9 ' . 'Days'; } elseif ($time == '1') { $time .= ' ' . 'Day'; } else { $time .= ' ' . 'Days'; } break; case 'First-Class Mail': $time = 'Estimated 1 - 5 ' . 'Days'; break; case 'MEDIA': $time = 'Estimated 2 - 9 ' . 'Days'; break; case 'BPM': $time = 'Estimated 2 - 9 ' . 'Days'; break; default: $time = ''; break; } if ($time != '') { $transittime[$service] = ': ' . $time . ''; } } } } } else { if (ereg('<Error>', $response[0])) { $number = ereg('<Number>(.*)</Number>', $response[0], $regs); $number = $regs[1]; $description = ereg('<Description>(.*)</Description>', $response[0], $regs); $description = $regs[1]; return array('error' => $number . ' - ' . $description); } else { $body = $response[0]; $services = array(); while (true) { if ($start = strpos($body, '<Service ID=')) { $body = substr($body, $start); $end = strpos($body, '</Service>'); $services[] = substr($body, 0, $end + 10); $body = substr($body, $end + 9); } else { break; } } $allowed_types = array('EXPRESS MAIL INT' => "Express Mail International (EMS)", 'EXPRESS MAIL INT FLAT RATE ENV' => "Express Mail International (EMS) Flat-Rate Envelope", 'PRIORITY MAIL INT' => "Priority Mail International", 'PRIORITY MAIL INT FLAT RATE ENV' => "Priority Mail International Flat-Rate Envelope", 'PRIORITY MAIL INT FLAT RATE BOX' => "Priority Mail International Flat-Rate Box", 'FIRST-CLASS MAIL INT' => "First Class Mail International Letters"); //foreach( explode(", ", MODULE_SHIPPING_USPS_TYPES_INTL) as $value ) $allowed_types[$value] = $this->intl_types[$value]; $size = sizeof($services); for ($i = 0, $n = $size; $i < $n; $i++) { if (strpos($services[$i], '<Postage>')) { $service = ereg('<SvcDescription>(.*)</SvcDescription>', $services[$i], $regs); $service = $regs[1]; $postage = ereg('<Postage>(.*)</Postage>', $services[$i], $regs); $postage = $regs[1]; $time = ereg('<SvcCommitments>(.*)</SvcCommitments>', $services[$i], $tregs); $time = $tregs[1]; $time = preg_replace('/Weeks$/', 'Weeks', $time); $time = preg_replace('/Days$/', 'Days', $time); $time = preg_replace('/Day$/', 'Day', $time); if (!in_array($service, $allowed_types)) { continue; } // if (isset($this->service) && ($service != $this->service) ) { // continue; // } $rates[] = array($service => $postage); if ($time != '') { $transittime[$service] = ' (' . $time . ')'; } } } $uspsQuote = $rates; } } // usps changes ends echo "</div>"; } }
function nzshpcrt_determine_base_shipping($per_item_shipping, $country_code) { global $wpdb, $wpsc_shipping_modules; $custom_shipping = get_option('custom_shipping_options'); if (get_option('do_not_use_shipping') != 1 && count($custom_shipping) > 0) { if (array_search($_SESSION['quote_shipping_method'], (array) $custom_shipping) === false) { //unset($_SESSION['quote_shipping_method']); } $shipping_quotes = null; if ($_SESSION['quote_shipping_method'] != null) { // use the selected shipping module $shipping_quotes = $wpsc_shipping_modules[$_SESSION['quote_shipping_method']]->getQuote(); } else { // otherwise select the first one with any quotes foreach ((array) $custom_shipping as $shipping_module) { // if the shipping module does not require a weight, or requires one and the weight is larger than zero if ($custom_shipping[$shipping_module]->requires_weight != true or $custom_shipping[$shipping_module]->requires_weight == true and shopping_cart_total_weight() > 0) { $_SESSION['quote_shipping_method'] = $shipping_module; $shipping_quotes = $wpsc_shipping_modules[$_SESSION['quote_shipping_method']]->getQuote(); if (count($shipping_quotes) > 0) { // if we have any shipping quotes, break the loop. break; } } } } //echo "<pre>".print_r($_SESSION['quote_shipping_method'],true)."</pre>"; if (count($shipping_quotes) < 1) { $_SESSION['quote_shipping_option'] = ''; } if ($_SESSION['quote_shipping_option'] == null && $shipping_quotes != null) { $_SESSION['quote_shipping_option'] = array_pop(array_keys(array_slice($shipping_quotes, 0, 1))); } foreach ((array) $shipping_quotes as $shipping_quote) { foreach ((array) $shipping_quote as $key => $quote) { if ($key == $_SESSION['quote_shipping_option']) { $shipping = $quote; } } } } else { $shipping = 0; } return $shipping; }
// break; // case 'PARCEL': $transreq[$key] = 'API=StandardB&XML=' . // urlencode( '<StandardBRequest ' . $transitreq . '</StandardBRequest>'); // break; // default: $transreq[$key] = ''; // break; // } // } // // $services_count++; // } // $request .= '</RateV3Request>'; //'</RateRequest>'; //Changed by Greg Deeth April 30, 2008 // $request = 'API=RateV3&XML=' . urlencode($request); } else { $dest = $wpdb->get_var("SELECT country FROM " . $wpdb->prefix . "currency_list WHERE isocode='" . $dest . "'"); $weight = shopping_cart_total_weight(); $request = '<IntlRateRequest USERID="' . get_option('usps_user_id') . '" PASSWORD="******">' . '<Package ID="0">' . '<Pounds>' . $weight . '</Pounds>' . '<Ounces>' . '0' . '</Ounces>' . '<MailType>Package</MailType>' . '<Country>' . $dest . '</Country>' . '</Package>' . '</IntlRateRequest>'; $request = 'API=IntlRate&XML=' . urlencode($request); } //$http = new httpClient(); $usps_server = 'production.shippingapis.com'; //'stg-production.shippingapis.com'; // or stg-secure.shippingapis.com //'production.shippingapis.com'; $api_dll = 'shippingapi.dll'; //'shippingapi.dll'; //if ($http->Connect($usps_server, 80)) { $url = 'http://' . $usps_server . '/' . $api_dll . '?' . $request; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_NOPROGRESS, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); //curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);