コード例 #1
0
function cw_import_chipstation_get_short_list_by_string($substring)
{
    $cookie = cw_import_chipstation_login();
    $get = array('name=Chipstation', 'op=ricerca_veloce', 'q=' . $substring);
    $products = cw_http_get_request('www.chipstation.it', '/modules.php', implode('&', $get), $cookie);
    return cw_import_chipstation_get_product_info($cookie, $products[1]);
}
コード例 #2
0
function cw_import_cosmos_el_get_short_list_by_string($substring)
{
    $cookie = cw_import_cosmos_el_login();
    $post = array('S1=', 'S2=' . $substring);
    $products = cw_http_get_request('www.cosmosel.it', '/Portale/Cosmos/B2B/it/AreaRiservata/ricerca.xml', implode('&', $post), $cookie);
    return cw_import_cosmos_el_get_product_info($cookie, $products[1]);
}
コード例 #3
0
function cw_import_esprinet_get_sections($substring)
{
    $sections = array();
    $cookie = cw_import_esprinet_login();
    $post = array('testo=' . $substring);
    $result_by_text = cw_http_get_request('it.esprinet.com', '/Area_Operativa/disponibilita/risultatiNew.asp', implode('&', $post), $cookie);
    preg_match_all('/<td><input.*value="(.*)".*<\\/td>.*<td>.*<a.*href="(.*)">(.*)<\\/a>.*<span.*>(.*)<\\/span>.*<\\/td>/Uims', $result_by_text[1], $fnd);
    if (is_array($fnd)) {
        foreach ($fnd[1] as $k => $v) {
            $sections[trim($v)] = array('code' => utf8_encode(trim($v)), 'title' => utf8_encode(trim($fnd[3][$k])), 'url' => trim($fnd[2][$k]), 'amount' => trim($fnd[4][$k]));
        }
    }
    return $sections;
}
コード例 #4
0
function cw_license_api($command, $params = array())
{
    global $app_config_file;
    cw_load('http');
    $params['target'] = 'license_server';
    $params['mode'] = $command;
    $params['license'] = cw_license_id();
    $params['domain'] = $app_config_file['web']['http_host'];
    foreach ($params as $k => $v) {
        $param .= '&' . urlencode($k) . "=" . urlencode($v);
    }
    // return array(0=>head, 1=>body, 2=>cookie)
    $return = cw_http_get_request(SERVICE_SERVER, SERVICE_SERVER_SCRIPT, $param);
    $return = unserialize(trim($return[1]));
    return $return;
}
コード例 #5
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);
        }
    }
}
コード例 #6
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;
}
コード例 #7
0
    cw_flush("\n");
    if (!defined('IS_CRON')) {
        echo '<br />';
    }
    cw_add_top_message(cw_get_langvar_by_name('msg_sitemap_xml', null, false, true));
    if ($config['sitemap_xml']['sm_ping_google'] == 'Y') {
        /* Ping Google to update sitemaps
           http://www.google.com/support/webmasters/bin/answer.py?answer=183669
           */
        cw_flush('Sending update request: ' . 'www.google.com' . '/webmasters/tools/ping' . '?sitemap=' . urlencode($http_location . '/' . $_filename));
        cw_flush("\n");
        if (!defined('IS_CRON')) {
            echo '<br />';
        }
        cw_load('http');
        list($header, $body) = cw_http_get_request('www.google.com', '/webmasters/tools/ping', 'sitemap=' . urlencode($http_location . '/' . $_filename));
        $msg = "\nGoogle response:\n" . $body;
        if (!defined('IS_CRON')) {
            $msg = '<br /><br />' . $msg;
        }
        echo $msg;
        cw_add_top_message($msg);
    }
    $success_msg = "Sitemap XML <a href='{$http_location}/{$_filename}'>file</a> updated";
    cw_call('cw_system_messages_add', array('sitemap_xml', $success_msg, SYSTEM_MESSAGE_COMMON, SYSTEM_MESSAGE_INFO));
} else {
    $msg = cw_get_langvar_by_name('msg_err_file_permission_denied', null, false, true);
    echo $msg;
    echo "<br />File: {$_filename}<br />";
    cw_add_top_message($msg, 'E');
    $warn_msg = "Sitemap XML. <acronym title='{$_filename}'>" . cw_get_langvar_by_name('msg_err_file_permission_denied') . '</acronym>';
コード例 #8
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="******">
<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))
    }
}