コード例 #1
0
function cw_shipper_AP($weight, $customer_id, $address, $debug, $cart)
{
    global $config, $tables;
    if ($config['Company']['country'] != 'AU' || !is_array($allowed_shipping_methods) || empty($allowed_shipping_methods)) {
        return false;
    }
    $stypes = array(1001 => "STANDARD", 1002 => "EXPRESS", 1003 => "AIR", 1005 => "SEA", 1006 => "ECI_D", 1007 => "ECI_M", 1008 => "EPI");
    $ap_host = "drc.edeliver.com.au";
    $ap_url = "/ratecalc.asp";
    $zipcode = preg_replace("|[^\\d\\w]|i", "", $address['zipcode']);
    $post = "Pickup_Postcode=" . $config['Company']['zipcode'] . "&Destination_Postcode=" . $zipcode . "&Country=" . $address['country'] . "&Weight=" . cw_weight_in_grams($weight) . "&Length=" . $options['param00'] . "&Width=" . $options['param01'] . "&Height=" . $options['param02'] . "&Quantity=1";
    if ($debug == "Y") {
        # Display debug info (header)
        print "<h1>Australia Post Debug Information</h1>";
        $is_display_debug = false;
    }
    foreach ($allowed_shipping_methods as $value) {
        if ($value['code'] != "APOST" || !isset($stypes[$value['service_code']])) {
            continue;
        }
        if ($address['country'] != 'AU' && $value['destination'] == "L" || $address['country'] == 'AU' && $value['destination'] == "I") {
            continue;
        }
        $md5_request = md5($post . $stypes[$value['service_code']]);
        if (!cw_is_shipping_result_in_cache($md5_request) || $debug == "Y") {
            list($header, $result) = cw_http_get_request($ap_host, $ap_url, $post . "&Service_type=" . $stypes[$value['service_code']]);
            if (empty($result)) {
                continue;
            }
            $return = array();
            if (preg_match_all("/^([^=]+)=(.*)\$/Sm", $result, $preg)) {
                foreach ($preg[1] as $k => $v) {
                    $return[$v] = trim($preg[2][$k]);
                }
            }
            if ($return['err_msg'] == "OK") {
                $rates[$value['subcode']] = array("methodid" => $value['subcode'], "rate" => $return['charge'], "shipping_time" => $return['days']);
                $cached_value = array("methodid" => $value['subcode'], "rate" => $return['charge'], "shipping_time" => $return['days']);
                if ($debug != "Y") {
                    cw_save_shipping_result_to_cache($md5_request, $cached_value);
                }
            }
        } else {
            $rates[] = cw_get_shipping_result_from_cache($md5_request);
        }
    }
}
コード例 #2
0
function cw_shipper($weight, $address, $debug = "N", $cart = false)
{
    global $allowed_shipping_methods, $rates;
    global $tables;
    global $config;
    $__intershipper_userinfo = $address;
    $rates = array();
    $intershipper_countries = array('IE' => 'IR', 'VA' => 'IT', 'FX' => 'FR', 'PR' => 'US');
    #
    # Intershipper depends on XML parser (EXPAT extension)
    #
    if (test_expat() == "") {
        return;
    }
    if (empty($address)) {
        if ($config['General']['apply_default_country'] == "Y" || $debug == "Y") {
            $__intershipper_userinfo = cw_user_get_default_address();
        } else {
            return array();
        }
    }
    $pounds = cw_weight_in_grams($weight) / 453;
    $pounds = sprintf("%.2f", round((double) $pounds + 9.999999999999999E-12, 2));
    if ($pounds < 0.1) {
        $pounds = 0.1;
    }
    $servername = "www.intershipper.com";
    $scriptname = "/Shipping/Intershipper/XML/v2.0/HTTP.jsp";
    $username = $config['Shipping']['intershipper_username'];
    $password = $config['Shipping']['intershipper_password'];
    $delivery = $params['param00'];
    $shipmethod = $params['param01'];
    $CO = $config['Company']['country'];
    $ZO = urlencode($config['Company']['zipcode']);
    $CD = $__intershipper_userinfo['country'];
    $ZD = urlencode($__intershipper_userinfo['zipcode']);
    if (!empty($intershipper_countries[$CD])) {
        $CD = $intershipper_countries[$CD];
    }
    if (!empty($intershipper_countries[$CO])) {
        $CO = $intershipper_countries[$CO];
    }
    $__intershipper_userinfo['country'] = $CD;
    $config['Company']['country'] = $CO;
    $length = (double) $params['param02'];
    $width = (double) $params['param03'];
    $height = (double) $params['param04'];
    $dunit = $params['param05'];
    $packaging = $params['param06'];
    $contents = $params['param07'];
    $codvalue = (double) $params['param08'];
    $insvalue = (double) $params['param09'];
    $queryid = substr(uniqid(rand()), 0, 15);
    $wunit = strtoupper(trim($config['General']['weight_symbol']));
    if (strlen($wunit) > 2) {
        $wunit = substr($wunit, 0, 2);
    }
    $allowed_shipping_methods = cw_query("SELECT * FROM {$tables['shipping']} WHERE active=1");
    $carriers = cw_query_column("SELECT DISTINCT(code) FROM {$tables['shipping']} WHERE code<>'' AND intershipper_code!='' AND active=1");
    if (!$carriers || !$username || !$password) {
        return array();
    }
    $post[] = "Version=2.0.0.0";
    $post[] = "ShipmentID=1";
    $post[] = "QueryID=1";
    $post[] = "Username={$username}";
    $post[] = "Password={$password}";
    $post[] = "TotalClasses=4";
    $post[] = "ClassCode1=GND";
    $post[] = "ClassCode2=1DY";
    $post[] = "ClassCode3=2DY";
    $post[] = "ClassCode4=3DY";
    $post[] = "DeliveryType={$delivery}";
    $post[] = "ShipMethod={$shipmethod}";
    $post[] = "OriginationPostal={$ZO}";
    $post[] = "OriginationCountry={$CO}";
    $post[] = "DestinationPostal={$ZD}";
    $post[] = "DestinationCountry={$CD}";
    $post[] = "Currency=USD";
    // Currently, supported only "USD". maxlen=3
    $post[] = "TotalPackages=1";
    $post[] = "BoxID1=box1";
    $post[] = "Weight1={$pounds}";
    $post[] = "WeightUnit1=LB";
    $post[] = "Length1={$length}";
    $post[] = "Width1={$width}";
    $post[] = "Height1={$height}";
    $post[] = "DimensionalUnit1={$dunit}";
    // DimensionalUnit	::= CM | IN
    $post[] = "Packaging1={$packaging}";
    // Packaging		::= BOX | ENV | LTR | TUB
    $post[] = "Contents1={$contents}";
    $post[] = "Cod1={$codvalue}";
    $post[] = "Insurance1={$insvalue}";
    $post[] = "TotalCarriers=" . count($carriers);
    foreach ($carriers as $k => $v) {
        if ($v == 'CPC') {
            $v = 'CAN';
        }
        $post[] = "CarrierCode" . ($k + 1) . "=" . $v;
    }
    $query = join('&', $post);
    $md5_request = md5($query);
    if (cw_is_shipping_result_in_cache($md5_request) && $debug != "Y") {
        return cw_get_shipping_result_from_cache($md5_request);
    }
    list($header, $result) = cw_http_get_request($servername, $scriptname, $query);
    $result = preg_replace("/^<\\?xml\\s+[^>]+>/s", "", trim($result));
    $parse_errors = false;
    $options = array('XML_OPTION_CASE_FOLDING' => 1, 'XML_OPTION_TARGET_ENCODING' => 'ISO-8859-1');
    $parsed = cw_xml_parse($result, $parse_errors, $options);
    $destination = $__intershipper_userinfo['country'] == $config['Company']['country'] ? "L" : "I";
    $packages =& cw_array_path($parsed, 'SHIPMENT/PACKAGE');
    if (is_array($packages)) {
        $rates = array();
        foreach ($packages as $pkginfo) {
            if (empty($pkginfo['#']) || !is_array($pkginfo['#'])) {
                continue;
            }
            foreach ($pkginfo['#']['QUOTE'] as $quote) {
                $carrier = cw_array_path($quote, 'CARRIER/CODE/0/#');
                if ($carrier == 'USP') {
                    $carrier = 'USPS';
                }
                $service = cw_array_path($quote, 'SERVICE/NAME/0/#');
                $sn = cw_array_path($quote, 'SERVICE/CODE/0/#');
                $rate = cw_array_path($quote, 'RATE/AMOUNT/0/#') / 100.0;
                if (!$carrier || !($service || $sn) || !$rate) {
                    continue;
                }
                $saved = -1;
                foreach ($allowed_shipping_methods as $sk => $sv) {
                    if ($sv['code'] != $carrier || $sv['destination'] != $destination) {
                        continue;
                    }
                    if ($sv['intershipper_code'] == 'CPC') {
                        $sv['intershipper_code'] = 'CAN';
                    }
                    if ((!$sn || $sv['intershipper_code'] != $sn) && (!$service || !stristr($sv['shipping'], $service))) {
                        continue;
                    }
                    # Suppressing duplicates
                    if ($saved < 0 || strlen($allowed_shipping_methods[$saved]['shipping']) > strlen($sv['shipping'])) {
                        $saved = $sk;
                    }
                }
                if ($saved >= 0) {
                    $rates[$allowed_shipping_methods[$saved]['subcode']] = $rate;
                }
            }
        }
        if (!empty($rates)) {
            foreach ($rates as $k => $v) {
                $rates[$k] = array("methodid" => $k, "rate" => $v);
            }
            if ($debug != "Y") {
                cw_save_shipping_result_to_cache($md5_request, $rates);
            }
        }
    }
    return $rates;
}
コード例 #3
0
function ab_rate_estimate($ab_url, $ab_id, $ab_password, $debug, $req)
{
    $ab_request = <<<EOT
<?xml version='1.0'?>
<eCommerce action="Request" version="1.1">
\t<Requestor>
\t\t<ID>{$ab_id}</ID>
\t\t<Password>{$ab_password}</Password>
\t</Requestor>
\t{$req}
</eCommerce>
EOT;
    $post = preg_split("/(\r\n|\r|\n)/", $ab_request, -1, PREG_SPLIT_NO_EMPTY);
    $md5_request = md5($ab_request);
    $is_cached = cw_is_shipping_result_in_cache($md5_request);
    if (!$is_cached || $debug == "Y") {
        list($a, $ab_response) = cw_https_request("POST", $ab_url, $post, "", "", "text/xml");
        ab_parse_response($ab_response);
        if ($debug == "Y") {
            print "<h1>DHL/Airborne Debug Information</h1>";
            print "<h2>DHL/Airborne Request</h2>";
            print "<pre>" . htmlspecialchars(cw_arb_prepare_debug($ab_request)) . "</pre>";
            print "<h2>DHL/Airborne Response</h2>";
            print "<pre>" . htmlspecialchars(cw_arb_prepare_debug($ab_response)) . "</pre>";
        } else {
            cw_save_shipping_result_to_cache($md5_request, $rates);
        }
        if (!empty($mod_AB_faults)) {
            if ($debug == "Y") {
                ab_show_faults();
            }
            ab_conv_faults();
        }
    } else {
        $rates = cw_get_shipping_result_from_cache($md5_request);
    }
}
コード例 #4
0
function cw_shipper_CPC($weight, $customer_id, $address, $debug, $cart)
{
    global $config, $tables;
    if ($config['Company']['country'] != "CA" || empty($config['Shipping']['CPC_merchant_id'])) {
        return;
    }
    $cpc_methods = array();
    foreach ($allowed_shipping_methods as $v) {
        if ($v['code'] == "CPC") {
            $cpc_methods[] = $v;
        }
    }
    if (empty($cpc_methods)) {
        return;
    }
    $cp_merchant = $config['Shipping']['CPC_merchant_id'];
    $cp_language = "en";
    $cp_qnty = "1";
    $cp_packed = true;
    $cp_weight = round(cw_weight_in_grams($weight) / 1000, 3);
    if ($cp_weight < 0.1) {
        $cp_weight = 0.1;
    }
    $cp_description = $params['param00'];
    $cp_length = $params['param01'];
    $cp_width = $params['param02'];
    $cp_height = $params['param03'];
    $cp_currency_rate = $params['param05'];
    $cp_insured_value = $params['param04'];
    $cp_dest_country = $address['country'];
    $cp_dest_city = $address['city'];
    $cp_dest_zip = $address['zipcode'];
    $cp_dest_state = empty($address['state']) ? "NA" : $address['state'];
    $cp_orig_zip = $config['Company']['zipcode'];
    # Server DNS; if does not work, use 'cybervente.postescanada.ca:30000'
    $cp_host = "sellonline.canadapost.ca:30000";
    if (isset($cart['discounted_subtotal'])) {
        $itemsPrice = "<itemsPrice>{$cart['discounted_subtotal']}</itemsPrice>";
    } elseif (!empty($cp_insured_value)) {
        $itemsPrice = "<itemsPrice>{$cp_insured_value}</itemsPrice>";
    } else {
        $itemsPrice = "";
    }
    $cp_request = "<?xml version=\"1.0\" ?>\n" . "<eparcel>" . "<language>{$cp_language}</language>\n" . "<ratesAndServicesRequest>\n" . "  <merchantCPCID>{$cp_merchant}</merchantCPCID>\n" . "  <fromPostalCode>{$cp_orig_zip}</fromPostalCode>\n" . "  {$itemsPrice}\n" . "  <lineItems>\n" . "    <item>\n" . "      <quantity>{$cp_qnty}</quantity>\n" . "      <weight>{$cp_weight}</weight>\n" . "      <length>{$cp_length}</length>\n" . "      <width>{$cp_width}</width>\n" . "      <height>{$cp_height}</height>\n" . "      <description>{$cp_description}</description>\n" . ($cp_packed ? "      <readyToShip/>\n" : "") . "    </item>\n" . "  </lineItems>\n" . "  <city>{$cp_dest_city}</city>\n" . "  <provOrState>{$cp_dest_state}</provOrState>\n" . "  <country>{$cp_dest_country}</country>\n" . "  <postalCode>{$cp_dest_zip}</postalCode>\n" . "</ratesAndServicesRequest>\n" . "</eparcel>";
    $md5_request = md5($cp_request);
    if (!cw_is_shipping_result_in_cache($md5_request) || $debug == "Y") {
        list($a, $result) = cw_http_post_request($cp_host, "/", $cp_request);
        $parse_errors = false;
        $options = array('XML_OPTION_CASE_FOLDING' => 1, 'XML_OPTION_TARGET_ENCODING' => 'ISO-8859-1');
        $parsed = cw_xml_parse($result, $parse_errors, $options);
        $products =& cw_array_path($parsed, 'EPARCEL/RATESANDSERVICESRESPONSE/PRODUCT');
        if (is_array($products)) {
            foreach ($products as $product) {
                $pid = $product['@']['ID'];
                $rate = cw_array_path($product, 'RATE/0/#');
                if ($pid === false || $rate === false) {
                    continue;
                }
                $is_found = false;
                foreach ($cpc_methods as $v) {
                    if ($v['service_code'] == $pid) {
                        $rates[] = array("methodid" => $v['subcode'], "rate" => $rate * $cp_currency_rate);
                        $is_found = true;
                        break;
                    }
                }
                if (!empty($pid) && !$is_found) {
                    $tmp_name = cw_array_path($product, "NAME/0/#");
                    cw_add_new_smethod($tmp_name, "CPC", array("service_code" => $pid));
                }
            }
        }
        if ($debug != "Y") {
            cw_save_shipping_result_to_cache($md5_request, $rates);
        }
        $error_code = cw_array_path($parsed, 'EPARCEL/ERROR/STATUSCODE/0/#');
        if ($error_code !== false) {
            $error_msg = cw_array_path($parsed, 'EPARCEL/ERROR/STATUSMESSAGE/0/#');
        }
    } else {
        $rates = cw_get_shipping_result_from_cache($md5_request);
    }
}
コード例 #5
0
function cw_shipper_USPS($weight, $customer_id, $address, $debug, $cart)
{
    global $config, $tables, $current_language;
    $USPS_username = $config['Shipping']['USPS_username'];
    $USPS_password = $config['Shipping']['USPS_password'];
    $USPS_servername = $config['Shipping']['USPS_servername'];
    $use_usps_https = false;
    if (empty($USPS_username) || empty($USPS_servername)) {
        return;
    }
    $USPS_FOUND = false;
    if (is_array($allowed_shipping_methods)) {
        foreach ($allowed_shipping_methods as $key => $value) {
            if ($value['code'] == "USPS") {
                $USPS_FOUND = true;
                break;
            }
        }
    }
    if (!$USPS_FOUND) {
        return;
    }
    cw_load('http', 'xml');
    $pounds = 0;
    $ounces = ceil(round(cw_weight_in_grams($weight) / 28.35, 3));
    if ($ounces < 1) {
        $ounces = 1;
    }
    $mailtype = $params['param00'];
    $package_size = $params['param01'];
    $machinable = $params['param02'];
    $container_express = $params['param03'];
    $container_priority = $params['param04'];
    if (!empty($container_express) && $container_express != 'None') {
        $container_express = "<Container>" . $container_express . "</Container>";
    } else {
        $container_express = "";
    }
    if (!empty($container_priority) && $container_priority != 'None') {
        $container_priority = "<Container>" . $container_priority . "</Container>";
    } else {
        $container_priority = "";
    }
    if ($address['country'] == 'PR' || $address['country'] == 'GU' || $address['country'] == 'VI') {
        $address['country'] = 'US';
    }
    $dst_country = USPS_get_country($address['country']);
    if (empty($dst_country)) {
        $dst_country = cw_query_first_cell("SELECT value FROM {$tables['languages']} WHERE name = 'country_" . $address['country'] . "' AND code = '{$current_language}'");
    }
    $USPS_file = $USPS_servername == "testing.shippingapis.com" ? "/ShippingAPITest.dll" : "/ShippingAPI.dll";
    $hash = array();
    if ($address['country'] != $config['Company']['country']) {
        # International shipping
        $query = <<<EOT
<IntlRateRequest USERID="{$USPS_username}" PASSWORD="{$USPS_password}">
<Package ID="0">
<Pounds>{$pounds}</Pounds>
<Ounces>{$ounces}</Ounces>
<MailType>{$mailtype}</MailType>
<Country>{$dst_country}</Country>
</Package>
</IntlRateRequest>
EOT;
        $md5_request = md5($query);
        if (cw_is_shipping_result_in_cache($md5_request) && $debug != "Y") {
            $rates = cw_get_shipping_result_from_cache($md5_request);
            return;
        }
        if ($use_usps_https) {
            $post = array("API=IntlRate", "XML=" . urlencode($query));
            list($header, $result) = cw_https_request("GET", "https://" . $USPS_servername . ":443" . $USPS_file . "?API=IntlRate&XML=" . urlencode($query));
        } else {
            list($header, $result) = cw_http_get_request($USPS_servername, $USPS_file, "API=IntlRate&XML=" . urlencode($query));
        }
        $xml = cw_xml_parse($result, $err);
        # Get <Error> elemenet
        $err = cw_array_path($xml, "IntlRateResponse/Package/Error");
        if (empty($err)) {
            # Get <Service> elements
            $packages = cw_array_path($xml, "IntlRateResponse/Package/Service");
            if (!empty($packages) && is_array($packages)) {
                foreach ($packages as $p) {
                    # Get shipping method name
                    $sname = cw_array_path($p, "SvcDescription/0/#");
                    # Get rate
                    $rate = cw_array_path($p, "Postage/0/#");
                    # Get comment
                    #$comment = cw_array_path($p, "SvcCommitments/0/#");
                    if (empty($sname) || zerolen($rate)) {
                        continue;
                    }
                    # Define shipping method
                    $is_found = false;
                    foreach ($allowed_shipping_methods as $sm) {
                        if ($sm['code'] == "USPS" && $sm['destination'] == "I" && preg_match("/^" . preg_quote($sm['shipping'], "/") . "/S", "USPS " . $sname)) {
                            if (!in_array($sm['subcode'], $hash)) {
                                $rates[] = array("methodid" => $sm['subcode'], "rate" => $rate, "warning" => "");
                                $hash[] = $sm['subcode'];
                            }
                            $is_found = true;
                            break;
                        }
                    }
                    if (!$is_found) {
                        # Add new shipping method
                        cw_add_new_smethod("USPS " . $sname, "USPS", array("destination" => "I"));
                    }
                }
                if ($debug != "Y") {
                    cw_save_shipping_result_to_cache($md5_request, $rates);
                }
            }
        }
    } else {
        # Domestic shipping
        $ZO = $config['Company']['zipcode'];
        $ZD = $address['zipcode'];
        $query = <<<EOT
<RateV2Request USERID="{$USPS_username}">
\t<Package ID="0">
\t\t<Service>EXPRESS</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t{$container_express}
\t\t<Size>{$package_size}</Size>
\t</Package>
\t<Package ID="1">
\t\t<Service>FIRST CLASS</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t<Container>None</Container>
\t\t<Size>{$package_size}</Size>
\t</Package>
\t<Package ID="2">
\t\t<Service>PRIORITY</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t{$container_priority}
\t\t<Size>{$package_size}</Size>
\t</Package>
\t<Package ID="3">
\t\t<Service>PARCEL</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t<Container>None</Container>
\t\t<Size>{$package_size}</Size>
\t\t<Machinable>{$machinable}</Machinable>
\t</Package>
\t<Package ID="4">
\t\t<Service>BPM</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t<Container>None</Container>
\t\t<Size>{$package_size}</Size>
\t</Package>
\t<Package ID="5">
\t\t<Service>LIBRARY</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t<Container>None</Container>
\t\t<Size>{$package_size}</Size>
\t</Package>
\t<Package ID="6">
\t\t<Service>MEDIA</Service>
\t\t<ZipOrigination>{$ZO}</ZipOrigination>
\t\t<ZipDestination>{$ZD}</ZipDestination>
\t\t<Pounds>{$pounds}</Pounds>
\t\t<Ounces>{$ounces}</Ounces>
\t\t<Container>None</Container>
\t\t<Size>{$package_size}</Size>
\t</Package>
</RateV2Request>
EOT;
        $md5_request = md5($query);
        if (cw_is_shipping_result_in_cache($md5_request) && $debug != "Y") {
            $rates = cw_get_shipping_result_from_cache($md5_request);
            return;
        }
        if ($use_usps_https) {
            $post = array("API=RateV2", "XML=" . urlencode($query));
            list($header, $result) = cw_https_request("GET", "https://" . $USPS_servername . ":443" . $USPS_file . "?API=RateV2&XML=" . urlencode($query));
        } else {
            list($header, $result) = cw_http_get_request($USPS_servername, $USPS_file, "API=RateV2&XML=" . urlencode($query));
        }
        $xml = cw_xml_parse($result, $err);
        # Get <Package> elements
        $packages = cw_array_path($xml, "RateV2Response/Package");
        if (is_array($packages)) {
            foreach ($packages as $p) {
                # Get <Error> element
                $err = cw_array_path($p, "Error");
                if (!empty($err)) {
                    continue;
                }
                # Get shipping method name
                $sname = cw_array_path($p, "Postage/MailService/0/#");
                # Get rate
                $rate = cw_array_path($p, "Postage/Rate/0/#");
                if (empty($sname) || zerolen($rate)) {
                    continue;
                }
                # Define shipping method
                $is_found = false;
                foreach ($allowed_shipping_methods as $sm) {
                    if ($sm['code'] == "USPS" && $sm['destination'] == "L" && preg_match("/^" . preg_quote($sm['shipping'], "/") . "/S", "USPS " . $sname)) {
                        if (!in_array($sm['subcode'], $hash)) {
                            $rates[] = array("methodid" => $sm['subcode'], "rate" => $rate, "warning" => "");
                            $hash[] = $sm['subcode'];
                        }
                        $is_found = true;
                        break;
                    }
                }
                if (!$is_found) {
                    # Add new shipping method
                    cw_add_new_smethod("USPS " . $sname, "USPS", array("destination" => "L"));
                }
            }
            if ($debug != "Y") {
                cw_save_shipping_result_to_cache($md5_request, $rates);
            }
        }
        // if (is_array($packages))
    }
}