Example #1
0
 /** 
  * Echos a formatted list of shipping rates.
  * 
  * @param array $d
  * @return boolean
  */
 function list_rates(&$d)
 {
     global $vendor_country_2_code, $vendor_currency, $vmLogger;
     global $VM_LANG, $CURRENCY_DISPLAY;
     $db = new ps_DB();
     $dbv = new ps_DB();
     $cart = $_SESSION['cart'];
     // Read the fedex configuration file
     require_once CLASSPATH . "shipping/" . $this->classname . ".cfg.php";
     // Include the main FedEx class
     require_once CLASSPATH . 'shipping/fedex/fedexdc.php';
     // Get the meter number
     if (FEDEX_METER_NUMBER == '') {
         if (!$this->update_meter_number()) {
             $vmLogger->err($VM_LANG->_('VM_FEDEX_ERR_METER_NUMBER', false));
             return false;
         }
     }
     // Get the shopper's shipping address
     $q = "SELECT * FROM #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
     $db->query($q);
     $db->next_record();
     // Get the vendor address
     $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'";
     $dbv->query($q);
     $dbv->next_record();
     // Is this a residential delivery?
     $residential_delivery_flag = vmGet($_REQUEST, 'address_type', 'residential') == 'residential' ? 'Y' : 'N';
     // Is this a domestic delivery?
     $recipient_country = $db->f('country_2_code');
     $domestic_delivery = $recipient_country == 'US' || $recipient_country == 'CA' ? true : false;
     // Get the weight total
     if ($d['weight'] > 150) {
         $d['weight'] = 150;
     }
     if ($d['weight'] < 1) {
         $d['weight'] = 1;
     }
     $order_weight = number_format((double) $d['weight'], 1, '.', '');
     // Set units
     $weight_units = WEIGHT_UOM == 'KG' ? 'KGS' : 'LBS';
     $dimension_units = WEIGHT_UOM == 'KG' ? 'C' : 'I';
     // config values
     $fed_conf = array();
     // create new FedExDC object
     $meter_number = defined('FEDEX_METER_NUMBER_TEMP') ? FEDEX_METER_NUMBER_TEMP : FEDEX_METER_NUMBER;
     $fed = new FedExDC(FEDEX_ACCOUNT_NUMBER, $meter_number, $fed_conf);
     // Set up the rate request array.
     // You can either use the FedEx tag value or the field name in the $FE_RE array
     $request_array = array('carrier_code' => '', 'sender_state' => $dbv->f('vendor_state'), 'sender_postal_code' => $dbv->f('vendor_zip'), 'sender_country_code' => $vendor_country_2_code, 'recipient_state' => $db->f('state'), 'recipient_postal_code' => $db->f('zip'), 'recipient_country' => $db->f('country_2_code'), 'residential_delivery_flag' => $residential_delivery_flag, 'signature_option' => FEDEX_SIGNATURE_OPTION, 'weight_units' => $weight_units, 'total_package_weight' => $order_weight, 'drop_off_type' => '1');
     // Get the rate quote
     $rate_Ret = $fed->services_rate($request_array);
     if ($error = $fed->getError()) {
         $vmLogger->err($error);
         // Switch to StandardShipping on Error !!!
         require_once CLASSPATH . 'shipping/standard_shipping.php';
         $shipping = new standard_shipping();
         $shipping->list_rates($d);
         return;
     } elseif (DEBUG) {
         echo "<pre>";
         echo $fed->debug_str . "\n<br />";
         print_r($rate_Ret);
         echo "\n";
         echo "ZONE: " . $rate_Ret[1092] . "\n\n";
         for ($i = 1; $i <= $rate_Ret[1133]; $i++) {
             echo "SERVICE : " . $fed->service_type($rate_Ret['1274-' . $i], $domestic_delivery) . "\n";
             echo "SURCHARGE : " . $rate_Ret['1417-' . $i] . "\n";
             echo "DISCOUNT : " . $rate_Ret['1418-' . $i] . "\n";
             echo "NET CHARGE : " . $rate_Ret['1419-' . $i] . "\n";
             echo "DELIVERY DAY : " . @$rate_Ret['194-' . $i] . "\n";
             echo "DELIVERY DATE : " . @$rate_Ret['409-' . $i] . "\n\n";
         }
         echo "</pre>";
     }
     // Set the tax rate
     if ($_SESSION['auth']['show_price_including_tax'] != 1) {
         $taxrate = 1;
     } else {
         $taxrate = $this->get_tax_rate() + 1;
     }
     // Write out the shipping rates
     $html = '<span class="fedex_header">' . $VM_LANG->_('VM_FEDEX_LBL_METHOD') . '</span><br />';
     // Get a sort order array (by cost)
     $cost_array = array();
     for ($i = 1; $i <= $rate_Ret[1133]; $i++) {
         $cost_array[$i] = $rate_Ret['1419-' . $i];
     }
     if (FEDEX_SORT_ORDER == 'ASC') {
         asort($cost_array, SORT_NUMERIC);
     } else {
         arsort($cost_array, SORT_NUMERIC);
     }
     // Determine which services we can display
     $selected_services = explode(',', FEDEX_SERVICES);
     if ($domestic_delivery) {
         $selected_services = preg_grep('/^d/', $selected_services);
         array_walk($selected_services, create_function('&$v,$k', '$v = substr($v, 1);'));
         // If this is a residential delivery, then remove the business option; otherwise, remove the home delivery option.
         if ($residential_delivery_flag == 'Y') {
             $remove = array("92");
             $selected_services = array_diff($selected_services, array("92"));
         } else {
             $remove = array("90");
             $selected_services = array_diff($selected_services, array("90"));
         }
     } else {
         $selected_services = preg_grep('/^i/', $selected_services);
         array_walk($selected_services, create_function('&$v,$k', '$v = substr($v, 1);'));
     }
     // Display each rate
     foreach (array_keys($cost_array) as $i) {
         if (in_array($rate_Ret['1274-' . $i], $selected_services)) {
             $charge = $rate_Ret['1419-' . $i] + floatval(FEDEX_HANDLINGFEE);
             $charge *= $taxrate;
             $charge_display = $CURRENCY_DISPLAY->getFullValue($charge);
             $shipping_rate_id = urlencode($this->classname . "|FedEx|" . $fed->service_type($rate_Ret['1274-' . $i], $domestic_delivery) . "|" . $charge);
             $checked = @$d["shipping_rate_id"] == $shipping_rate_id ? "checked=\"checked\"" : "";
             $html .= "\n<span class=\"ssectiontableentry" . (2 - $i % 2) . "\">";
             $html .= "\n<input type=\"radio\" id=\"{$shipping_rate_id}\" name=\"shipping_rate_id\" {$checked} value=\"{$shipping_rate_id}\" />\n";
             $_SESSION[$shipping_rate_id] = 1;
             $html .= "<label for=\"{$shipping_rate_id}\">" . $fed->service_type($rate_Ret['1274-' . $i], $domestic_delivery) . " ";
             //			if( !empty( $rate_Ret['194-'.$i] ) && !empty($rate_Ret['409-'.$i])) {
             //				$html .= ", expected delivery: ".$rate_Ret['194-'.$i].', '.$rate_Ret['409-'.$i];
             //			}
             $html .= "<strong>({$charge_display})</strong>";
             $html .= "</label>\n";
             $html .= "</span>\n";
             $html .= "<br />\n";
         }
     }
     echo $html;
     return true;
 }
Example #2
0
 function list_rates(&$d)
 {
     global $weight_total, $CURRENCY_DISPLAY, $vmLogger;
     $d["ship_to_info_id"] = vmGet($_REQUEST, "ship_to_info_id");
     /** Read current Configuration ***/
     require_once CLASSPATH . "shipping/" . $this->classname . ".cfg.php";
     $dbv = new ps_DB();
     $q = "SELECT * from #__{vm}_vendor, #__{vm}_country WHERE vendor_id='" . $_SESSION["ps_vendor_id"] . "' AND (vendor_country=country_2_code OR vendor_country=country_3_code)";
     $dbv->query($q);
     $dbv->next_record();
     $dbst = new ps_DB();
     $q = "SELECT * from #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
     $dbst->query($q);
     $dbst->next_record();
     $carrier_arr = array();
     $i = 0;
     if (CARRIER1_NAME != "") {
         $carrier_arr[$i]["name"] = CARRIER1_NAME;
         $carrier_arr[$i]["invoice"] = CARRIER1_INVOICE;
         $carrier_arr[$i]["account"] = CARRIER1_ACCOUNT;
         $i++;
     }
     if (CARRIER2_NAME != "") {
         $carrier_arr[$i]["name"] = CARRIER2_NAME;
         $carrier_arr[$i]["invoice"] = CARRIER2_INVOICE;
         $carrier_arr[$i]["account"] = CARRIER2_ACCOUNT;
         $i++;
     }
     if (CARRIER3_NAME != "") {
         $carrier_arr[$i]["name"] = CARRIER3_NAME;
         $carrier_arr[$i]["invoice"] = CARRIER3_INVOICE;
         $carrier_arr[$i]["account"] = CARRIER3_ACCOUNT;
         $i++;
     }
     if (CARRIER4_NAME != "") {
         $carrier_arr[$i]["name"] = CARRIER4_NAME;
         $carrier_arr[$i]["invoice"] = CARRIER4_INVOICE;
         $carrier_arr[$i]["account"] = CARRIER4_ACCOUNT;
         $i++;
     }
     if (CARRIER5_NAME != "") {
         $carrier_arr[$i]["name"] = CARRIER5_NAME;
         $carrier_arr[$i]["invoice"] = CARRIER5_INVOICE;
         $carrier_arr[$i]["account"] = CARRIER5_ACCOUNT;
         $i++;
     }
     $i = 0;
     $class_arr = array();
     if (SERVICE_CLASS1 != "") {
         $class_arr[$i] = SERVICE_CLASS1;
         $i++;
     }
     if (SERVICE_CLASS2 != "") {
         $class_arr[$i] = SERVICE_CLASS2;
         $i++;
     }
     if (SERVICE_CLASS3 != "") {
         $class_arr[$i] = SERVICE_CLASS3;
         $i++;
     }
     if (SERVICE_CLASS4 != "") {
         $class_arr[$i] = SERVICE_CLASS4;
         $i++;
     }
     //Set your username and password.
     $username = IS_USERNAME;
     $password = IS_PASSWORD;
     // Build the query string to be sent to the IS server.
     //http://intershipper.com/Shipping/Intershipper/Website/MainPage.jsp?Page=Integrate
     // for additional information
     // for additional information
     $url = 'www.intershipper.com';
     $uri = '/Interface/Intershipper/XML/v2.0/HTTP.jsp?' . 'Username='******'&Password='******'&Version=' . '2.0.0.0' . '&ShipmentID=' . '1234' . '&QueryID=' . '23456' . '&TotalCarriers=' . count($carrier_arr);
     $i = 1;
     foreach ($carrier_arr as $carrier) {
         $uri .= "&CarrierCode{$i}=" . $carrier["name"] . "&CarrierInvoiced{$i}=" . $carrier["invoice"] . "&CarrierAccount{$i}=" . $carrier["account"];
         $i++;
     }
     $uri .= '&TotalClasses=' . count($class_arr);
     $i = 1;
     foreach ($class_arr as $k => $v) {
         $uri .= "&ClassCode{$i}=" . $v;
         $i++;
     }
     $uri .= '&DeliveryType=' . 'COM' . '&ShipMethod=' . 'DRP' . '&OriginationName=' . urlencode($dbv->f("contact_first_name") . '%20' . $dbv->f("contact_last_name")) . '&OriginationAddress1=' . urlencode($dbv->f("vendor_address_1")) . '&OriginationCity=' . urlencode($dbv->f("vendor_city")) . '&OriginationState=' . urlencode($dbv->f("vendor_state")) . '&OriginationPostal=' . $dbv->f("vendor_zip") . '&OriginationCountry=' . $dbv->f("country_2_code") . '&DestinationName=' . urlencode($dbst->f("first_name") . '%20' . $dbst->f("last_name")) . '&DestinationAddress1=' . urlencode($dbst->f("address_1")) . '&DestinationCity=' . urlencode($dbst->f("city")) . '&DestinationState=' . urlencode($dbst->f("state")) . '&DestinationPostal=' . $dbst->f("zip") . '&DestinationCountry=' . $dbst->f("country_2_code") . '&Currency=' . $_SESSION['vendor_currency'] . '&TotalPackages=' . '1' . '&BoxID1=' . '1' . '&Weight1=' . $weight_total . '&WeightUnit1=' . WEIGHT_UOM . '&Length1=' . '10' . '&Width1=' . '10' . '&Height1=' . '10' . '&DimensionalUnit1=' . 'IN' . '&Packaging1=' . 'BOX' . '&Contents1=' . 'OTR' . '&Cod1=' . '0' . '&Insurance1=' . '0' . '&TotalOptions=' . '1' . '&OptionCode1=' . 'SDD';
     //Define some global vars for later use
     $state = array();
     global $state;
     $quote = array();
     global $quote;
     $quotes = array();
     global $quotes;
     global $package_id;
     global $boxID;
     // funtion to handle the start elements for the XML data
     function startElement(&$Parser, &$Elem, $Attr)
     {
         global $state;
         if (!is_array($state)) {
             $state = array();
         }
         array_push($state, $Elem);
         $states = join(' ', $state);
         //check what state we are in
         if ($states == "SHIPMENT PACKAGE") {
             global $package_id;
             $package_id = $Attr['ID'];
         } elseif ($states == "SHIPMENT PACKAGE QUOTE") {
             global $package_id;
             global $quote;
             $quote = array('package_id' => $package_id, 'id' => $Attr['ID']);
         }
     }
     //funtion to parse the XML data. The routine does a series of conditional
     //checks on the data to determine where in the XML stack "we" are.
     //
     function characterData($Parser, $Line)
     {
         global $state;
         $states = join(' ', $state);
         if ($states == "SHIPPMENT ERROR") {
             $error = $Line;
         } elseif ($states == "SHIPMENT PACKAGE BOXID") {
             global $boxID;
             $boxID = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE CARRIER NAME") {
             global $quote;
             $quote["carrier_name"] = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE CARRIER CODE") {
             global $quote;
             $quote["carrier_code"] = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE CLASS NAME") {
             global $quote;
             $quote["class_name"] = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE CLASS CODE") {
             global $quote;
             $quote["class_code"] = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE SERVICE NAME") {
             global $quote;
             $quote["service_name"] = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE SERVICE CODE") {
             global $quote;
             $quote["service_code"] = $Line;
         } elseif ($states == "SHIPMENT PACKAGE QUOTE RATE AMOUNT") {
             global $quote;
             $quote['amount'] = $Line;
         }
     }
     // this function handles the end elements.
     // once encountered it sticks the quote into the hash $quotes
     // for easy access later
     function endElement($Parser, $Elem)
     {
         global $state, $vmLogger;
         $states = join(' ', $state);
         if ($states == "SHIPMENT PACKAGE QUOTE") {
             global $quote;
             global $boxID;
             global $quotes;
             unset($quote['id']);
             unset($quote['package_id']);
             // the $key is a combo of the carrier_code and service_code
             // this is the logical way to key each quote returned
             $key = $quote['carrier_code'] . ' ' . $quote['service_code'];
             $quotes[$boxID][$key] = $quote;
         }
         array_pop($state);
     }
     //Send the socket request with the uri/url
     $fp = fsockopen("www.intershipper.com", 80, $errno, $errstr, 30);
     if (!$fp) {
         $html = "Error: {$errstr} ({$errno})<br>\n";
         $error = true;
     } else {
         //echo "<a href=\"http://".$url.$uri."\">URL</a>";
         $depth = array();
         fputs($fp, "GET {$uri} HTTP/1.0\r\nHost: {$url}\r\n\r\n");
         //define the XML parsing routines/functions to call
         //based on the handler state
         $xml_parser = xml_parser_create();
         xml_set_element_handler($xml_parser, "startElement", "endElement");
         xml_set_character_data_handler($xml_parser, "characterData");
         //now lets roll through the data
         $error = false;
         while ($data = fread($fp, 8192)) {
             $newdata = $data;
             /*fsockopen returns more infomation than we'd like. here we 
               remove the excess data. */
             $newdata = preg_replace('/\\r\\n\\r\\n/', "", $newdata);
             $newdata = preg_replace('/HTTP.*\\r\\n/', "", $newdata);
             $newdata = preg_replace('/Date.*\\r\\n/', "", $newdata);
             $newdata = preg_replace('/Server.*\\r\\n/', "", $newdata);
             $newdata = preg_replace('/Via.*/', "", $newdata);
             $newdata = preg_replace('/Con.*/', "", $newdata);
             $newdata = preg_replace('/Set.*/', "", $newdata);
             $newdata = preg_replace('/\\r/', "", $newdata);
             $newdata = preg_replace('/\\n/', "", $newdata);
             if (strstr($newdata, "error")) {
                 $html = $newdata;
                 $error = true;
             }
             /* if we properl cleaned up the XML stream/data we can now hand it off 
             	  to an XML parser without error */
             if (!xml_parse($xml_parser, $newdata, feof($fp))) {
                 die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
             }
         }
         //clean up the parser object
         xml_parser_free($xml_parser);
     }
     /* Here we build a drop down menu list (as an example).
     	  print_r $quotes
     	  can help you debug or use the $quotes hash we built above.
     	  a variety of info is included but mostly we probably want amount, carrier_name,
     	  service_name. */
     $shipping_rate_id = urlencode(vmGet($_REQUEST, "shipping_rate_id"));
     if (!$error) {
         if ($_SESSION['auth']['show_price_including_tax'] != 1) {
             $taxrate = 1;
         } else {
             $taxrate = $this->get_tax_rate() + 1;
         }
         while (list($quotedata, $boxID) = each($quotes)) {
             while (list($key, $bar) = each($boxID)) {
                 if (isset($carrier)) {
                     if ($carrier != $boxID[$key]['carrier_name']) {
                         echo "<br /><strong>" . $boxID[$key]['carrier_name'] . "</strong><br />";
                     }
                     $carrier = $boxID[$key]['carrier_name'];
                 } else {
                     echo "<br /><strong>" . $boxID[$key]['carrier_name'] . "</strong><br />";
                     $carrier = $boxID[$key]['carrier_name'];
                 }
                 echo $carrier == $boxID[$key]['carrier_name'] ? "" : $carrier;
                 $boxID[$key]['amount'] = $boxID[$key]['amount'] / 100 * $taxrate;
                 $boxID[$key]['amount'] = number_format($boxID[$key]['amount'], 2, '.', ' ');
                 $value = urlencode($this->classname . "|" . $key . "|" . $boxID[$key]['service_name'] . "|" . $boxID[$key]['amount']);
                 $checked = $shipping_rate_id == $value ? "checked=\"checked\"" : "";
                 print "\n<input type=\"radio\" name=\"shipping_rate_id\" {$checked} value=\"{$value}\" />\n";
                 $_SESSION[urlencode($this->classname . "|" . $key . "|" . $boxID[$key]['service_name'] . "|" . $boxID[$key]['amount'])] = 1;
                 print $boxID[$key]['service_name'] . " ";
                 print "<strong>" . $CURRENCY_DISPLAY->getFullValue($boxID[$key]['amount']) . "</strong>";
                 print "<br />";
             }
         }
     } else {
         // Switch to StandardShipping on Error !!!
         $vmLogger->err($html);
         require_once CLASSPATH . 'shipping/standard_shipping.php';
         $shipping = new standard_shipping();
         $shipping->list_rates($d);
         return;
     }
 }
Example #3
0
    function list_rates(&$d)
    {
        global $VM_LANG, $CURRENCY_DISPLAY;
        $d["ship_to_info_id"] = vmGet($_REQUEST, "ship_to_info_id");
        /** Read current Configuration ***/
        require_once CLASSPATH . "shipping/" . $this->classname . ".cfg.php";
        $dbst = new ps_DB();
        $q = "SELECT * from #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
        $dbst->query($q);
        $dbst->next_record();
        $cart = $_SESSION['cart'];
        $dboi = new ps_DB();
        for ($i = 0; $i < $cart["idx"]; $i++) {
            $r = "SELECT product_id,product_name,product_weight,product_length,product_width ";
            $r .= "FROM #__{vm}_product WHERE product_id='" . $cart[$i]["product_id"] . "'";
            $dboi->query($r);
            $dboi->next_record();
            //		echo ($cart[$i]["quantity"]." ".$dboi->f("product_weight")." ".$dboi->f("product_length")." ".$dboi->f("product_width")." ".$dboi->f("product_height")." ".$dboi->f("product_name"));
            $this->addItem($cart[$i]["quantity"], $dboi->f("product_weight") ? $dboi->f("product_weight") : 0, $dboi->f("product_length") ? $dboi->f("product_length") : 0, $dboi->f("product_width") ? $dboi->f("product_width") : 0, $dboi->f("product_height") ? $dboi->f("product_height") : 0, $dboi->f("product_name"));
            //		$this->addItem( $cart[$i]["quantity"], $dboi->f("product_weight"), 10, 10, 10, $dboi->f("product_name")) ;
        }
        $this->getQuote(urlencode($dbst->f("city")), urlencode($dbst->f("country_2_code") == "US" ? $dbst->f("state") : ""), $dbst->f("country_2_code"), $dbst->f("zip"));
        $shipping_rate_id = urlencode(vmGet($_REQUEST, "shipping_rate_id"));
        $i = 0;
        if (!$this->error) {
            ?>
      <table width="100%"><tr class="sectiontableheader">
	  <th>&nbsp;</th>
	  <th><?php 
            echo $VM_LANG->_('PHPSHOP_ISSHIP_LIST_CARRIER_LBL');
            ?>
</th>
 	  <th><?php 
            echo $VM_LANG->_('VM_CANADAPOST_FORM_HANDLING_DATE');
            ?>
<sup>1</sup></th>
	  <th><?php 
            echo $VM_LANG->_('VM_CANADAPOST_FORM_HANDLING_LBL');
            ?>
<sup>2</sup></th>
      </tr>
      <?php 
            foreach ($this->shipping_methods as $m) {
                $value = urlencode($this->classname . "|" . $m["name"] . "|" . $m["deliveryDate"] . "|" . $m["rate"]);
                $_SESSION[urlencode($this->classname . "|" . $m["name"] . "|" . $m["deliveryDate"] . "|" . $m["rate"])] = 1;
                if ($i++ % 2) {
                    $class = "sectiontableentry1";
                } else {
                    $class = "sectiontableentry2";
                }
                $checked = $shipping_rate_id == $value ? "checked=\"checked\"" : "";
                // formatting of the shipping date returned by Canada Post
                $str = $m["deliveryDate"];
                if (($timestamp = strtotime($str)) === -1) {
                    $str = html_entity_decode($m["deliveryDate"]);
                } else {
                    if ($VM_LANG->_('VM_CANADAPOST_SEND_LANGUAGE_CODE') == "FR") {
                        setlocale(LC_ALL, 'fr');
                        $str = strftime('%A %d %B %Y', $timestamp);
                    } else {
                        setlocale(LC_ALL, 'en');
                        $str = strftime('%A, %B %d %Y', $timestamp);
                    }
                }
                // Adding taxes to the rates returned by Canada Post
                // First : add the federal tax (FT) to the shipping rate -> R * (1+FT%) = R1
                // Second : add the provincial tax (PT) to the rate R1 -> R1 * (1+PT%) = R2
                $R1 = $m["rate"] * (1 + CP_FEDERAL_TAX / 100);
                $R2 = $R1 * (1 + CP_PROVINCIAL_TAX / 100);
                ?>
			<tr class=<?php 
                echo $class;
                ?>
 >
				<td><?php 
                print "<input type=\"radio\" name=\"shipping_rate_id\" {$checked} value=\"{$value}\" />\n";
                ?>
</td>
				<td><?php 
                print html_entity_decode($m["name"]);
                ?>
</td>
				<td align="center"><?php 
                print $str;
                ?>
</td>
				<td align="right"><?php 
                echo $CURRENCY_DISPLAY->getFullValue($R2);
                ?>
</td>
			</tr>
			<tr>
				<td colspan="4" bgcolor="#cccccc"><img src="/pics/blank.gif" width="1" height="1" border="0"></td>
			</tr>
<?php 
            }
            // foreach
            // print "<hr>\n\n\n" ;
            // print "Request XML:<br><form action='http://" . CP_SERVER . ":" . CP_PORT . "' method='post' target='_blank' ><textarea name='XMLRequest' style='width:100%;height:400px;background-color:#f2f2f2'>\n" . $this->xml_request . "\n\n</textarea><br><input type='submit' value='Send to Canada Post'></form>";
            // print "<br><br>Return XML:<br><form><textarea style='width:100%;height:400px;background-color:#f2f2f2'>\n" . $this->xml_response . "\n\n</textarea></form>";
            ?>
		<td colspan="4">
		<?php 
            echo "<SUP>1</SUP>La date de livraison est calcul�e en ajoutant les normes de livraison de Postes Canada au d�lai d�ex�cution des commandes.<BR>";
            ?>
		<?php 
            echo "<SUP>2</SUP>Les frais d�exp�dition sont calcul�s en ajoutant les services de Postes Canada aux co�ts de manutention. Taxes incluses.<BR>";
            ?>
		</td>
<?php 
            return True;
        } else {
            // Switch to StandardShipping on Error !!!
            echo html_entity_decode($this->error_msg) . "<br><br>";
            // print "<hr>\n\n\n" ;
            // print "Request XML:<br><form action='http://" . CP_SERVER . ":" . CP_PORT . "' method='post' target='_blank' ><textarea name='XMLRequest' style='width:100%;height:400px;background-color:#f2f2f2'>\n" . $this->xml_request . "\n\n</textarea><br><input type='submit' value='Send to Canada Post'></form>";
            // print "<br><br>Return XML:<br><form><textarea style='width:100%;height:400px;background-color:#f2f2f2'>\n" . $this->xml_response . "\n\n</textarea></form>";
            require_once CLASSPATH . 'shipping/standard_shipping.php';
            $shipping = new standard_shipping();
            $shipping->list_rates($d);
            return;
        }
    }
Example #4
0
 function list_rates(&$d)
 {
     global $vendor_country_2_code, $vendor_currency, $vmLogger;
     global $VM_LANG, $CURRENCY_DISPLAY, $mosConfig_absolute_path;
     $db = new ps_DB();
     $dbv = new ps_DB();
     $cart = $_SESSION['cart'];
     /** Read current Configuration ***/
     require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php";
     $q = "SELECT * FROM #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
     $db->query($q);
     $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'";
     $dbv->query($q);
     $dbv->next_record();
     $order_weight = $d['weight'];
     $html = "";
     if ($order_weight > 0) {
         if ($order_weight < 1) {
             $order_weight = 1;
         }
         if ($order_weight > 150.0) {
             $order_weight = 150.0;
         }
         //Access code for online tools at ups.com
         $ups_access_code = UPS_ACCESS_CODE;
         //Username from registering for online tools at ups.com
         $ups_user_id = UPS_USER_ID;
         //Password from registering for online tools at ups.com
         $ups_user_password = UPS_PASSWORD;
         //Title for your request
         $request_title = "Shipping Estimate";
         //The zip that you are shipping from
         // Add ability to override vendor zip code as source ship from...
         if (Override_Source_Zip != "" or Override_Source_Zip != NULL) {
             $source_zip = Override_Source_Zip;
         } else {
             $source_zip = $dbv->f("vendor_zip");
         }
         //The zip that you are shipping to
         $dest_country = $db->f("country_2_code");
         $dest_zip = substr($db->f("zip"), 0, 5);
         // Make sure the ZIP is 5 chars long
         //LBS  = Pounds
         //KGS  = Kilograms
         $weight_measure = WEIGHT_UOM == 'KG' ? "KGS" : "LBS";
         // The XML that will be posted to UPS
         $xmlPost = "<?xml version=\"1.0\"?>";
         $xmlPost .= "<AccessRequest xml:lang=\"en-US\">";
         $xmlPost .= " <AccessLicenseNumber>" . $ups_access_code . "</AccessLicenseNumber>";
         $xmlPost .= " <UserId>" . $ups_user_id . "</UserId>";
         $xmlPost .= " <Password>" . $ups_user_password . "</Password>";
         $xmlPost .= "</AccessRequest>";
         $xmlPost .= "<?xml version=\"1.0\"?>";
         $xmlPost .= "<RatingServiceSelectionRequest xml:lang=\"en-US\">";
         $xmlPost .= " <Request>";
         $xmlPost .= "  <TransactionReference>";
         $xmlPost .= "  <CustomerContext>" . $request_title . "</CustomerContext>";
         $xmlPost .= "  <XpciVersion>1.0001</XpciVersion>";
         $xmlPost .= "  </TransactionReference>";
         $xmlPost .= "  <RequestAction>rate</RequestAction>";
         $xmlPost .= "  <RequestOption>shop</RequestOption>";
         $xmlPost .= " </Request>";
         $xmlPost .= " <PickupType>";
         $xmlPost .= "  <Code>" . UPS_PICKUP_TYPE . "</Code>";
         $xmlPost .= " </PickupType>";
         $xmlPost .= " <Shipment>";
         $xmlPost .= "  <Shipper>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $source_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$vendor_country_2_code}</CountryCode>";
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </Shipper>";
         $xmlPost .= "  <ShipTo>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $dest_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$dest_country}</CountryCode>";
         if (UPS_RESIDENTIAL == "yes") {
             $xmlPost .= "    <ResidentialAddressIndicator/>";
         }
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </ShipTo>";
         $xmlPost .= "  <ShipFrom>";
         $xmlPost .= "   <Address>";
         $xmlPost .= "    <PostalCode>" . $source_zip . "</PostalCode>";
         $xmlPost .= "    <CountryCode>{$vendor_country_2_code}</CountryCode>";
         $xmlPost .= "   </Address>";
         $xmlPost .= "  </ShipFrom>";
         // Service is only required, if the Tag "RequestOption" contains the value "rate"
         // We don't want a specific servive, but ALL Rates
         //$xmlPost .= "  <Service>";
         //$xmlPost .= "   <Code>".$shipping_type."</Code>";
         //$xmlPost .= "  </Service>";
         $xmlPost .= "  <Package>";
         $xmlPost .= "   <PackagingType>";
         $xmlPost .= "    <Code>" . UPS_PACKAGE_TYPE . "</Code>";
         $xmlPost .= "   </PackagingType>";
         $xmlPost .= "   <PackageWeight>";
         $xmlPost .= "    <UnitOfMeasurement>";
         $xmlPost .= "     <Code>" . $weight_measure . "</Code>";
         $xmlPost .= "    </UnitOfMeasurement>";
         $xmlPost .= "    <Weight>" . $order_weight . "</Weight>";
         $xmlPost .= "   </PackageWeight>";
         $xmlPost .= "  </Package>";
         $xmlPost .= " </Shipment>";
         $xmlPost .= "</RatingServiceSelectionRequest>";
         // echo htmlentities( $xmlPost );
         $upsURL = "https://www.ups.com:443/ups.app/xml/Rate";
         require_once CLASSPATH . 'connectionTools.class.php';
         $error = false;
         $xmlResult = vmConnector::handleCommunication($upsURL, $xmlPost);
         if (!$xmlResult) {
             $vmLogger->err($VM_LANG->_('PHPSHOP_INTERNAL_ERROR', false) . " UPS.com");
             $error = true;
         } else {
             /* XML Parsing */
             require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php';
             $xmlDoc = new DOMIT_Lite_Document();
             $xmlDoc->parseXML($xmlResult, false, true);
             /* Let's check wether the response from UPS is Success or Failure ! */
             if (strstr($xmlResult, "Failure")) {
                 $error = true;
                 $error_code = $xmlDoc->getElementsByTagName("ErrorCode");
                 $error_code = $error_code->item(0);
                 $error_code = $error_code->getText();
                 $error_desc = $xmlDoc->getElementsByTagName("ErrorDescription");
                 $error_desc = $error_desc->item(0);
                 $error_desc = $error_desc->getText();
                 $vmLogger->err($VM_LANG->_('PHPSHOP_UPS_RESPONSE_ERROR', false) . '. ' . $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . ', ' . $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc);
             }
         }
         if ($error) {
             // Switch to StandardShipping on Error !!!
             require_once CLASSPATH . 'shipping/standard_shipping.php';
             $shipping = new standard_shipping();
             $shipping->list_rates($d);
             return;
         }
         // retrieve the list of all "RatedShipment" Elements
         $rate_list =& $xmlDoc->getElementsByTagName("RatedShipment");
         $allservicecodes = array("UPS_Next_Day_Air", "UPS_2nd_Day_Air", "UPS_Ground", "UPS_Worldwide_Express_SM", "UPS_Worldwide_Expedited_SM", "UPS_Standard", "UPS_3_Day_Select", "UPS_Next_Day_Air_Saver", "UPS_Next_Day_Air_Early_AM", "UPS_Worldwide_Express_Plus_SM", "UPS_2nd_Day_Air_AM", "UPS_Saver", "na");
         $myservicecodes = array();
         foreach ($allservicecodes as $servicecode) {
             if (constant($servicecode) != '' || constant($servicecode) != 0) {
                 $myservicecodes[] = constant($servicecode);
             }
         }
         if (DEBUG) {
             echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n";
             echo "XML Post: <br>";
             echo "<textarea cols='80'>" . $xmlPost . "</textarea>";
             echo "<br>";
             echo "XML Result: <br>";
             echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>";
             echo "<br>";
         }
         // Loop through the rate List
         for ($i = 0; $i < $rate_list->getLength(); $i++) {
             $currNode =& $rate_list->item($i);
             if (in_array($currNode->childNodes[0]->getText(), $myservicecodes)) {
                 $e = 0;
                 // First Element: Service Code
                 $shipment[$i]["ServiceCode"] = $currNode->childNodes[$e++]->getText();
                 // Second Element: BillingWeight
                 if ($currNode->childNodes[$e]->nodeName == 'RatedShipmentWarning') {
                     $e++;
                 }
                 $shipment[$i]["BillingWeight"] = $currNode->childNodes[$e++];
                 // Third Element: TransportationCharges
                 $shipment[$i]["TransportationCharges"] = $currNode->childNodes[$e++];
                 $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->getElementsByTagName("MonetaryValue");
                 $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->item(0);
                 if (is_object($shipment[$i]["TransportationCharges"])) {
                     $shipment[$i]["TransportationCharges"] = $shipment[$i]["TransportationCharges"]->getText();
                 }
                 // Fourth Element: ServiceOptionsCharges
                 $shipment[$i]["ServiceOptionsCharges"] = $currNode->childNodes[$e++];
                 // Fifth Element: TotalCharges
                 $shipment[$i]["TotalCharges"] = $currNode->childNodes[$e++];
                 // Sixth Element: GuarenteedDaysToDelivery
                 $shipment[$i]["GuaranteedDaysToDelivery"] = $currNode->childNodes[$e++]->getText();
                 // Seventh Element: ScheduledDeliveryTime
                 $shipment[$i]["ScheduledDeliveryTime"] = $currNode->childNodes[$e++]->getText();
                 // Eighth Element: RatedPackage
                 $shipment[$i]["RatedPackage"] = $currNode->childNodes[$e++];
                 // map ServiceCode to ServiceName
                 switch ($shipment[$i]["ServiceCode"]) {
                     case "01":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air";
                         break;
                     case "02":
                         $shipment[$i]["ServiceName"] = "UPS 2nd Day Air";
                         break;
                     case "03":
                         $shipment[$i]["ServiceName"] = "UPS Ground";
                         break;
                     case "07":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Express SM";
                         break;
                     case "08":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Expedited SM";
                         break;
                     case "11":
                         $shipment[$i]["ServiceName"] = "UPS Standard";
                         break;
                     case "12":
                         $shipment[$i]["ServiceName"] = "UPS 3 Day Select";
                         break;
                     case "13":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air Saver";
                         break;
                     case "14":
                         $shipment[$i]["ServiceName"] = "UPS Next Day Air Early A.M.";
                         break;
                     case "54":
                         $shipment[$i]["ServiceName"] = "UPS Worldwide Express Plus SM";
                         break;
                     case "59":
                         $shipment[$i]["ServiceName"] = "UPS 2nd Day Air A.M.";
                         break;
                     case "64":
                         $shipment[$i]["ServiceName"] = "n/a";
                         break;
                     case "65":
                         $shipment[$i]["ServiceName"] = "UPS Saver";
                         break;
                 }
                 unset($currNode);
             }
         }
         if (!$shipment) {
             //$vmLogger->err( "Error processing the Request to UPS.com" );
             /*$vmLogger->err( "We could not find a UPS shipping rate.
             		Please make sure you have entered a valid shipping address.
             		Or choose a rate below." );
             		// Switch to StandardShipping on Error !!!
             		require_once( CLASSPATH . 'shipping/standard_shipping.php' );
             		$shipping = new standard_shipping();
             		$shipping->list_rates( $d );*/
             return;
         }
         // UPS returns Charges in USD ONLY.
         // So we have to convert from USD to Vendor Currency if necessary
         if ($_SESSION['vendor_currency'] != "USD") {
             $convert = true;
         } else {
             $convert = false;
         }
         if ($_SESSION['auth']['show_price_including_tax'] != 1) {
             $taxrate = 1;
         } else {
             $taxrate = $this->get_tax_rate() + 1;
         }
         foreach ($shipment as $key => $value) {
             //Get the Fuel SurCharge rate, defined in config.
             $fsc = $value['ServiceName'] . "_FSC";
             $fsc = str_replace(" ", "_", str_replace(".", "", str_replace("/", "", $fsc)));
             $fsc = constant($fsc);
             if ($fsc == 0) {
                 $fsc_rate = 1;
             } else {
                 $fsc_rate = $fsc / 100;
                 $fsc_rate = $fsc_rate + 1;
             }
             if ($convert) {
                 $tmp = $GLOBALS['CURRENCY']->convert($value['TransportationCharges'], "USD", $vendor_currency);
                 // tmp is empty when the Vendor Currency could not be converted!!!!
                 if (!empty($tmp)) {
                     $charge = $tmp;
                     // add Fuel SurCharge
                     $charge *= $fsc_rate;
                     // add Handling Fee
                     $charge += UPS_HANDLING_FEE;
                     $charge *= $taxrate;
                     $value['TransportationCharges'] = $CURRENCY_DISPLAY->getFullValue($tmp);
                 } else {
                     $charge = $value['TransportationCharges'] + intval(UPS_HANDLING_FEE);
                     // add Fuel SurCharge
                     $charge *= $fsc_rate;
                     // add Handling Fee
                     $charge += UPS_HANDLING_FEE;
                     $charge *= $taxrate;
                     $value['TransportationCharges'] = $value['TransportationCharges'] . " USD";
                 }
             } else {
                 $charge = $charge_unrated = $value['TransportationCharges'];
                 // add Fuel SurCharge
                 $charge *= $fsc_rate;
                 // add Handling Fee
                 $charge += UPS_HANDLING_FEE;
                 $charge *= $taxrate;
                 $value['TransportationCharges'] = $CURRENCY_DISPLAY->getFullValue($charge);
             }
             $shipping_rate_id = urlencode(__CLASS__ . "|UPS|" . $value['ServiceName'] . "|" . $charge);
             $checked = @$d["shipping_rate_id"] == $value ? "checked=\"checked\"" : "";
             if (count($shipment) == 1) {
                 $checked = "checked=\"checked\"";
             }
             $html .= '<label for="' . $shipping_rate_id . '">' . "\n<input type=\"radio\" name=\"shipping_rate_id\" {$checked} value=\"{$shipping_rate_id}\" id=\"{$shipping_rate_id}\" />\n";
             $_SESSION[$shipping_rate_id] = 1;
             $html .= $value['ServiceName'] . ' ';
             $html .= "<strong>(" . $value['TransportationCharges'] . ")</strong>";
             if (DEBUG) {
                 $html .= " - " . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_WEIGHT') . ": " . $order_weight . " " . $weight_measure . ", " . $VM_LANG->_('PHPSHOP_RATE_FORM_VALUE') . ": [[" . $charge_unrated . "(" . $fsc_rate . ")]+" . UPS_HANDLING_FEE . "](" . $taxrate . ")]";
             }
             // DELIVERY QUOTE
             if (Show_Delivery_Days_Quote == 1) {
                 if (!empty($value['GuaranteedDaysToDelivery'])) {
                     $html .= "&nbsp;&nbsp;-&nbsp;&nbsp;" . $value['GuaranteedDaysToDelivery'] . " " . $VM_LANG->_('PHPSHOP_UPS_SHIPPING_GUARANTEED_DAYS');
                 }
             }
             if (Show_Delivery_ETA_Quote == 1) {
                 if (!empty($value['ScheduledDeliveryTime'])) {
                     $html .= "&nbsp;(ETA:&nbsp;" . $value['ScheduledDeliveryTime'] . ")";
                 }
             }
             if (Show_Delivery_Warning == 1 && !empty($value['RatedShipmentWarning'])) {
                 $html .= "</label><br/>\n&nbsp;&nbsp;&nbsp;*&nbsp;<em>" . $value['RatedShipmentWarning'] . "</em>\n";
             }
             $html .= "<br />\n";
         }
     }
     echo $html;
     //DEBUG
     if (DEBUG) {
         /*
         echo "My Services: <br>";
         print_r($myservicecodes);
         echo "<br>";
         echo "All Services: <br>";
         print_r($allservicecodes);
         echo "<br>";
         echo "XML Result: <br>";
         echo "<textarea cols='80' rows='10'>".$xmlResult."</textarea>";
         echo "<br>";
         */
     }
     return true;
 }