Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

UPSXML and UPS Choice merge


mugitty

Recommended Posts

I have been trying to get the UPSXML contribution to allow for choice of shipping options as used in the UPS Choice contribution. I can get to the point of having the options show up in Admin with their appropriate checkboxes and I am able to select multiple options but, when I add something to the shopping cart and look at the shipping portion of checkout, none of the rates appear. I don't get any error messages - just the UPS title and no individual rates.

 

In comparing UPS Choice with the stock UPS shipping module, the differences appear to be in the "quote" function, the addition of the shipping methods into the "install" function and the addition of the shipping methods to the "key" function

 

The UPS Choice mod has

$this->types = array('1DM' => 'Next Day Air Early AM', etc...

in the "ups" function which is picked up in the additional "install" query mentioned above while the UPSXML mod does not have this "types" array - in its place there is

$this->service_codes = array(

// US Origin

'US Origin' => array(

'01' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_01, etc...

 

I assume the ability to make the shipping options selectable through the Admin would be accomplished by adding a field for "types" or "service_codes" to the "install" and "keys" functions and making the appropriate changes in the "quote" function to display only "$allowed_methods", but I haven't been able to get it to work.

 

I'm posting below the complete "quote" function for each the UPS Choice and the UPSXML mods. If anyone can help with what code changes would be needed, it would be greatly appreciated!

 

UPS Choice

    function quote($method = '') {
     global $HTTP_POST_VARS, $order, $shipping_weight, $shipping_num_boxes;

     if ( (tep_not_null($method)) && (isset($this->types[$method])) ) {
       $prod = $method;
     } else if ($order->delivery['country']['iso_code_2'] == 'CA') {
    $prod = 'STD';
     } else {
       $prod = 'GNDRES';
     }

     if ($method) $this->_upsAction('3'); // return a single quote

     $this->_upsProduct($prod);

     $country_name = tep_get_countries(SHIPPING_ORIGIN_COUNTRY, true);
     $this->_upsOrigin(SHIPPING_ORIGIN_ZIP, $country_name['countries_iso_code_2']);
     $this->_upsDest($order->delivery['postcode'], $order->delivery['country']['iso_code_2']);
     $this->_upsRate(MODULE_SHIPPING_UPS_PICKUP);
     $this->_upsContainer(MODULE_SHIPPING_UPS_PACKAGE);
     $this->_upsWeight($shipping_weight);
     $this->_upsRescom(MODULE_SHIPPING_UPS_RES);

     $upsQuote = $this->_upsGetQuote();

     if ( (is_array($upsQuote)) && (sizeof($upsQuote) > 0) ) {
       $this->quotes = array('id' => $this->code,
                             'module' => $this->title . ' (' . $shipping_num_boxes . ' x ' . $shipping_weight . 'lbs)');

       $methods = array();
 $allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
 $std_rcd = false;
       $qsize = sizeof($upsQuote);

       for ($i=0; $i<$qsize; $i++) {
         list($type, $cost) = each($upsQuote[$i]);
   if ($type=='STD') {
    if ($std_rcd) continue;
    else $std_rcd = true;
	 };
   if (!in_array($type, $allowed_methods)) continue;
         $methods[] = array('id' => $type,
                            'title' => $this->types[$type],
                            'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
       }

       $this->quotes['methods'] = $methods;

 if ($this->tax_class > 0) {
         $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
       }
     } else {
       $this->quotes = array('module' => $this->title,
                             'error' => 'We are unable to obtain a rate quote for UPS shipping.<br>Please contact the store if no other alternative is shown.');
     }

     if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

     return $this->quotes;
   }

 

UPSXML

    function quote($method = '') {
 global $HTTP_POST_VARS, $order, $shipping_weight, $shipping_num_boxes, $total_weight, $boxcount, $cart;
    
 // UPS purports that if the origin is left out, it defaults to the account's location. Yeah, right.
 $state = $order->delivery['state'];
    $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_name = '" .  $order->delivery['state'] . "'");
 if (tep_db_num_rows($zone_query)) {
   $zone = tep_db_fetch_array($zone_query);
   $state = $zone['zone_code'];
 }

 $this->_upsOrigin(MODULE_SHIPPING_UPSXML_RATES_CITY, MODULE_SHIPPING_UPSXML_RATES_STATEPROV, MODULE_SHIPPING_UPSXML_RATES_COUNTRY, MODULE_SHIPPING_UPSXML_RATES_POSTALCODE);
 $this->_upsDest($order->delivery['city'], $state, $order->delivery['country']['iso_code_2'], $order->delivery['postcode']);

 $productsArray = $cart->get_products();

 if (DIMENSIONS_SUPPORTED) {
	 //Use packing algoritm to return the number of boxes we'll ship
	 $boxesToShip = $this->packProducts($productsArray);
	 //quote for the number of boxes
	 for ($i = 0; $i < count($boxesToShip); $i++) {
   $this->_addItem($boxesToShip[$i]['length'], $boxesToShip[$i]['width'], $boxesToShip[$i]['height'], $boxesToShip[$i]['current_weight']);
   $totalWeight += $boxesToShip[$i]['current_weight'];
	 }
 } else {
	 // The old method. Let osCommerce tell us how many boxes, plus the weight of each (or total?? might be sw / num boxes)
	 for ($i = 0; $i < $shipping_num_boxes; $i++) {
   $this->_addItem (0, 0, 0, $shipping_weight);
	 }
 }
            $this->timeintransit = $this->_upsgetTime();  
               if ($this->logfile) {
      error_log("------------------------------------------\n", 3, $this->logfile);
      error_log("Time in Transit: " . $this->timeintransit . "\n", 3, $this->logfile);
   }


 $upsQuote = $this->_upsGetQuote();
 
 if ((is_array($upsQuote)) && (sizeof($upsQuote) > 0)) {
	 if (DIMENSIONS_SUPPORTED) {
   $this->quotes = array('id' => $this->code, 'module' => $this->title . ' (' . $this->boxCount . ($this->boxCount > 1 ? ' pkg(s), ' : ' pkg, ') . $totalWeight . ' ' . strtolower($this->unit_weight) . ' total)');
	 } else {
   $this->quotes = array('id' => $this->code, 'module' => $this->title . ' (' . $shipping_num_boxes . ($this->boxCount > 1 ? ' pkg(s) x ' : ' pkg x ') . $shipping_weight . ' ' . strtolower($this->unit_weight) . ' total)');
	 }
	 
	 $methods = array();

// add from UPS Choice to allow for method selection
 $allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
 $std_rcd = false;
       $qsize = sizeof($upsQuote);

       for ($i=0; $i<$qsize; $i++) {
         list($type, $cost) = each($upsQuote[$i]);
   if ($type=='STD') {
    if ($std_rcd) continue;
    else $std_rcd = true;
	 };
   if (!in_array($type, $allowed_methods)) continue;
         $methods[] = array('id' => $type,
                            'title' => $this->types[$type],
                            'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
       }
// end add from UPS Choice

// 	 for ($i=0; $i < sizeof($upsQuote); $i++) {
//    list($type, $cost) = each($upsQuote[$i]);
//    if ( $method == '' || $method == $type ) {
//   	 $methods[] = array('id' => $type, 'title' => $type, 'cost' => ($this->handling_fee + $cost));
//    }
// 	 }

	 if ($this->tax_class > 0) {
   $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
	 }

	 $this->quotes['methods'] = $methods;

 } else {
	 if ( $upsQuote != false ) {
   $errmsg = $upsQuote;
	 } else {
   $errmsg = MODULE_SHIPPING_UPSXML_RATES_TEXT_UNKNOWN_ERROR;
	 }
	 $errmsg .= '<br>' . MODULE_SHIPPING_UPSXML_RATES_TEXT_IF_YOU_PREFER . ' ' . STORE_NAME.' via <a href="mailto:'.STORE_OWNER_EMAIL_ADDRESS.'"><u>Email</U></a>.';
	 $this->quotes = array('module' => $this->title, 'error' => $errmsg);
 }

 if (tep_not_null($this->icon)) {
	 $this->quotes['icon'] = tep_image($this->icon, $this->title);
 }
 
 return $this->quotes;
   }

... if you want to REALLY see something that doesn't set up right out of the box without some tweaking,

try being a Foster Parent!

Link to comment
Share on other sites

UPSXML.php: In the "function _parseResult($xmlResult)" section (line 634), there is a line that reads

$title = $this->service_codes[$this->origin][$serviceCode];

Should I be trying to use

$this->service_codes[$this->origin][$serviceCode]

or some variation of it in the "$allowed_methods" statement to cause the results to be displayed?

... if you want to REALLY see something that doesn't set up right out of the box without some tweaking,

try being a Foster Parent!

Link to comment
Share on other sites

If I need to pull 2 keys from the configuration table (MODULE_SHIPPING_UPSXML_RATES_ORIGIN and MODULE_SHIPPING_UPSXML_RATES_TYPES) to determine $allowed_methods, what would be the correct syntax?

 

The UPS Choice, which only uses 1 key uses this

$allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);

... if you want to REALLY see something that doesn't set up right out of the box without some tweaking,

try being a Foster Parent!

Link to comment
Share on other sites

I could really use a bit of guidance here...

 

I have added a new entry to configuration thusly

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ( 'Shipping Methods', 'MODULE_SHIPPING_UPSXML_TYPES', 'Next Day/Express,2nd Day,Ground,Express/WW Express,Expedited,Standard Canada,3 Day Select,Next Saver/Express Saver,Next AM/Express AM,WW Express Plus,2nd Day AM,Express NA1,Express Saver', 'Select the UPS services to be offered.', '6', '19', 'tep_cfg_select_multioption(array(\'01\', \'02\', \'03\', \'07\', \'08\', \'11\', \'12\', \'13\', \'14\', \'54\', \'59\', \'64\', \'65\'), ', now() )");

and added the tep_cfg_select_multioption function previously.

 

I have added to the array for the keys function MODULE_SHIPPING_UPSXML_TYPES

 

Then I have changed a portion of the original quote function from

 	 $methods = array();
	 for ($i=0; $i < sizeof($upsQuote); $i++) {
   list($type, $cost) = each($upsQuote[$i]);
   if ( $method == '' || $method == $type ) {
  	 $methods[] = array('id' => $type, 'title' => $type, 'cost' => ($this->handling_fee + $cost));
   }
	 }

to

 	 $methods = array();

 $allowed_methods = explode(", ", MODULE_SHIPPING_UPSXML_TYPES); //add for method selection

	 for ($i=0; $i < sizeof($upsQuote); $i++) {
   list($type, $cost) = each($upsQuote[$i]);
        if (!in_array($type, $allowed_methods)) continue;
//         if ( $method == '' || $method == $type ) {
  	 $methods[] = array('id' => $type,
                                            'title' => $this->service_codes[$type],
                                            'cost' => ($this->handling_fee + $cost));
//    }
	 }

I am able to select desired methods in Admin from the new key being added without issue.

 

I get no errors, but when I look at checkout_shipping.php from the customer's view, I get the shipping mod title only - United Parcel Service (XML) (1 pkg x 11 lbs total) with no rates below it.

 

Any ideas about what to do to get the selected rates to appear?

... if you want to REALLY see something that doesn't set up right out of the box without some tweaking,

try being a Foster Parent!

Link to comment
Share on other sites

Well, it looks like I'm going to have to beg for help here

Please, please, please, pleeeeeze, sniffle

 

I've tried a dozen different ways to get this done - some produced errors, some didn't, and I just cannot get the individual chosen rates to show when I try to do this.

 

The main reason for wanting to do this is because I think it's a bit absurd (not to mention cluttered looking) to show a customer "Next Day Air, "Next Day Air Early AM" and "Next Day Air Saver"... If they want it the next day, just give one choice!

 

Can anyone who has more knowledge and coding expertise than me please offer some help as to how I can write selectable methods into UPSXML (a la UPS Choice and USPS Methods). I would love to get this done so I could kick it back to the community along with the updated instructions for the dimensional support option (which is already completed)

 

-> Maybe some of you 3,000+ post guys? (congrats! Burt) - y'all must know more than I do about how to do this!

... if you want to REALLY see something that doesn't set up right out of the box without some tweaking,

try being a Foster Parent!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...