/** * Initializes the global currency converter array * * @return mixed */ function init() { global $mosConfig_cachepath, $mosConfig_absolute_path, $vendor_currency, $vmLogger; if (!is_array($GLOBALS['converter_array']) && $GLOBALS['converter_array'] !== -1) { setlocale(LC_TIME, "en-GB"); $now = time() + 3600; // Time in ECB (Germany) is GMT + 1 hour (3600 seconds) if (date("I")) { $now += 3600; // Adjust for daylight saving time } $weekday_now_local = gmdate('w', $now); // week day, important: week starts with sunday (= 0) !! $date_now_local = gmdate('Ymd', $now); $time_now_local = gmdate('Hi', $now); $time_ecb_update = '1415'; if (is_writable($mosConfig_cachepath)) { $store_path = $mosConfig_cachepath; } else { $store_path = $mosConfig_absolute_path . "/media"; } $archivefile_name = $store_path . '/daily.xml'; $ecb_filename = $this->document_address; $val = ''; if (file_exists($archivefile_name) && filesize($archivefile_name) > 0) { // timestamp for the Filename $file_datestamp = date('Ymd', filemtime($archivefile_name)); // check if today is a weekday - no updates on weekends if (date('w') > 0 && date('w') < 6 && $file_datestamp != $date_now_local && $time_now_local > $time_ecb_update) { $curr_filename = $ecb_filename; } else { $curr_filename = $archivefile_name; $this->last_updated = $file_datestamp; $this->archive = false; } } else { $curr_filename = $ecb_filename; } if (!is_writable($store_path)) { $this->archive = false; $vmLogger->debug("The file {$archivefile_name} can't be created. The directory {$store_path} is not writable"); } if ($curr_filename == $ecb_filename) { // Fetch the file from the internet require_once CLASSPATH . 'connectionTools.class.php'; $contents = vmConnector::handleCommunication($curr_filename); $this->last_updated = date('Ymd'); } else { $contents = @file_get_contents($curr_filename); } if ($contents) { // if archivefile does not exist if ($this->archive) { // now write new file file_put_contents($archivefile_name, $contents); } $contents = str_replace("<Cube currency='USD'", " <Cube currency='EUR' rate='1'/> <Cube currency='USD'", $contents); /* XML Parsing */ require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php'; $xmlDoc = new DOMIT_Lite_Document(); if (!$xmlDoc->parseXML($contents, false, true)) { $vmLogger->err('Failed to parse the Currency Converter XML document.'); $_SESSION['product_currency'] = $GLOBALS['product_currency'] = $vendor_currency; return false; } $currency_list = $xmlDoc->getElementsByTagName("Cube"); // Loop through the Currency List for ($i = 0; $i < $currency_list->getLength(); $i++) { $currNode =& $currency_list->item($i); $currency[$currNode->getAttribute("currency")] = $currNode->getAttribute("rate"); unset($currNode); } $GLOBALS['converter_array'] = $currency; } else { $GLOBALS['converter_array'] = -1; $vmLogger->err('Failed to retrieve the Currency Converter XML document.'); $_SESSION['product_currency'] = $GLOBALS['product_currency'] = $vendor_currency; return false; } } return true; }
/** * calls the unfuddle api to get the latest svn revision and compares it to the rev * listed in this class */ function checkRevision() { $this->_error = ''; $this->_msg = ''; if (!function_exists('curl_init')) { $this->_error = JText::_("SORRY YOU NEED CURL INSTALLED TO CHECK REVISION"); return false; } $this->config = array('port' => 80, 'version' => 1, 'account' => 'account_identifier', 'response_type' => 'application/xml', 'username' => 'anonymous', 'password' => 'anonymous', 'project' => 17220, 'default_assignee' => 8527, 'default_milestone' => 0); $headers = array('Content-Type: application/xml', 'Accept: application/xml'); $headers = $this->construct_headers(''); $url = "http://fabrik.unfuddle.com/api/v1/projects/17220/changesets/latest"; $this->connection = curl_init($url); $xml_string = ''; $curl_options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => 1, CURLOPT_VERBOSE => 1, CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_USERPWD => 'anonymous:anonymous'); foreach ($curl_options as $key => $value) { curl_setopt($this->connection, $key, $value); } $xml = $this->handle_response(curl_exec($this->connection)); require_once COM_FABRIK_BASE . DS . "includes" . DS . "domit" . DS . "xml_domit_lite_parser.php"; $xmlDoc = new DOMIT_Lite_Document(); $ok = $xmlDoc->parseXML($xml); if ($ok) { $this->_msg .= "<p style='color:green'>Version info obtained from SNV server</p>"; $rev = $xmlDoc->getElementsByTagName('revision'); $rev = $rev->item(0); $lastestRev = $rev->getText(); if ($this->SVNREV != $lastestRev) { $this->_msg .= "An update is available from the SVN<br>"; $msg = $xmlDoc->getElementsByTagName('message'); $msg = $msg->item(0); $date = $xmlDoc->getElementsByTagName('created-at'); $date = $date->item(0); $this->_msg .= "<br />message:" . $msg->getText() . "<br>date:" . $date->getText() . "<br><br>"; } else { $this->_msg .= "<p>YOU ARE UP TO DATE!</p>"; } $this->_msg .= "This release versions revision = '{$this->REV}' <br>\n\t\t This installations current SVN revision = '{$this->SVNREV}' <br>\n\t\t Latest available SVN rev = '{$lastestRev}'<br />"; } else { $this->_error = JText::_("UNABLE TO PARSE RESPONSE"); } }
function list_rates(&$d) { global $VM_LANG, $CURRENCY_DISPLAY, $mosConfig_absolute_path; $db = new ps_DB(); $dbv = new ps_DB(); $dbc = new ps_DB(); /** Read current Configuration ***/ require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php"; $q = "SELECT * FROM `#__{vm}_user_info`, `#__{vm}_country` WHERE user_info_id='" . $db->getEscaped($d["ship_to_info_id"]) . "' AND ( country=country_2_code OR country=country_3_code)"; $db->query($q); $db->next_record(); $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'"; $dbv->query($q); $dbv->next_record(); $order_weight = $d['weight']; if ($order_weight > 0) { //USPS Username $usps_username = USPS_USERNAME; //USPS Password $usps_password = USPS_PASSWORD; //USPS Server $usps_server = USPS_SERVER; //USPS Path $usps_path = USPS_PATH; //USPS package size $usps_packagesize = USPS_PACKAGESIZE; //USPS Package ID $usps_packageid = 0; //USPS International Per Pound Rate $usps_intllbrate = USPS_INTLLBRATE; //USPS International handling fee $usps_intlhandlingfee = USPS_INTLHANDLINGFEE; //Pad the shipping weight to allow weight for shipping materials $usps_padding = USPS_PADDING; $usps_padding = $usps_padding * 0.01; $order_weight = $order_weight * $usps_padding + $order_weight; //USPS Machinable for Parcel Post $usps_machinable = USPS_MACHINABLE; if ($usps_machinable == '1') { $usps_machinable = 'TRUE'; } else { $usps_machinable = 'FALSE'; } //USPS Shipping Options to display $usps_ship[0] = USPS_SHIP0; $usps_ship[1] = USPS_SHIP1; $usps_ship[2] = USPS_SHIP2; $usps_ship[3] = USPS_SHIP3; $usps_ship[4] = USPS_SHIP4; $usps_ship[5] = USPS_SHIP5; $usps_ship[6] = USPS_SHIP6; $usps_ship[7] = USPS_SHIP7; $usps_ship[8] = USPS_SHIP8; $usps_ship[9] = USPS_SHIP9; $usps_ship[10] = USPS_SHIP10; foreach ($usps_ship as $key => $value) { if ($value == '1') { $usps_ship[$key] = 'TRUE'; } else { $usps_ship[$key] = 'FALSE'; } } $usps_intl[0] = USPS_INTL0; $usps_intl[1] = USPS_INTL1; $usps_intl[2] = USPS_INTL2; $usps_intl[3] = USPS_INTL3; $usps_intl[4] = USPS_INTL4; $usps_intl[5] = USPS_INTL5; $usps_intl[6] = USPS_INTL6; $usps_intl[7] = USPS_INTL7; $usps_intl[8] = USPS_INTL8; // $usps_intl[9] = USPS_INTL9; foreach ($usps_intl as $key => $value) { if ($value == '1') { $usps_intl[$key] = 'TRUE'; } else { $usps_intl[$key] = 'FALSE'; } } //Title for your request $request_title = "Shipping Estimate"; //The zip that you are shipping from $source_zip = substr($dbv->f("vendor_zip"), 0, 5); $shpService = 'All'; //"Priority"; //The zip that you are shipping to $dest_country = $db->f("country_2_code"); if ($dest_country == "GB") { $q = "SELECT state_name FROM #__{vm}_state WHERE state_2_code='" . $db->f("state") . "'"; $dbc->query($q); $dbc->next_record(); $dest_country_name = $dbc->f("state_name"); } else { $dest_country_name = $db->f("country_name"); } $dest_state = $db->f("state"); $dest_zip = substr($db->f("zip"), 0, 5); //$weight_measure if ($order_weight < 1) { $shipping_pounds_intl = 0; } else { $shipping_pounds_intl = ceil($order_weight); } if ($order_weight < 0.88) { $shipping_pounds = 0; $shipping_ounces = round(16 * ($order_weight - floor($order_weight))); } else { $shipping_pounds = ceil($order_weight); $shipping_ounces = 0; } $os = array("Mac", "NT", "Irix", "Linux"); $states = array("AL", "AK", "AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WI", "WV", "WY"); //If weight is over 70 pounds, round down to 70 for now. //Will update in the future to be able to split the package or something? if ($order_weight > 70.0) { echo "We are unable to ship USPS as the package weight exceeds the 70 pound limit,<br>please select another shipping method."; } else { if ($dest_country == "US" && in_array($dest_state, $states)) { /******START OF DOMESTIC RATE******/ //the xml that will be posted to usps $xmlPost = 'API=RateV2&XML=<RateV2Request USERID="' . $usps_username . '" PASSWORD="******">'; $xmlPost .= '<Package ID="' . $usps_packageid . '">'; $xmlPost .= "<Service>" . $shpService . "</Service>"; $xmlPost .= "<ZipOrigination>" . $source_zip . "</ZipOrigination>"; $xmlPost .= "<ZipDestination>" . $dest_zip . "</ZipDestination>"; $xmlPost .= "<Pounds>" . $shipping_pounds . "</Pounds>"; $xmlPost .= "<Ounces>" . $shipping_ounces . "</Ounces>"; $xmlPost .= "<Size>" . $usps_packagesize . "</Size>"; $xmlPost .= "<Machinable>" . $usps_machinable . "</Machinable>"; $xmlPost .= "</Package></RateV2Request>"; // echo htmlentities( $xmlPost ); $host = $usps_server; //$host = "production.shippingapis.com"; $path = $usps_path; //"/ups.app/xml/Rate"; //$path = "/ShippingAPI.dll"; $port = 80; $protocol = "http"; $html = ""; //echo "<textarea>".$protocol."://".$host.$path."?API=Rate&XML=".$xmlPost."</textarea>"; // Using cURL is Up-To-Date and easier!! if (function_exists("curl_init")) { $CR = curl_init(); curl_setopt($CR, CURLOPT_URL, $protocol . "://" . $host . $path); //"?API=RateV2&XML=".$xmlPost); curl_setopt($CR, CURLOPT_POST, 1); curl_setopt($CR, CURLOPT_FAILONERROR, true); curl_setopt($CR, CURLOPT_POSTFIELDS, $xmlPost); curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1); $xmlResult = curl_exec($CR); $error = curl_error($CR); if (!empty($error)) { $GLOBALS['vmLogger']->err(curl_error($CR)); $html = "<br/><span class=\"message\">" . $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . " USPS.com</span>"; $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 USPS is Success or Failure ! */ if (strstr($xmlResult, "Error")) { $error = true; $html = "<span class=\"message\">" . $VM_LANG->_('PHPSHOP_USPS_RESPONSE_ERROR') . "</span><br/>"; $error_code = $xmlDoc->getElementsByTagName("Number"); $error_code = $error_code->item(0); $error_code = $error_code->getText(); $html .= $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . "<br/>"; $error_desc = $xmlDoc->getElementsByTagName("Description"); $error_desc = $error_desc->item(0); $error_desc = $error_desc->getText(); $html .= $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc . "<br/>"; } } curl_close($CR); } else { $protocol = "http"; $fp = fsockopen($protocol . "://" . $host, $errno, $errstr, $timeout = 60); if (!$fp) { $error = true; $html = $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . ": {$errstr} ({$errno})"; } else { //send the server request fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, "Host: {$host}\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: " . strlen($xmlPost) . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $xmlPost . "\r\n\r\n"); $xmlResult = ''; while (!feof($fp)) { $xmlResult .= fgets($fp, 4096); } if (stristr($xmlResult, "Success")) { /* XML Parsing */ require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php'; $xmlDoc = new DOMIT_Lite_Document(); $xmlDoc->parseXML($xmlResult, false, true); $error = false; } else { $html = "Error processing the Request to USPS.com"; $error = true; } } } if (DEBUG) { echo "XML Post: <br>"; echo "<textarea cols='80'>" . $protocol . "://" . $host . $path . "?" . $xmlPost . "</textarea>"; echo "<br>"; echo "XML Result: <br>"; echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>"; echo "<br>"; echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n"; } if ($error) { // comment out, if you don't want the Errors to be shown!! //$vmLogger->err( $html ); // Switch to StandardShipping on Error !!! //require_once( CLASSPATH . 'shipping/standard_shipping.php' ); //$shipping = new standard_shipping(); //$shipping->list_rates( $d ); echo "We are unable to ship USPS as the there was an error,<br> please select another shipping method."; return; } // Domestic shipping - add how long it might take $ship_commit[0] = "1 - 2 Days"; $ship_commit[1] = "1 - 2 Days"; $ship_commit[2] = "1 - 2 Days"; $ship_commit[3] = "1 - 3 Days"; $ship_commit[4] = "1 - 3 Days"; $ship_commit[5] = "1 - 3 Days"; $ship_commit[6] = "2 - 9 Days"; $ship_commit[7] = "2 - 9 Days"; $ship_commit[8] = "2 - 9 Days"; $ship_commit[9] = "2 - 9 Days"; $ship_commit[10] = "2 Days or More"; // retrieve the service and postage items $i = 0; if ($order_weight > 15) { $count = 8; $usps_ship[6] = $usps_ship[7]; $usps_ship[7] = $usps_ship[9]; $usps_ship[8] = $usps_ship[10]; } else { if ($order_weight >= 0.86) { $count = 9; $usps_ship[6] = $usps_ship[7]; $usps_ship[7] = $usps_ship[8]; $usps_ship[8] = $usps_ship[9]; $usps_ship[9] = $usps_ship[10]; } else { $count = 10; } } while ($i <= $count) { if (isset($xmlDoc)) { $ship_service[$i] = $xmlDoc->getElementsByTagName('MailService'); $ship_service[$i] = $ship_service[$i]->item($i); $ship_service[$i] = $ship_service[$i]->getText(); $ship_postage[$i] = $xmlDoc->getElementsByTagName('Rate'); $ship_postage[$i] = $ship_postage[$i]->item($i); $ship_postage[$i] = $ship_postage[$i]->getText(); if (preg_match('/%$/', USPS_HANDLINGFEE)) { $ship_postage[$i] = $ship_postage[$i] * (1 + substr(USPS_HANDLINGFEE, 0, -1) / 100); } else { $ship_postage[$i] = $ship_postage[$i] + USPS_HANDLINGFEE; } $i++; } } /******END OF DOMESTIC RATE******/ } else { /******START INTERNATIONAL RATE******/ //the xml that will be posted to usps $xmlPost = 'API=IntlRate&XML=<IntlRateRequest USERID="' . $usps_username . '" PASSWORD="******">'; $xmlPost .= '<Package ID="' . $usps_packageid . '">'; $xmlPost .= "<Pounds>" . $shipping_pounds_intl . "</Pounds>"; $xmlPost .= "<Ounces>" . $shipping_ounces . "</Ounces>"; $xmlPost .= "<MailType>Package</MailType>"; $xmlPost .= "<Country>" . $dest_country_name . "</Country>"; $xmlPost .= "</Package></IntlRateRequest>"; // echo htmlentities( $xmlPost ); $host = $usps_server; //$host = "production.shippingapis.com"; $path = $usps_path; //"/ups.app/xml/Rate"; //$path = "/ShippingAPI.dll"; $port = 80; $protocol = "http"; //echo "<textarea>".$protocol."://".$host.$path."?API=Rate&XML=".$xmlPost."</textarea>"; // Using cURL is Up-To-Date and easier!! if (function_exists("curl_init")) { $CR = curl_init(); curl_setopt($CR, CURLOPT_URL, $protocol . "://" . $host . $path); //"?API=RateV2&XML=".$xmlPost); curl_setopt($CR, CURLOPT_POST, 1); curl_setopt($CR, CURLOPT_FAILONERROR, true); curl_setopt($CR, CURLOPT_POSTFIELDS, $xmlPost); curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1); $xmlResult = curl_exec($CR); //echo "<textarea>".$xmlResult."</textarea>"; $error = curl_error($CR); if (!empty($error)) { $GLOBALS['vmLogger']->err(curl_error($CR)); $html = "<br/><span class=\"message\">" . $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . " USPS.com</span>"; $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 USPS is Success or Failure ! */ if (strstr($xmlResult, "Error")) { $error = true; $html = "<span class=\"message\">" . $VM_LANG->_('PHPSHOP_USPS_RESPONSE_ERROR') . "</span><br/>"; $error_code = $xmlDoc->getElementsByTagName("Number"); $error_code = $error_code->item(0); $error_code = $error_code->getText(); $html .= $VM_LANG->_('PHPSHOP_ERROR_CODE') . ": " . $error_code . "<br/>"; $error_desc = $xmlDoc->getElementsByTagName("Description"); $error_desc = $error_desc->item(0); $error_desc = $error_desc->getText(); $html .= $VM_LANG->_('PHPSHOP_ERROR_DESC') . ": " . $error_desc . "<br/>"; } } curl_close($CR); } else { $protocol = "http"; $fp = fsockopen($protocol . "://" . $host, $errno, $errstr, $timeout = 60); if (!$fp) { $error = true; $html = $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . ": {$errstr} ({$errno})"; } else { //send the server request fputs($fp, "POST {$path} HTTP/1.1\r\n"); fputs($fp, "Host: {$host}\r\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: " . strlen($xmlPost) . "\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $xmlPost . "\r\n\r\n"); $xmlResult = ''; while (!feof($fp)) { $xmlResult .= fgets($fp, 4096); } if (stristr($xmlResult, "Success")) { /* XML Parsing */ require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php'; $xmlDoc = new DOMIT_Lite_Document(); $xmlDoc->parseXML($xmlResult, false, true); $error = false; } else { $html = "Error processing the Request to USPS.com"; $error = true; } } } if (DEBUG) { echo "XML Post: <br>"; echo "<textarea cols='80'>" . $protocol . "://" . $host . $path . "?" . $xmlPost . "</textarea>"; echo "<br>"; echo "XML Result: <br>"; echo "<textarea cols='80' rows='10'>" . $xmlResult . "</textarea>"; echo "<br>"; echo "Cart Contents: " . $order_weight . " " . $weight_measure . "<br><br>\n"; } if ($error) { // comment out, if you don't want the Errors to be shown!! //$vmLogger->err( $html ); // Switch to StandardShipping on Error !!! //require_once( CLASSPATH . 'shipping/standard_shipping.php' ); //$shipping = new standard_shipping(); //$shipping->list_rates( $d ); //return; echo "We are unable to ship USPS as there was an error,<br> please select another shipping method."; } // retrieve the service and postage items $i = 0; $numChildren = 0; $numChildren = $xmlDoc->documentElement->firstChild->childCount; $numChildren = $numChildren - 7; // this line removes the preceeding 6 lines of crap not needed plus 1 to make up for the $i starting at 0 while ($i <= $numChildren) { if (isset($xmlDoc)) { $ship_service[$i] = $xmlDoc->getElementsByTagName("SvcDescription"); $ship_service[$i] = $ship_service[$i]->item($i); $ship_service[$i] = $ship_service[$i]->getText(); $ship_weight[$i] = $xmlDoc->getElementsByTagName("MaxWeight"); $ship_weight[$i] = $ship_weight[$i]->item($i); $ship_weight[$i] = $ship_weight[$i]->getText($i); } $i++; } // retrieve postage for countries that support all nine shipping methods and weights $ship_weight[8] = $ship_weight[8] / 16; if ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5] && $ship_weight[6] && $ship_weight[7] && $ship_weight[8]) { $count = 8; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5] && $ship_weight[6] && $ship_weight[7]) { $count = 7; // $usps_intl[6] = $usps_intl[7]; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5] && $ship_weight[6]) { $count = 6; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4] && $ship_weight[5]) { $count = 5; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3] && $ship_weight[4]) { $count = 4; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2] && $ship_weight[3]) { $count = 3; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1] && $ship_weight[2]) { $count = 2; } elseif ($order_weight <= $ship_weight[0] && $ship_weight[1]) { $count = 1; } elseif ($order_weight <= $ship_weight[0]) { $count = 0; } else { echo "We are unable to ship USPS as the package weight exceeds what your<br>country allows, please select another shipping method."; } $i = 0; while ($i <= $numChildren) { if (isset($xmlDoc)) { $ship_service[$i] = $xmlDoc->getElementsByTagName("SvcDescription"); $ship_service[$i] = $ship_service[$i]->item($i); $ship_service[$i] = $ship_service[$i]->getText(); $ship_commit[$i] = $xmlDoc->getElementsByTagName("SvcCommitments"); $ship_commit[$i] = $ship_commit[$i]->item($i); $ship_commit[$i] = $ship_commit[$i]->getText(); $ship_postage[$i] = $xmlDoc->getElementsByTagName("Postage"); $ship_postage[$i] = $ship_postage[$i]->item($i); $ship_postage[$i] = $ship_postage[$i]->getText($i); $ship_postage[$i] = $ship_postage[$i] + USPS_INTLHANDLINGFEE; $i++; } /******END INTERNATIONAL RATE******/ } } $i = 0; while ($i <= $count) { $html = ""; // USPS returns Charges in USD. $charge[$i] = $ship_postage[$i]; $ship_postage[$i] = $CURRENCY_DISPLAY->getFullValue($charge[$i]); $shipping_rate_id = urlencode(__CLASS__ . "|USPS|" . $ship_service[$i] . "|" . $charge[$i]); //$checked = (@$d["shipping_rate_id"] == $value) ? "checked=\"checked\"" : ""; $html .= "\n<input type=\"radio\" name=\"shipping_rate_id\" checked=\"checked\" value=\"{$shipping_rate_id}\" id=\"{$shipping_rate_id}\" />\n"; $_SESSION[$shipping_rate_id] = 1; $html .= "<label for=\"{$shipping_rate_id}\">"; $html .= "USPS " . $ship_service[$i] . " "; $html .= "<strong>(" . $ship_postage[$i] . ")</strong>"; if (USPS_SHOW_DELIVERY_QUOTE == 1) { $html .= " - " . $ship_commit[$i]; } $html .= "</label>"; $html .= "<br />"; if ($dest_country_name == "United States" && $usps_ship[$i] == "TRUE") { echo $html; } else { if ($dest_country_name != "United States" && $usps_intl[$i] == "TRUE") { echo $html; } } $i++; } } } return true; }
function list_rates(&$d) { global $vmLogger; global $VM_LANG, $CURRENCY_DISPLAY, $mosConfig_absolute_path; /* Read current Configuration */ require_once CLASSPATH . "shipping/" . __CLASS__ . ".cfg.php"; /* * Check the current day and time to determine if it is too late to * ship today. This will have impact on the Saturday delivery * option and the ship date XML field. */ $cur_timestamp = time(); $cur_day_of_week = date('D', $cur_timestamp); $cur_month = date('n', $cur_timestamp); $cur_day_of_month = date('j', $cur_timestamp); $cur_year = date('Y', $cur_timestamp); if ($cur_day_of_week == 'Sun') { /* we don't ship on Sunday */ $shipping_delayed = true; $ship_timestamp = mktime(0, 0, 0, $cur_month, $cur_day_of_month + 1, $cur_year); $ship_delay_msg = $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_NOT_ON_WEEKENDS') . " " . $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_WILL_GO_OUT') . ": " . date('M j, Y', $ship_timestamp); $ship_day = 'Mon'; $ship_date = date('Y-m-d', $ship_timestamp); } else { if ($cur_day_of_week == 'Sat') { /* we don't ship on Saturday */ $shipping_delayed = true; $ship_timestamp = mktime(0, 0, 0, $cur_month, $cur_day_of_month + 2, $cur_year); $ship_delay_msg = $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_NOT_ON_WEEKENDS') . " " . $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_WILL_GO_OUT') . ": " . date('M j, Y', $ship_timestamp); $ship_day = 'Mon'; $ship_date = date('Y-m-d', $ship_timestamp); } else { /* check time */ $shipping_delayed = true; $cur_time = date('Gi'); if ($cur_time > intval(DHL_TOO_LATE)) { /* too late to go out today */ if ($cur_day_of_week == 'Fri') { $ship_timestamp = mktime(0, 0, 0, $cur_month, $cur_day_of_month + 3, $cur_year); $ship_delay_msg = $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_TOO_LATE_TO_SHIP') . " " . $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_WILL_GO_OUT') . ": " . date('M j, Y', $ship_timestamp); $ship_day = 'Mon'; $ship_date = date('Y-m-d', $ship_timestamp); } else { $ship_timestamp = mktime(0, 0, 0, $cur_month, $cur_day_of_month + 1, $cur_year); $ship_delay_msg = $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_TOO_LATE_TO_SHIP') . " " . $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_WILL_GO_OUT') . ": " . date('M j, Y', $ship_timestamp); $ship_day = date('D', $ship_timestamp); $ship_date = date('Y-m-d', $ship_timestamp); } } else { /* it's okay, we can ship today */ $shipping_delayed = false; $ship_day = $cur_day_of_week; $ship_date = date('Y-m-d', $cur_timestamp); } } } $db = new ps_DB(); $cart = $_SESSION['cart']; $q = "SELECT * FROM #__users, #__{vm}_country " . "WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR " . "country=country_3_code)"; $db->query($q); if (!$db->next_record()) { $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); } if ($d['weight'] == 0) { return true; } $dhl_url = "https://eCommerce.airborne.com/"; if (DHL_TEST_MODE == 'TRUE') { $dhl_url .= "ApiLandingTest.asp"; } else { $dhl_url .= "ApiLanding.asp"; } /* We haven't defined any shipping methods yet. */ $methods = array(); /* determine if we are domestic or international */ $dest_country = $db->f("country_2_code"); $dest_state = $db->f("state"); $is_international = $this->is_international($dest_country, $dest_state); if (!$is_international) { if (DHL_EXPRESS_ENABLED == 'TRUE') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_EXPRESS'), 'service_code' => 'E', 'special_service' => '', 'package_type' => DHL_DOMESTIC_PACKAGE, 'international' => false); } if (DHL_NEXT_AFTERNOON_ENABLED == 'TRUE') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_NEXT_AFTERNOON'), 'service_code' => 'N', 'special_service' => '', 'package_type' => DHL_DOMESTIC_PACKAGE, 'international' => false); } if (DHL_SECOND_DAY_ENABLED == 'TRUE') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_SECOND_DAY'), 'service_code' => 'S', 'special_service' => '', 'package_type' => DHL_DOMESTIC_PACKAGE, 'international' => false); } if (DHL_GROUND_ENABLED == 'TRUE') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_GROUND'), 'service_code' => 'G', 'special_service' => '', 'package_type' => DHL_DOMESTIC_PACKAGE, 'international' => false); } if (DHL_1030_ENABLED == 'TRUE') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_1030'), 'service_code' => 'E', 'special_service' => '1030', 'package_type' => DHL_DOMESTIC_PACKAGE, 'international' => false); } // Saturday delivery is only an option on Fridays if (DHL_SATURDAY_ENABLED == 'TRUE' && $ship_day == 'Fri') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_SATURDAY'), 'service_code' => 'E', 'special_service' => 'SAT', 'package_type' => DHL_DOMESTIC_PACKAGE, 'international' => false); } $shipping_key = DHL_DOMESTIC_SHIPPING_KEY; if (DHL_DOMESTIC_PACKAGE != 'E') { $order_weight = $d['weight'] + floatval(DHL_PACKAGE_WEIGHT); } $content_desc = ''; $duty_value = 0; } else { if (DHL_INTERNATIONAL_ENABLED == 'TRUE') { $methods[] = array('service_desc' => $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_INTERNATIONAL'), 'service_code' => 'IE', 'special_service' => '', 'package_type' => DHL_INTERNATIONAL_PACKAGE, 'international' => true); } /* * XXX * We should really walk through the list of each product in * the order and check for special "harmonizing descriptions" * to build our $content_desc variables. */ $content_desc = DHL_CONTENT_DESC; $duty_value = $this->calc_duty_value($d); $shipping_key = DHL_INTERNATIONAL_SHIPPING_KEY; /* DHL country codes are non-standard, remap them */ $dest_country = $this->remap_country_code($dest_country, $dest_state); if (DHL_INTERNATIONAL_PACKAGE != 'E') { $order_weight = $d['weight'] + floatval(DHL_PACKAGE_WEIGHT); } } /* if we're not on an exact integer pound, round */ if (floatval(intval($order_weight)) != $order_weight) { /* round up */ $order_weight = $order_weight + 0.51; $order_weight = round($order_weight, 0); } /* calculate insurance protection value */ $insurance = $this->calc_insurance_value($d, $is_international); require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php'; $html = ''; if ($shipping_delayed) { $html .= '<span class="message"><strong>'; $html .= $ship_delay_msg; $html .= '</strong></span><br />'; } foreach ($methods as $method) { $xmlReq = new DOMIT_Lite_Document(); $xmlReq->setXMLDeclaration('<?xml version="1.0"?>'); $root =& $xmlReq->createElement('eCommerce'); $root->setAttribute('action', 'Request'); $root->setAttribute('version', '1.1'); $xmlReq->setDocumentElement($root); $requestor =& $xmlReq->createElement('Requestor'); $id =& $xmlReq->createElement('ID'); $id->setText(DHL_ID); $requestor->appendChild($id); $password =& $xmlReq->createElement('Password'); $password->setText(DHL_PASSWORD); $requestor->appendChild($password); $root->appendChild($requestor); /* International Rate Estimate Request */ if ($method['international']) { $shipment =& $xmlReq->createElement('IntlShipment'); } else { $shipment =& $xmlReq->createElement('Shipment'); } $shipment->setAttribute('action', 'RateEstimate'); $shipment->setAttribute('version', '1.0'); $creds =& $xmlReq->createElement('ShippingCredentials'); $ship_key =& $xmlReq->createElement('ShippingKey'); $ship_key->setText($shipping_key); $creds->appendChild($ship_key); $an =& $xmlReq->createElement('AccountNbr'); $an->setText(DHL_ACCOUNT_NUMBER); $creds->appendChild($an); $shipment->appendChild($creds); $detail =& $xmlReq->createElement('ShipmentDetail'); $date =& $xmlReq->createElement('ShipDate'); $date->setText($ship_date); $detail->appendChild($date); $service =& $xmlReq->createElement('Service'); $code =& $xmlReq->createElement('Code'); $code->setText($method['service_code']); $service->appendChild($code); $detail->appendChild($service); $stype =& $xmlReq->createElement('ShipmentType'); $code =& $xmlReq->createElement('Code'); $code->setText($method['package_type']); $stype->appendChild($code); if ($insurance > 0 && DHL_ADDITIONAL_PROTECTION != 'NR') { /* include additional value protection */ $addl_prot =& $xmlReq->createElement('AdditionalProtection'); $code =& $xmlReq->createElement('Code'); $code->setText(DHL_ADDITIONAL_PROTECTION); $addl_prot->appendChild($code); $value =& $xmlReq->createElement('Value'); $value->setText(round($insurance, 0)); $addl_prot->appendChild($value); $detail->appendChild($addl_prot); } $detail->appendChild($stype); if ($method['international']) { $desc =& $xmlReq->createElement('ContentDesc'); /* CDATA description */ $desc_text =& $xmlReq->createCDATASection($content_desc); $desc->appendChild($desc_text); $detail->appendChild($desc); } $weight =& $xmlReq->createElement('Weight'); $weight->setText($order_weight); $detail->appendChild($weight); if ($method['special_service'] != '') { $sservices =& $xmlReq->createElement('SpecialServices'); $service =& $xmlReq->createElement('SpecialService'); $code =& $xmlReq->createElement('Code'); $code->setText($method['special_service']); $service->appendChild($code); $sservices->appendChild($service); $detail->appendChild($sservices); } $shipment->appendChild($detail); if ($method['international']) { $dutiable =& $xmlReq->createElement('Dutiable'); $dflag =& $xmlReq->createElement('DutiableFlag'); if ($duty_value == 0) { $dflag->setText('N'); $dutiable->appendChild($dflag); } else { $dflag->setText('Y'); $dutiable->appendChild($dflag); $dval =& $xmlReq->createElement('CustomsValue'); $dval->setText(round($duty_value, 0)); $dutiable->appendChild($dval); } $shipment->appendChild($dutiable); } $billing =& $xmlReq->createElement('Billing'); $party =& $xmlReq->createElement('Party'); $code =& $xmlReq->createElement('Code'); /* Always bill shipper */ $code->setText('S'); $party->appendChild($code); $billing->appendChild($party); if ($method['international']) { $duty_payer =& $xmlReq->createElement('DutyPaymentType'); /* receiver pays duties */ $duty_payer->setText('R'); $billing->appendChild($duty_payer); } $shipment->appendChild($billing); $recv =& $xmlReq->createElement('Receiver'); $addr =& $xmlReq->createElement('Address'); // Handle address_1 $address_1 = $db->f('address_1'); if (strlen($address_1) > 35) { $address_1 = substr($address_1, 0, 35); $vmLogger->debug('Address 1 too long. Shortened to 35 characters.'); } $street_addr =& $xmlReq->createCDATASection($address_1); $street =& $xmlReq->createElement('Street'); $street->appendChild($street_addr); $addr->appendChild($street); // Handle address_2 $address_2 = $db->f('address_2'); if (strlen($address_2) > 35) { $address_2 = substr($address_2, 0, 35); $vmLogger->debug('Address 2 too long. Shortened to 35 characters.'); } $street_addr2 =& $xmlReq->createCDATASection($address_2); $street2 =& $xmlReq->CreateElement('StreetLine2'); $street2->appendChild($street_addr2); $addr->appendChild($street2); $city =& $xmlReq->createElement('City'); $city_name =& $xmlReq->createCDATASection($db->f('city')); $city->appendChild($city_name); $addr->appendChild($city); if ($db->f('state') != '') { $state =& $xmlReq->createElement('State'); $state->setText($db->f('state')); $addr->appendChild($state); } $country =& $xmlReq->createElement('Country'); $country->setText($dest_country); $addr->appendChild($country); if ($db->f('zip') != '') { $pc =& $xmlReq->createElement('PostalCode'); $pc->setText($db->f('zip')); $addr->appendChild($pc); } $recv->appendChild($addr); $shipment->appendChild($recv); $root->appendChild($shipment); // $vmLogger->err($xmlReq->toNormalizedString()); if (function_exists("curl_init")) { $CR = curl_init(); curl_setopt($CR, CURLOPT_URL, $dhl_url); curl_setopt($CR, CURLOPT_POST, 1); curl_setopt($CR, CURLOPT_FAILONERROR, true); curl_setopt($CR, CURLOPT_POSTFIELDS, $xmlReq->toString()); curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1); $xmlResult = curl_exec($CR); $error = curl_error($CR); if (!empty($error)) { $vmLogger->err(curl_error($CR)); $html = '<br/><span class="message">' . $VM_LANG->_('PHPSHOP_INTERNAL_ERROR') . ' DHL</span>'; return false; } curl_close($CR); } // XML Parsing $xmlResp = new DOMIT_Lite_Document(); if (!$xmlResp->parseXML($xmlResult, false, true)) { $vmLogger->err($VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_INVALID_XML') . $xmlResult); $html .= '<br /><span class="message">' . $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_INVALID_XML') . '</span>'; continue; } // $vmLogger->err($xmlResp->toNormalizedString()); // Check for success or failure. $result_code_list =& $xmlResp->getElementsByPath('//Result/Code'); $result_code =& $result_code_list->item(0); $result_desc_list =& $xmlResp->getElementsByPath('//Result/Desc'); $result_desc =& $result_desc_list->item(0); if ($result_code == NULL) { $html .= $VM_LANG->_('PHPSHOP_ERROR_DESC') . ': ' . $VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_MISSING_RESULT'); $vmLogger->debug($VM_LANG->_('PHPSHOP_SHIPPING_METHOD_DHL_MISSING_RESULT') . "\n" . $xmlResp->toNormalizedString()); continue; } // '203' is the code for success (at least with domestic) if ($result_code->getText() != '203') { $html .= '<br /><span class="message">' . $method['service_desc'] . ': ' . $result_desc->getText() . ' [code ' . $result_code->getText() . ']' . '</span>'; // display an error line for each fault $fault_node_list =& $xmlResp->getElementsByPath('//Faults/Fault'); if ($fault_node_list->getLength() > 0) { $html .= '<ul>'; } for ($i = 0; $i < $fault_node_list->getLength(); $i++) { $fault_node =& $fault_node_list->item($i); $fault_code_node_list =& $fault_node->getElementsByTagName('Code'); $fault_desc_node_list =& $fault_node->getElementsByTagName('Desc'); $fault_code_node =& $fault_code_node_list->item(0); $fault_desc_node =& $fault_desc_node_list->item(0); $html .= '<li>' . $fault_desc_node->getText() . ' [code ' . $fault_code_node->getText() . ']</li>'; } if ($fault_node_list->getLength() > 0) { $html .= '</ul>'; } continue; } else { $deliver_date_node_list =& $xmlResp->getElementsByPath('//ServiceLevelCommitment/Desc'); $deliver_date_node =& $deliver_date_node_list->item(0); $deliver_date = $deliver_date_node->getText(); $ship_rate_node_list =& $xmlResp->getElementsByTagName('TotalChargeEstimate'); $ship_rate_node =& $ship_rate_node_list->item(0); $ship_rate = $ship_rate_node->getText(); /* * If DHL freaks out and gives us a $0.00 shipping * rate, don't list the option. */ if ($ship_rate == 0.0) { continue; } $total_rate = $ship_rate + floatval(DHL_HANDLING_FEE); $ship_postage = $CURRENCY_DISPLAY->getFullValue($total_rate); /* * Leave the shipping class field empty * since it looks ugly. The information we need to * generate a shipping label for this rate will be * stored one off the end. */ $id_string = __CLASS__; $id_string .= "|DHL"; $id_string .= "|" . $method['service_desc']; $id_string .= "|" . $total_rate; $id_string .= "|"; $id_string .= "|" . $ship_date; $id_string .= ";" . $method['service_code']; $id_string .= ";" . $method['special_service']; $id_string .= ";" . $method['package_type']; if ($method['international']) { $id_string .= ";T"; } else { $id_string .= ";F"; } $id_string .= ";" . DHL_ADDITIONAL_PROTECTION; $id_string .= ";" . $order_weight; $id_string .= ";" . $duty_value; $id_string .= ";" . $insurance; $id_string .= ";" . $content_desc; $shipping_rate_id = urlencode($id_string); $html .= "\n<input type=\"radio\" " . "name=\"shipping_rate_id\"" . " value=\"{$shipping_rate_id}\" />\n"; $_SESSION[$shipping_rate_id] = 1; $html .= "DHL " . $method['service_desc']; $html .= " <strong>(" . $ship_postage . ")</strong>"; $html .= " - " . $deliver_date; $html .= "<br />"; } } echo $html; return true; }
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 .= " - " . $value['GuaranteedDaysToDelivery'] . " " . $VM_LANG->_('PHPSHOP_UPS_SHIPPING_GUARANTEED_DAYS'); } } if (Show_Delivery_ETA_Quote == 1) { if (!empty($value['ScheduledDeliveryTime'])) { $html .= " (ETA: " . $value['ScheduledDeliveryTime'] . ")"; } } if (Show_Delivery_Warning == 1 && !empty($value['RatedShipmentWarning'])) { $html .= "</label><br/>\n * <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; }