internal_name = "ups"; $this->name="UPS"; $this->is_external=true; $this->requires_curl=true; $this->requires_weight=true; $this->needs_zipcode=true; $this->_includeUPSData(); $this->_setServiceURL(); return true; } function getId() { // return $this->usps_id; } function setId($id) { // $usps_id = $id; // return true; } private function _setServiceURL(){ global $wpdb; $wpsc_ups_settings = get_option("wpsc_ups_settings"); $wpsc_ups_environment = $wpsc_ups_settings["upsenvironment"]; if ($wpsc_ups_environment == "1"){ $this->service_url = "https://www.ups.com/ups.app/xml/Rate"; }else{ $this->service_url = "https://wwwcie.ups.com/ups.app/xml/Rate"; } } function getName() { return $this->name; } function getInternalName() { return $this->internal_name; } private function _includeUPSData(){ list($eol,$Auth,$MessageStart,$RateRequest, $RateService, $RatePackage, $RateCustomPacakge,$RateRequestEnd, $Services) = include 'ups_data.php'; $this->MessageStart = $MessageStart; $this->RateRequest = $RateRequest; $this->RateService = $RateService; $this->RatePackage = $RatePackage; $this->RateCustomPackage = $RateCustomPacakge; $this->RateRequestEnd = $RateRequestEnd; $this->Services = $Services; } function getForm(){ if (!isset($this->Services)){ $this->_includeUPSData(); } //__('Your Packaging', 'wpsc'); <-- use to translate $wpsc_ups_settings = get_option("wpsc_ups_settings"); $wpsc_ups_services = get_option("wpsc_ups_services"); // Defined on page 41 in UPS API documentation RSS_Tool_06_10_09.pdf /*$packaging_options['00'] = __('**UNKNOWN**', 'wpsc');*/ $packaging_options['01'] = __('UPS Letter', 'wpsc'); $packaging_options['02'] = __('Your Packaging', 'wpsc'); $packaging_options['03'] = __('UPS Tube', 'wpsc'); $packaging_options['04'] = __('UPS Pak', 'wpsc'); $packaging_options['21'] = __('UPS Express Box', 'wpsc'); $packaging_options['2a'] = __('UPS Express Box - Small', 'wpsc'); $packaging_options['2b'] = __('UPS Express Box - Medium', 'wpsc'); $packaging_options['2c'] = __('UPS Express Box - Large', 'wpsc'); $output = "
Node from the chunk
$getServiceCodeNode = $serviceNode->getElementsByTagName("Code");
// Get the value from
$serviceCode = $getServiceCodeNode->item(0)->nodeValue;
// Get the Node from the XML chunk
$getChargeNodes = $rate_block->getElementsByTagName("TotalCharges");
$chargeNode = $getChargeNodes->item(0);
// Get the from the chunk
$getCurrNode= $chargeNode->getElementsByTagName("CurrencyCode");
// Get the value of
$currCode = $getCurrNode->item(0)->nodeValue;
// Get the from the chunk
$getMonetaryNode= $chargeNode->getElementsByTagName("MonetaryValue");
// Get the value of
$price = $getMonetaryNode->item(0)->nodeValue;
// If there are any services specified in the admin area
// this will check that list and pass on adding any services that
// are not explicitly defined.
if (!empty($wpsc_ups_services)){
if (is_array($wpsc_ups_services)){
if (array_search($serviceCode, $wpsc_ups_services) === false){
continue;
}
}else if ($wpsc_ups_services != $serviceCode){
continue;
}
}
if(array_key_exists($serviceCode,$this->Services)){
$rate_table[$this->Services[$serviceCode]] = array($currCode,$price);
}
} // End foreach rated shipment block
}
}
// Revers sort the rate selection so it is cheapest First!
asort($rate_table);
return $rate_table;
}
private function _formatTable($services, $currency=false){
/* The checkout template expects the array to be in a certain
* format. This function will iterate through the provided
* services array and format it for use. During the loop
* we take advantage of the loop and translate the currency
* if necessary based off of what UPS tells us they are giving us
* for currency and what is set for the main currency in the settings
* area
*/
$converter = null;
if ($currency){
$converter = new CURRENCYCONVERTER();
}
$finalTable = array();
foreach(array_keys($services) as $service){
if ($currency != false && $currency != $services[$service][0]){
$temp =$services[$service][1];
$services[$service][1] = $converter->convert($services[$service][1],
$currency,
$services[$service][0]);
}
$finalTable[$service] = $services[$service][1];
}
return $finalTable;
}
function getQuote(){
global $wpdb;
// Arguments array for various functions to use
$args = array();
// Final rate table
$rate_table = array();
// Get the ups settings from the ups account info page (Shipping tab)
$wpsc_ups_settings = get_option("wpsc_ups_settings");
// Get the wordpress shopping cart options
$wpsc_options = get_option("wpsc_options");
// API Auth settings //
$args['username'] = $wpsc_ups_settings['upsusername'];
$args['password'] = $wpsc_ups_settings['upspassword'];
$args['api_id'] = $wpsc_ups_settings['upsid'];
// What kind of pickup service do you use ?
$args['pickup_type'] = "01";
$args['packaging'] = $wpsc_ups_settings['48_container'];
// Preferred Currency to display
$currency_data = $wpdb->get_row("SELECT `code`
FROM `".WPSC_TABLE_CURRENCY_LIST."`
WHERE `isocode`='".$wpsc_options['currency_type']."'
LIMIT 1",ARRAY_A) ;
if ($currency_data){
$args['currency'] = $currency_data['code'];
}else{
$args['currency'] = "USD";
}
// Shipping billing / account address
$args['shipr_ccode'] = get_option('base_country');
$args['shipr_pcode'] = get_option('base_zipcode');
// Physical Shipping addres being shipped from
$args['shipf_ccode'] = get_option('base_country');
$args['shipf_pcode'] = get_option('base_zipcode');
// Get the total weight from the shopping cart
$args['units'] = "LBS";
$args['weight'] = wpsc_cart_weight_total();
// Destination zip code
$args['dest_ccode'] = $_SESSION['wpsc_delivery_country'];
if ($args['dest_ccode'] == "UK"){
// So, UPS is a little off the times
$args['dest_ccode'] = "GB";
}
// If ths zip code is provided via a form post use it!
if(isset($_POST['zipcode'])) {
$args['dest_pcode'] = $_POST['zipcode'];
$_SESSION['wpsc_zipcode'] = $_POST['zipcode'];
} else if(isset($_SESSION['wpsc_zipcode'])) {
// Well, we have a zip code in the session and no new one provided
$args['dest_pcode'] = $_SESSION['wpsc_zipcode'];
}else{
// We cannot get a quote without a zip code so might as well return!
return array();
}
$shipping_cache_check['zipcode'] = $args['dest_pcode'];
$shipping_cache_check['weight'] = $args['weight'];
// This is where shipping breaks out of UPS if weight is higher than 150 LBS
if($weight > 150){
unset($_SESSION['quote_shipping_method']);
$shipping_quotes[TXT_WPSC_OVER_UPS_WEIGHT] = 0;
$_SESSION['wpsc_shipping_cache_check']['weight'] = $args['weight'];
$_SESSION['wpsc_shipping_cache'][$this->internal_name] = $shipping_quotes;
$_SESSION['quote_shipping_method'] = $this->internal_name;
return array($shipping_quotes);
}
// We do not want to spam UPS (and slow down our process) if we already
// have a shipping quote!
if(($_SESSION['wpsc_shipping_cache_check'] === $shipping_cache_check)
&& ($_SESSION['wpsc_shipping_cache'][$this->internal_name] != null)) {
$rate_table = $_SESSION['wpsc_shipping_cache'][$this->internal_name];
}else{
// Build the XML request
$request = $this->_buildRateRequest($args);
// Now that we have the message to send ... Send it!
$raw_quote = $this->_makeRateRequest($request);
// Now we have the UPS response .. unfortunately its not ready
// to be viewed by normal humans ...
$quotes = $this->_parseQuote($raw_quote);
// If we actually have rates back from UPS we can use em!
if ($quotes != false){
$rate_table = $this->_formatTable($quotes,$args['currency']);
}
}
// return the final formatted array !
$_SESSION['wpsc_shipping_cache_check']['zipcode'] = $args['dest_pcode'];
$_SESSION['wpsc_shipping_cache_check']['weight'] = $args['weight'];
$_SESSION['wpsc_shipping_cache'][$this->internal_name] = $rate_table;
return $rate_table;
}
// Empty Function, this exists just b/c it is prototyped elsewhere
function get_item_shipping(){
}
}
$ups = new ups();
$wpsc_shipping_modules[$ups->getInternalName()] = $ups;
?>