Jump to content
Sign in to follow this  
queasyprawn

Force UPS Next Day Shipping

Recommended Posts

I have a store that has products ranging from shirts & hats, to sauces & seasonings, to food. For everything but the food I can use any UPS Shipping method but for the food I require it to be shipped UPS Next Day Air.

 

Is there a way I can specifiy anything in the food catagory gives only Next Day Air shipping options?

 

Please let me know.

 

Thanks,

txcrew

Share this post


Link to post
Share on other sites

I did some poking around in the forums and in the code. Now Im very much a beginner in code so PLEASE correct me if Im going down the wrong track or trying to do somthing that cannot be done.

 

Can something like an IF or ELSE statement be placed around this code in the shipping methods that basically said IF in the food catagory THEN only ups next day ELSE all of the ups shipping methods:

 

 

$methods[] = array('id' => $type,

'title' => 'Code: '. $type . " - " . $this->types[$type],

'cost' => (SHIPPING_HANDLING + $cost) * $shipping_num_boxes);

 

 

 

or maybe the code could be in this file includes/modules/shipping/ups.php

 

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

'1DML' => 'Next Day Air Early AM Letter',

'1DA' => 'Next Day Air',

'1DAL' => 'Next Day Air Letter',

'1DAPI' => 'Next Day Air Intra (Puerto Rico)',

'1DP' => 'Next Day Air Saver',

'1DPL' => 'Next Day Air Saver Letter',

'2DM' => '2nd Day Air AM',

'2DML' => '2nd Day Air AM Letter',

'2DA' => '2nd Day Air',

'2DAL' => '2nd Day Air Letter',

'3DS' => '3 Day Select',

'GND' => 'Ground',

'GNDCOM' => 'Ground Commercial',

'GNDRES' => 'Ground Residential',

'STD' => 'Canada Standard',

'XPR' => 'Worldwide Express',

'XPRL' => 'worldwide Express Letter',

'XDM' => 'Worldwide Express Plus',

'XDML' => 'Worldwide Express Plus Letter',

'XPD' => 'Worldwide Expedited');

 

 

again, if Im way off with what to do please tell me. I have no idea what to do here and I really need this option to run my store.

 

Thanks all!

 

txcrew

Share this post


Link to post
Share on other sites

Okay, I think I have a logical way to make this work, but I am going to need some programming help with the PHP since I am not even a half-assed PHP hacker.

 

In the UPS module, either only get the quotes for air shipment or get all the quotes and discard the ground type quotes. This is probably going to be answered on which is easier - modifing the array that holds that info, or writing a new function. (I'm guessing modifing the array after the fact; but that is me)

 

The UPS module has to do the above, if the cart is found to have an item that requires air shipping. I'm guessing that the way to do this is to add another column in products and have a query look through the cart to check for that column having a value of, basically, air ship only. The query sees that result, and says, hey, set this variable so the UPS module does this special thing.

 

I'm assuming from the bit of playing around I did with the ups.php file, that if the array only contains air ship options, that is all that will be displayed; I won't have a radio button with no text to go with it.

 

So, that being said, will somebody be able to help?

 

Thanks,

Rick

Share this post


Link to post
Share on other sites

Anyone??

 

I really need this to work for my store, otherwise, I cannot use OSC and I really want to. However, some of the products I have are food and have to be shipped UPS Next Day.

 

Please Help!

Share this post


Link to post
Share on other sites

Please Anyone!! Even a suggestion as to what to do alternatively would help? Perhaps running two different shops???

 

At this point, I would pay $$ to have someone create this contribution for me.

 

Thanks

Share this post


Link to post
Share on other sites

My line of approach would be to use UPS Choice (see the contributions) and where the code checks for which UPS methods are wanted and which should be excluded you can add your own stuff. I haven't looked at that, but I assume that it will be possible to see what articles are in the shopping cart and then you can make your own code determine which shipping options are allowed. Depending on the complexity of your site there are multiple ways to make a list of articles that have to force certain shipping: a simple text file, a check in which category the articles belong if they are all grouped, an extra database table, an extra column to your product_info database table. Probably, an extra database query will be involved also.

 

Nothing impossible, but highly dependent on your products...

Share this post


Link to post
Share on other sites

Thank you so very much for your response. However, I'm a novice when it comes to programing and I'm not exactly sure how to write the code I need for this project. Perhaps I could with some more of your guidence.

Share this post


Link to post
Share on other sites

txcrew,

 

I think this should get you going. I couldn't test this with UPS Choice itself since I use UPS XML, so it might not work right away. This code assumes you make a comma separated list of product id's (like: 55, 66, 77, 1004) in a file called list_prdcts_forced_ship.txt that you upload to the /includes/modules/shipping/ directory. Never mind about returns or spaces in that file, the code should take care of that.

Add an extra function to the ups.php from UPS Choice that should replace the standard one in the above mentioned directory. Put it at the bottom, after the last curly brace, but before the ?>

//*******************************
function remove_white_space(&$val, $key) {
$val = trim($val); 
$val = (int)$val;
? ? }

Find the code that starts with $methods = array(); around line 107 and modify it to:

 ? ? ? ?$methods = array();
?$allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
?$std_rcd = false;
// BOF extra code to force shipping if certain products are present in the cart
? ? $force_shipping_allowed_methods = array('1DM', '1DA', '1DP');
? ? $force_shipping = false;

? ? $file_with_prdct_nos = DIR_FS_CATALOG . DIR_WS_MODULES .'shipping/list_prdcts_forced_ship.txt';
? ? $fp = @fopen($file_with_prdct_nos, "r") or die("Cannot open file with list of products that need forced shipping");
? ? $filesize_fp = filesize($file_with_prdct_nos);
? ? $f_contents = fread($fp, $filesize_fp);
? ? @fclose($fp);
? ? $products_force_shipping = explode(",", $f_contents);
? ? array_walk($products_force_shipping, "remove_white_space"); // remove spaces and line endings to get "clean" product id's
? ? 
? ? $products_in_cart = $cart->get_products();
? ? $no_of_prdcts = sizeof($products_in_cart);

? ? for ($x=0; $x < $no_of_prdcts; $x++) {
? ? ?if ( in_array ($products_in_cart[$x]['id'], $products_force_shipping) ) {
? ? ? $force_shipping = true;
? ? ?}
? ? }
? ? // EOF force shipping
? ? ? ?$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;
?	};
?// BOF force shipping
?if ($force_shipping == true && !in_array( $type, $force_shipping_allowed_methods)) {
?	continue;
?}
?elseif (!in_array($type, $allowed_methods)) {
?	continue;
?}
?// EOF force shipping and regular code to exclude UPS Methods
? ? ? ? ?$methods[] = array('id' => $type,
? ? ? ? ? ? ? ? ? ? ? ? ? ? 'title' => $this->types[$type],
? ? ? ? ? ? ? ? ? ? ? ? ? ? 'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
? ? ? ?}

You probably want to exclude or include more choices for shipping. Adapt the "array('1DM', '1DA', '1DP');" for that purpose. 1DM for example stands for "Next Day Air Early AM", see the source code of ups.php around line 55 and further.

Edited by JanZ

Share this post


Link to post
Share on other sites
will this script still get live shipping fee's from the ups site
Oh yes, it is only excluding certain UPS shipping choices from showing to the customer (and thus cannot be chosen). If any product is in the shopping cart, with a product id listed in list_prdcts_forced_ship.txt, it will show the options set with array('1DM', '1DA', '1DP'), otherwise the shipping options set in the admin section. For UPS XML the code is very similar.

Share this post


Link to post
Share on other sites

Also, here is my ups.php file after adding the code:

<?php
/*
$Id: ups.php,v 1.54 2003/04/08 23:23:42 dgw_ Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

/*
revised by Fritz Clapp as UPS Choice 1.8 2003/08/02
 filters service types to those selected in admin and saved in 
 configuration table with key MODULE_SHIPPING_UPS_TYPES;
 suggests STD service as default for Canada;
 modified error message refers to failure to get quote;

*/

 class ups {
   var $code, $title, $descrption, $icon, $enabled, $types;

// class constructor
   function ups() {
     global $order;

     $this->code = 'ups';
     $this->title = MODULE_SHIPPING_UPS_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_UPS_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_UPS_SORT_ORDER;
     $this->icon = DIR_WS_ICONS . 'shipping_ups.gif';
  $this->tax_class = MODULE_SHIPPING_UPS_TAX_CLASS;
     $this->enabled = ((MODULE_SHIPPING_UPS_STATUS == 'True') ? true : false);

     if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_UPS_ZONE > 0) ) {
       $check_flag = false;
       $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_UPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
       while ($check = tep_db_fetch_array($check_query)) {
         if ($check['zone_id'] < 1) {
           $check_flag = true;
           break;
         } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
           $check_flag = true;
           break;
         }
       }

       if ($check_flag == false) {
         $this->enabled = false;
       }
     }

     $this->types = array('1DM' => 'Next Day Air Early AM',
                          '1DML' => 'Next Day Air Early AM Letter',
                          '1DA' => 'Next Day Air',
                          '1DAL' => 'Next Day Air Letter',
                          '1DAPI' => 'Next Day Air Intra (Puerto Rico)',
                          '1DP' => 'Next Day Air Saver',
                          '1DPL' => 'Next Day Air Saver Letter',
                          '2DM' => '2nd Day Air AM',
                          '2DML' => '2nd Day Air AM Letter',
                          '2DA' => '2nd Day Air',
                          '2DAL' => '2nd Day Air Letter',
                          '3DS' => '3 Day Select',
                          'GND' => 'Ground',
                          'GNDCOM' => 'Ground Commercial',
                          'GNDRES' => 'Ground Residential',
                          'STD' => 'Canada Standard',
                          'XPR' => 'Worldwide Express',
                          'XPRL' => 'worldwide Express Letter',
                          'XDM' => 'Worldwide Express Plus',
                          'XDML' => 'Worldwide Express Plus Letter',
                          'XPD' => 'Worldwide Expedited');
   }

// class methods
   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;
// BOF extra code to force shipping if certain products are present in the cart
   $force_shipping_allowed_methods = array('1DM', '1DA', '1DP');
   $force_shipping = false;

   $file_with_prdct_nos = DIR_FS_CATALOG . DIR_WS_MODULES .'shipping/list_prdcts_forced_ship.txt';
   $fp = @fopen($file_with_prdct_nos, "r") or die("Cannot open file with list of products that need forced shipping");
   $filesize_fp = filesize($file_with_prdct_nos);
   $f_contents = fread($fp, $filesize_fp);
   @fclose($fp);
   $products_force_shipping = explode(",", $f_contents);
   array_walk($products_force_shipping, "remove_white_space"); // remove spaces and line endings to get "clean" product id's
  
   $products_in_cart = $cart->get_products();
   $no_of_prdcts = sizeof($products_in_cart);

   for ($x=0; $x < $no_of_prdcts; $x++) {
    if ( in_array ($products_in_cart[$x]['id'], $products_force_shipping) ) {
     $force_shipping = true;
    }
   }
   // EOF force shipping
      $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;
 };
// BOF force shipping
if ($force_shipping == true && !in_array( $type, $force_shipping_allowed_methods)) {
 continue;
}
elseif (!in_array($type, $allowed_methods)) {
 continue;
}
// EOF force shipping and regular code to exclude UPS Methods
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
      }  $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;
   }

   function check() {
     if (!isset($this->_check)) {
       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_UPS_STATUS'");
       $this->_check = tep_db_num_rows($check_query);
     }
     return $this->_check;
   }

   function install() {
     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 ('Enable UPS Shipping', 'MODULE_SHIPPING_UPS_STATUS', 'True', 'Do you want to offer UPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Pickup Method', 'MODULE_SHIPPING_UPS_PICKUP', 'CC', 'How do you give packages to UPS? CC - Customer Counter, RDP - Daily Pickup, OTP - One Time Pickup, LC - Letter Center, OCA - On Call Air', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Packaging?', 'MODULE_SHIPPING_UPS_PACKAGE', 'CP', 'CP - Your Packaging, ULE - UPS Letter, UT - UPS Tube, UBE - UPS Express Box', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Residential Delivery?', 'MODULE_SHIPPING_UPS_RES', 'RES', 'Quote for Residential (RES) or Commercial Delivery (COM)', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_UPS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_UPS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_UPS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_SHIPPING_UPS_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
     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_UPS_TYPES', 'Nxt AM,Nxt AM Ltr,Nxt,Nxt Ltr,Nxt PR,Nxt Save,Nxt Save Ltr,2nd AM,2nd AM Ltr,2nd,2nd Ltr,3 Day Select,Ground,Canada,World Xp,World Xp Ltr, World Xp Plus,World Xp Plus Ltr,World Expedite', 'Select the USPS services to be offered.', '6', '13', 'tep_cfg_select_multioption(array(\'1DM\',\'1DML\', \'1DA\', \'1DAL\', \'1DAPI\', \'1DP\', \'1DPL\', \'2DM\', \'2DML\', \'2DA\', \'2DAL\', \'3DS\',\'GND\', \'STD\', \'XPR\', \'XPRL\', \'XDM\', \'XDML\', \'XPD\'), ', now() )");
   }

   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }

   function keys() {
     return array('MODULE_SHIPPING_UPS_STATUS', 'MODULE_SHIPPING_UPS_PICKUP', 'MODULE_SHIPPING_UPS_PACKAGE', 'MODULE_SHIPPING_UPS_RES', 'MODULE_SHIPPING_UPS_HANDLING', 'MODULE_SHIPPING_UPS_TAX_CLASS', 'MODULE_SHIPPING_UPS_ZONE', 'MODULE_SHIPPING_UPS_SORT_ORDER', 'MODULE_SHIPPING_UPS_TYPES');
   }

   function _upsProduct($prod){
     $this->_upsProductCode = $prod;
   }

   function _upsOrigin($postal, $country){
     $this->_upsOriginPostalCode = $postal;
     $this->_upsOriginCountryCode = $country;
   }

   function _upsDest($postal, $country){
     $postal = str_replace(' ', '', $postal);

     if ($country == 'US') {
       $this->_upsDestPostalCode = substr($postal, 0, 5);
     } else {
       $this->_upsDestPostalCode = $postal;
     }

     $this->_upsDestCountryCode = $country;
   }

   function _upsRate($foo) {
     switch ($foo) {
       case 'RDP':
         $this->_upsRateCode = 'Regular+Daily+Pickup';
         break;
       case 'OCA':
         $this->_upsRateCode = 'On+Call+Air';
         break;
       case 'OTP':
         $this->_upsRateCode = 'One+Time+Pickup';
         break;
       case 'LC':
         $this->_upsRateCode = 'Letter+Center';
         break;
       case 'CC':
         $this->_upsRateCode = 'Customer+Counter';
         break;
     }
   }

   function _upsContainer($foo) {
     switch ($foo) {
       case 'CP': // Customer Packaging
         $this->_upsContainerCode = '00';
         break;
       case 'ULE': // UPS Letter Envelope
         $this->_upsContainerCode = '01';
         break;
       case 'UT': // UPS Tube
         $this->_upsContainerCode = '03';
         break;
       case 'UEB': // UPS Express Box
         $this->_upsContainerCode = '21';
         break;
       case 'UW25': // UPS Worldwide 25 kilo
         $this->_upsContainerCode = '24';
         break;
       case 'UW10': // UPS Worldwide 10 kilo
         $this->_upsContainerCode = '25';
         break;
     }
   }

   function _upsWeight($foo) {
     $this->_upsPackageWeight = $foo;
   }

   function _upsRescom($foo) {
     switch ($foo) {
       case 'RES': // Residential Address
         $this->_upsResComCode = '1';
         break;
       case 'COM': // Commercial Address
         $this->_upsResComCode = '2';
         break;
     }
   }

   function _upsAction($action) {
     /* 3 - Single Quote
        4 - All Available Quotes */

     $this->_upsActionCode = $action;
   }

   function _upsGetQuote() {
     if (!isset($this->_upsActionCode)) $this->_upsActionCode = '4';

     $request = join('&', array('accept_UPS_license_agreement=yes',
                                '10_action=' . $this->_upsActionCode,
                                '13_product=' . $this->_upsProductCode,
                                '14_origCountry=' . $this->_upsOriginCountryCode,
                                '15_origPostal=' . $this->_upsOriginPostalCode,
                                '19_destPostal=' . $this->_upsDestPostalCode,
                                '22_destCountry=' . $this->_upsDestCountryCode,
                                '23_weight=' . $this->_upsPackageWeight,
                                '47_rate_chart=' . $this->_upsRateCode,
                                '48_container=' . $this->_upsContainerCode,
                                '49_residential=' . $this->_upsResComCode));
     $http = new httpClient();
     if ($http->Connect('www.ups.com', 80)) {
       $http->addHeader('Host', 'www.ups.com');
       $http->addHeader('User-Agent', 'osCommerce');
       $http->addHeader('Connection', 'Close');

       if ($http->Get('/using/services/rave/qcostcgi.cgi?' . $request)) $body = $http->getBody();

       $http->Disconnect();
     } else {
       return 'error';
     }
/*
   mail('you@yourdomain.com','UPS response',$body,'From: <you@yourdomain.com>');
*/
     $body_array = explode("\n", $body);

     $returnval = array();
     $errorret = 'error'; // only return error if NO rates returned

     $n = sizeof($body_array);
     for ($i=0; $i<$n; $i++) {
       $result = explode('%', $body_array[$i]);
       $errcode = substr($result[0], -1);
       switch ($errcode) {
         case 3:
           if (is_array($returnval)) $returnval[] = array($result[1] => $result[8]);
           break;
         case 4:
           if (is_array($returnval)) $returnval[] = array($result[1] => $result[8]);
           break;
         case 5:
           $errorret = $result[1];
           break;
         case 6:
           if (is_array($returnval)) $returnval[] = array($result[3] => $result[10]);
           break;
       }
     }
     if (empty($returnval)) $returnval = $errorret;

     return $returnval;
   }
 }
 //*******************************
function remove_white_space(&$val, $key) {
$val = trim($val);
$val = (int)$val;
   }
?>

Share this post


Link to post
Share on other sites

and now I get this error when I try to checkout:

 

Fatal error: Call to a member function on a non-object in /storage/txcrew/public_html/store/includes/modules/shipping/ups.php on line 122

Share this post


Link to post
Share on other sites
Fatal error: Call to a member function on a non-object
Not good, especially not in a live shop. You should try these things on a test server...

Can you try changing the last line of:

? ?array_walk($products_force_shipping, "remove_white_space"); // remove spaces and line endings to get "clean" product id's
? 
? ?$products_in_cart = $cart->get_products();

to:

$products_in_cart = $order->products;

Share this post


Link to post
Share on other sites
Not good, especially not in a live shop. You should try these things on a test server...

 

This is a test shop. ;)

 

Can you try changing the last line of:
   array_walk($products_force_shipping, "remove_white_space"); // remove spaces and line endings to get "clean" product id's
 
  $products_in_cart = $cart->get_products();

to:

$products_in_cart = $order->products;

 

Changed it, now the page loads up but with these errors:

 

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /storage/txcrew/public_html/store/includes/classes/http_client.php on line 330

Warning: fsockopen(): unable to connect to www.ups.com:80 in /storage/txcrew/public_html/store/includes/classes/http_client.php on line 330

Share this post


Link to post
Share on other sites

txcrew,

 

maybe you can look at one of the flat rate shipping options and set a flat rate cost for shipping on all the products on the food category.

Share this post


Link to post
Share on other sites

txcrew,

This is a test shop.
You mentioned that, sorry, overlooked that. Good to hear though ;)
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /storage/txcrew/public_html/store/includes/classes/http_client.php on line 330
That is weird (on first glance). It seems unrelated because that is "subcode" used by the function _upsQuote and that function is called on line 101... [$upsQuote = $this->_upsGetQuote(); ] several lines above where the mod is.

I have no suggestions yet, other than backup this file and trying the original file to confirm that that is working.

 

Regarding your question:

Do all of the product ID's go into the list_prdcts_forced_ship.txt?
Only those of the food items that if present in the card should ship quickly and therefore restrict the shipping options to the fast ones.

Share this post


Link to post
Share on other sites
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /storage/txcrew/public_html/store/includes/classes/http_client.php on line 330
According to http://bugs.php.net/bug.php?id=11058 it is a bug that can be circumvented by adding the remote server to a file on your server (the bug has apparently something to do with name servers and resolving url's to IP addresses).

 

However, I saw sneeking into the admin area of your test shop (better change the user name and password soon, before someone gets at other passwords...) that the shop runs on Linux and has cURL and OpenSSL installed. Getting UPS XML working ( http://www.oscommerce.com/community/contributions,1323 ) shouldn't be a problem. You already have done the necessary changes to general.php glancing over the instructions for UPS Choice so all that need to be done is changing a database field in one of the tables (see the instructions), adding the necessary files and installing it in the admin area.

 

The code for UPS XML is pretty similar (the array with the allowed methods is built differently, just add more lines in the same fashion if you need more choices for the food products), also add the function remove_white_space at the bottom:

            $methods = array();
    
    $force_shipping_allowed_methods[] = MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_01;
    $force_shipping_allowed_methods[] = MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_02;
    $force_shipping = false;
    $products_in_cart = $order->products;
    $no_of_prdcts = sizeof($products_in_cart);
    $file_with_prdct_nos = DIR_FS_CATALOG . DIR_WS_MODULES .'shipping/list_prdcts_forced_ship.txt';
    $fp = fopen($file_with_prdct_nos, "r") or die("Cannot open file with list of products that need forced shipping");
    $filesize_fp = filesize($file_with_prdct_nos);
    $f_contents = fread($fp, $filesize_fp);
    @fclose($fp);
    $products_force_shipping = explode(",", $f_contents);
    array_walk($products_force_shipping, "remove_white_space"); // remove spaces and line endings to get "clean" product id's
    for ($x=0; $x < $no_of_prdcts; $x++) {
     if ( in_array ($products_in_cart[$x]['id'], $products_force_shipping) ) {
      $force_shipping = true;
     }
    }
           for ($i=0; $i < sizeof($upsQuote); $i++) {
               list($type, $cost) = each($upsQuote[$i]);
               // BOF limit choices
 if ($force_shipping == true && !in_array( $type, $force_shipping_allowed_methods)) {
	 continue;
 }
               elseif (!exclude_choices($type)) continue;
               // EOF limit choices
               if ( $method == '' || $method == $type ) {
   $_type = $type;
  	 if (isset($this->servicesTimeintransit[$type])) {
  	 $_type = $_type . ", ".$this->servicesTimeintransit[$type]["date"];
   }

Share this post


Link to post
Share on other sites

I just installed upsxml and now I get this error when I try to edit it in the admin:

 

Parse error: parse error, unexpected ';' in /home/heckys/public_html/outlet/admin/modules.php(216) : eval()'d code on line 1

 

 

I skipped the step that had to do with editing moduels.php because I already have ups choice installed. What should I do?

Share this post


Link to post
Share on other sites

and after making the changes in upsxml.php I now get this error in the admin:

 

Parse error: parse error, unexpected $ in /home/heckys/public_html/outlet/includes/modules/shipping/upsxml.php on line 948

Share this post


Link to post
Share on other sites

Here is my full upsxml.php code

 

<?php

/*

   $Id: upsxml.php,v 1.1.4 2004/12/19 13:30:00 sgo Exp $

   

   Original copyright (c) 2003 Torin Walker

   This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License

   as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied

   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

   See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along with this program;

   If not, you may obtain one by writing to and requesting one from:

   The Free Software Foundation, Inc.,

   59 Temple Place, Suite 330,

   Boston, MA 02111-1307 USA

   

   Written by Torin Walker.

   Some code/style borrowed from both Fritz Clapp's UPS Choice 1.7 Module,

   and Kelvin, Kenneth, and Tom St.Croix's Canada Post 3.1 Module.

*/

 

require ('includes/classes/xmldocument.php');

// if using the optional dimensional support, set to 1, otherwise leave as 0

define('DIMENSIONS_SUPPORTED', 0);

 

class upsxml {

   var $code, $title, $description, $icon, $enabled, $types, $boxcount;

 

   //***************

   function upsxml() {

       global $order;

       $this->code = 'upsxml';

       $this->title = MODULE_SHIPPING_UPSXML_RATES_TEXT_TITLE;

       $this->description = MODULE_SHIPPING_UPSXML_RATES_TEXT_DESCRIPTION;

       $this->sort_order = MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER;

       $this->icon = DIR_WS_ICONS . 'shipping_ups.gif';

       $this->tax_class = MODULE_SHIPPING_UPSXML_RATES_TAX_CLASS;

       $this->enabled = ((MODULE_SHIPPING_UPSXML_RATES_STATUS == 'True') ? true : false);

       $this->access_key = MODULE_SHIPPING_UPSXML_RATES_ACCESS_KEY;

       $this->access_username = MODULE_SHIPPING_UPSXML_RATES_USERNAME;

       $this->access_password = MODULE_SHIPPING_UPSXML_RATES_PASSWORD;

       $this->origin = MODULE_SHIPPING_UPSXML_RATES_ORIGIN;

       $this->origin_city = MODULE_SHIPPING_UPSXML_RATES_CITY;

       $this->origin_stateprov = MODULE_SHIPPING_UPSXML_RATES_STATEPROV;

       $this->origin_country = MODULE_SHIPPING_UPSXML_RATES_COUNTRY;

       $this->origin_postalcode = MODULE_SHIPPING_UPSXML_RATES_POSTALCODE;

       $this->pickup_method = MODULE_SHIPPING_UPSXML_RATES_PICKUP_METHOD;

       $this->package_type = MODULE_SHIPPING_UPSXML_RATES_PACKAGE_TYPE;

       $this->unit_weight = MODULE_SHIPPING_UPSXML_RATES_UNIT_WEIGHT;

       $this->unit_length = MODULE_SHIPPING_UPSXML_RATES_UNIT_LENGTH;

       $this->handling_fee = MODULE_SHIPPING_UPSXML_RATES_HANDLING;

       $this->quote_type = MODULE_SHIPPING_UPSXML_RATES_QUOTE_TYPE;

       $this->customer_classification = MODULE_SHIPPING_UPSXML_RATES_CUSTOMER_CLASSIFICATION_CODE;

       $this->protocol = 'https';

       $this->host = ((MODULE_SHIPPING_UPSXML_RATES_TEST_MODE == 'Test') ? 'wwwcie.ups.com' : 'wwwcie.ups.com');

       $this->port = '443';

       $this->path = '/ups.app/xml/Rate';

       $this->transitpath = '/ups.app/xml/TimeInTransit';

       $this->version = 'UPSXML Rate 1.0001';

       $this->transitversion = 'UPSXML Time In Transit 1.0001';

       $this->timeout = '60';

       $this->xpci_version = '1.0001';

       $this->transitxpci_version = '1.0001';

       $this->items_qty = 0;

       $this->timeintransit = '0';

       $this->today = date("Ymd");

   

// to enable logging, create an empty "upsxml.log" file at the location you set below, give it write permissions (777) and uncomment the next line

//      $this->logfile = '/tmp/upsxml.log';

 

// when cURL is not compiled into PHP (Windows users, some Linux users)

// you can set the next variable to "1" and then exec(curl -d $xmlRequest, $xmlResponse)

// will be used

       $this->use_exec = '0';

 

       if (($this->enabled == true) && ((int)MODULE_SHIPPING_UPSXML_RATES_ZONE > 0)) {

           $check_flag = false;

           $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_UPSXML_RATES_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");

           while ($check = tep_db_fetch_array($check_query)) {

               if ($check['zone_id'] < 1) {

                   $check_flag = true;

                   break;

               } elseif ($check['zone_id'] == $order->delivery['zone_id']) {

                   $check_flag = true;

                   break;

               }

           }

           if ($check_flag == false) {

               $this->enabled = false;

           }

       }

 

       // Available pickup types - set in admin

       $this->pickup_methods = array(

           'Daily Pickup' => '01',

           'Customer Counter' => '03',

           'One Time Pickup' => '06',

           'On Call Air Pickup' => '07',

           'Letter Center' => '09',

           'Air Service Center' => '10'

       );

 

       // Available package types

       $this->package_types = array(

           'Unknown' => '00',

           'UPS Letter' => '01',

           'Customer Package' => '02',

           'UPS Tube' => '03',

           'UPS Pak' => '04',

           'UPS Express Box' => '21',

           'UPS 25kg Box' => '24',

           'UPS 10kg Box' => '25'

       );

 

       // Human-readable Service Code lookup table. The values returned by the Rates and Service "shop" method are numeric.

       // Using these codes, and the admininstratively defined Origin, the proper human-readable service name is returned.

       // Note: The origin specified in the admin configuration affects only the product name as displayed to the user.

       $this->service_codes = array(

           // US Origin

           'US Origin' => array(

               '01' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_01,

               '02' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_02,

               '03' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_03,

               '07' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_07,

               '08' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_08,

               '11' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_11,

               '12' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_12,

               '13' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_13,

               '14' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_14,

               '54' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_54,

               '59' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_59,

               '65' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_65

           ),

           // Canada Origin

           'Canada Origin' => array(

               '01' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_01,

               '07' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_07,

               '08' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_08,

               '11' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_11,

               '12' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_12,

               '13' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_13,

               '14' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_14,

               '54' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_CANADA_ORIGIN_54

           ),

           // European Union Origin

           'European Union Origin' => array(

               '07' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_EU_ORIGIN_07,

               '08' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_EU_ORIGIN_08,

               '11' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_EU_ORIGIN_11,

               '54' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_EU_ORIGIN_54,

               '64' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_EU_ORIGIN_64,

               '65' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_EU_ORIGIN_65

           ),

           // Puerto Rico Origin

           'Puerto Rico Origin' => array(

               '01' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_01,

               '02' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_02,

               '03' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_03,

               '07' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_07,

               '08' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_08,

               '14' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_14,

               '54' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_PR_ORIGIN_54

           ),

           // Mexico Origin

           'Mexico Origin' => array(

               '07' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_MEXICO_ORIGIN_07,

               '08' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_MEXICO_ORIGIN_08,

               '54' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_MEXICO_ORIGIN_54

           ),

           // All other origins

           'All other origins' => array(

               '07' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_OTHER_ORIGIN_07,

               '08' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_OTHER_ORIGIN_08,

               '54' => MODULE_SHIPPING_UPSXML_SERVICE_CODE_OTHER_ORIGIN_54

           )

       );

   }

 

   // class methods

   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) {

           // sort $productsArray according to ready-to-ship (first) and not-ready-to-ship (last)

           usort($productsArray, ready_to_shipCmp);

           // 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)

  $this->items_qty = 0; //reset quantities

           for ($i = 0; $i < $shipping_num_boxes; $i++) {

               $this->_addItem (0, 0, 0, $shipping_weight);

           }

       }

 

// BOF Time In Transit: comment out this section if you don't want/need to have

// expected delivery dates

 

       $this->servicesTimeintransit = $this->_upsGetTimeServices();  

       if ($this->logfile) {

           error_log("------------------------------------------\n", 3, $this->logfile);

           error_log("Time in Transit: " . $this->timeintransit . "\n", 3, $this->logfile);

       }

 

// EOF Time In Transit

 

       $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();

 

   $force_shipping_allowed_methods[] = MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_01;

   $force_shipping_allowed_methods[] = MODULE_SHIPPING_UPSXML_SERVICE_CODE_US_ORIGIN_02;

   $force_shipping = false;

   $products_in_cart = $order->products;

   $no_of_prdcts = sizeof($products_in_cart);

   $file_with_prdct_nos = DIR_FS_CATALOG . DIR_WS_MODULES .'shipping/list_prdcts_forced_ship.txt';

   $fp = fopen($file_with_prdct_nos, "r") or die("Cannot open file with list of products that need forced shipping");

   $filesize_fp = filesize($file_with_prdct_nos);

   $f_contents = fread($fp, $filesize_fp);

   @fclose($fp);

   $products_force_shipping = explode(",", $f_contents);

   array_walk($products_force_shipping, "remove_white_space"); // remove spaces and line endings to get "clean" product id's

   for ($x=0; $x < $no_of_prdcts; $x++) {

    if ( in_array ($products_in_cart[$x]['id'], $products_force_shipping) ) {

     $force_shipping = true;

    }

   }

          for ($i=0; $i < sizeof($upsQuote); $i++) {

              list($type, $cost) = each($upsQuote[$i]);

              // BOF limit choices

if ($force_shipping == true && !in_array( $type, $force_shipping_allowed_methods)) {

 continue;

}

              elseif (!exclude_choices($type)) continue;

              // EOF limit choices

              if ( $method == '' || $method == $type ) {

  $_type = $type;

   if (isset($this->servicesTimeintransit[$type])) {

   $_type = $_type . ", ".$this->servicesTimeintransit[$type]["date"];

  }            for ($i=0; $i < sizeof($upsQuote); $i++) {

               list($type, $cost) = each($upsQuote[$i]);

               // BOF limit choices

               if (!exclude_choices($type)) continue;

               // EOF limit choices

               if ( $method == '' || $method == $type ) {

   $_type = $type;

    if (isset($this->servicesTimeintransit[$type])) {

    $_type = $_type . ", ".$this->servicesTimeintransit[$type]["date"];

   }

 

 // instead of just adding the expected delivery date as ", yyyy-mm-dd"

 // you might like to change this to your own liking for example by commenting the

 // three lines above this and uncommenting/changing the next:

 // START doing things differently

 /*

 

    if (isset($this->servicesTimeintransit[$type])) {

    $eta_array = explode("-", $this->servicesTimeintransit[$type]["date"]);

    $months = array (" ", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

    $eta_arrival_date = $months[(int)$eta_array[1]]." ".$eta_array[2].", ".$eta_array[0];

   $_type .= ", <acronym title='Estimated Delivery Date'>EDD</acronym>: ".$eta_arrival_date;

   }

 END of doing things differently:  */

   

                   $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;

   }

 

   //**************

   function check() {

       if (!isset($this->_check)) {

           $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_UPSXML_RATES_STATUS'");

           $this->_check = tep_db_num_rows($check_query);

       }

       return $this->_check;

   }

 

   //**************

   function install() {

       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 ('Enable UPS Shipping', 'MODULE_SHIPPING_UPSXML_RATES_STATUS', 'True', 'Do you want to offer UPS shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Rates Access Key', 'MODULE_SHIPPING_UPSXML_RATES_ACCESS_KEY', '', 'Enter the XML rates access key assigned to you by UPS.', '6', '1', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Rates Username', 'MODULE_SHIPPING_UPSXML_RATES_USERNAME', '', 'Enter your UPS Services account username.', '6', '2', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('UPS Rates Password', 'MODULE_SHIPPING_UPSXML_RATES_PASSWORD', '', 'Enter your UPS Services account password.', '6', '3', now())");

       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 ('Pickup Method', 'MODULE_SHIPPING_UPSXML_RATES_PICKUP_METHOD', 'Daily Pickup', 'How do you give packages to UPS?', '6', '4', 'tep_cfg_select_option(array(\'Daily Pickup\', \'Customer Counter\', \'One Time Pickup\', \'On Call Air Pickup\', \'Letter Center\', \'Air Service Center\'), ', now())");

       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 ('Packaging Type', 'MODULE_SHIPPING_UPSXML_RATES_PACKAGE_TYPE', 'Customer Package', 'What kind of packaging do you use?', '6', '5', 'tep_cfg_select_option(array(\'Customer Package\', \'UPS Letter\', \'UPS Tube\', \'UPS Pak\', \'UPS Express Box\', \'UPS 25kg Box\', \'UPS 10kg box\'), ', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Customer Classification Code', 'MODULE_SHIPPING_UPSXML_RATES_CUSTOMER_CLASSIFICATION_CODE', '01', '01 - If you are billing to a UPS account and have a daily UPS pickup, 03 - If you do not have a UPS account or you are billing to a UPS account but do not have a daily pickup, 04 - If you are shipping from a retail outlet', '6', '6', now())");

       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 Origin', 'MODULE_SHIPPING_UPSXML_RATES_ORIGIN', 'US Origin', 'What origin point should be used (this setting affects only what UPS product names are shown to the user)', '6', '7', 'tep_cfg_select_option(array(\'US Origin\', \'Canada Origin\', \'European Union Origin\', \'Puerto Rico Origin\', \'Mexico Origin\', \'All other origins\'), ', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin City', 'MODULE_SHIPPING_UPSXML_RATES_CITY', '', 'Enter the name of the origin city.', '6', '8', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin State/Province', 'MODULE_SHIPPING_UPSXML_RATES_STATEPROV', '', 'Enter the two-letter code for your origin state/province.', '6', '9', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin Country', 'MODULE_SHIPPING_UPSXML_RATES_COUNTRY', '', 'Enter the two-letter code for your origin country.', '6', '10', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin Zip/Postal Code', 'MODULE_SHIPPING_UPSXML_RATES_POSTALCODE', '', 'Enter your origin zip/postalcode.', '6', '11', now())");

       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 ('Test or Production Mode', 'MODULE_SHIPPING_UPSXML_RATES_MODE', 'Test', 'Use this module in Test or Production mode?', '6', '12', 'tep_cfg_select_option(array(\'Test\', \'Production\'), ', now())");

       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 ('Unit Weight', 'MODULE_SHIPPING_UPSXML_RATES_UNIT_WEIGHT', 'LBS', 'By what unit are your packages weighed?', '6', '13', 'tep_cfg_select_option(array(\'LBS\', \'KGS\'), ', now())");

       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 ('Unit Length', 'MODULE_SHIPPING_UPSXML_RATES_UNIT_LENGTH', 'IN', 'By what unit are your packages sized?', '6', '14', 'tep_cfg_select_option(array(\'IN\', \'CM\'), ', now())");

       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 ('Quote Type', 'MODULE_SHIPPING_UPSXML_RATES_QUOTE_TYPE', 'Commercial', 'Quote for Residential or Commercial Delivery', '6', '15', 'tep_cfg_select_option(array(\'Commercial\', \'Residential\'), ', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_UPSXML_RATES_HANDLING', '0', 'Handling fee for this shipping method.', '6', '16', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_UPSXML_RATES_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '17', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_UPSXML_RATES_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '18', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

       tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '19', now())");

       // add key for allowed shipping methods

       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 Air, 2nd Day Air, Ground, Worldwide Express, Standard, 3 Day Select', 'Select the UPS services to be offered.', '6', '20', 'tep_cfg_select_multioption(array(\'Next Day Air\', \'2nd Day Air\', \'Ground\', \'Worldwide Express\', \'Worldwide Expedited\', \'Standard\', \'3 Day Select\', \'Next Day Air Saver\', \'Next Day Air Early A.M.\', \'Worldwide Express Plus\', \'2nd Day Air A.M.\', \'Express NA1\', \'Express Saver\'), ',  now())");

// add key for shipping delay

tep_db_query("insert into " . TABLE_CONFIGURATION . " ( configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) values ('', 'Shipping Delay', 'SHIPPING_DAYS_DELAY', '1', 'How many days from when an order is placed to when you ship it (Decimals are allowed). Arrival date estimations are based on this value.', '7', '6', NULL, now(), NULL, NULL)");

   }

 

   //****************

   function remove() {

       tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

   }

 

   //*************

   function keys() {

       // add MODULE_SHIPPING_UPSXML_TYPES to end of array for selectable shipping methods

       return array('MODULE_SHIPPING_UPSXML_RATES_STATUS', 'MODULE_SHIPPING_UPSXML_RATES_ACCESS_KEY', 'MODULE_SHIPPING_UPSXML_RATES_USERNAME', 'MODULE_SHIPPING_UPSXML_RATES_PASSWORD', 'MODULE_SHIPPING_UPSXML_RATES_PICKUP_METHOD', 'MODULE_SHIPPING_UPSXML_RATES_PACKAGE_TYPE', 'MODULE_SHIPPING_UPSXML_RATES_CUSTOMER_CLASSIFICATION_CODE', 'MODULE_SHIPPING_UPSXML_RATES_ORIGIN', 'MODULE_SHIPPING_UPSXML_RATES_CITY', 'MODULE_SHIPPING_UPSXML_RATES_STATEPROV', 'MODULE_SHIPPING_UPSXML_RATES_COUNTRY', 'MODULE_SHIPPING_UPSXML_RATES_POSTALCODE', 'MODULE_SHIPPING_UPSXML_RATES_MODE', 'MODULE_SHIPPING_UPSXML_RATES_UNIT_WEIGHT', 'MODULE_SHIPPING_UPSXML_RATES_UNIT_LENGTH', 'MODULE_SHIPPING_UPSXML_RATES_QUOTE_TYPE', 'MODULE_SHIPPING_UPSXML_RATES_HANDLING', 'MODULE_SHIPPING_UPSXML_RATES_TAX_CLASS', 'MODULE_SHIPPING_UPSXML_RATES_ZONE', 'MODULE_SHIPPING_UPSXML_RATES_SORT_ORDER', 'MODULE_SHIPPING_UPSXML_TYPES', 'SHIPPING_DAYS_DELAY');

   }

 

   //***********************

   function _upsProduct($prod){

       $this->_upsProductCode = $prod;

   }

 

   //**********************************************

   function _upsOrigin($city, $stateprov, $country, $postal){

       $this->_upsOriginCity = $city;

       $this->_upsOriginStateProv = $stateprov;

       $this->_upsOriginCountryCode = $country;

       $postal = str_replace(' ', '', $postal);

       if ($country == 'US') {

           $this->_upsOriginPostalCode = substr($postal, 0, 5);

       } else {

           $this->_upsOriginPostalCode = $postal;

       }

   }

 

   //**********************************************

   function _upsDest($city, $stateprov, $country, $postal) {

       $this->_upsDestCity = $city;

       $this->_upsDestStateProv = $stateprov;

       $this->_upsDestCountryCode = $country;

       $postal = str_replace(' ', '', $postal);

       if ($country == 'US') {

           $this->_upsDestPostalCode = substr($postal, 0, 5);

       } else {

           $this->_upsDestPostalCode = $postal;

       }

   }

 

   //************************

   function _upsAction($action) {

       // rate - Single Quote; shop - All Available Quotes

       $this->_upsActionCode = $action;

   }

 

   //********************************************

   function _addItem($length, $width, $height, $weight) {

       // Add box or item to shipment list. Round weights to 1 decimal places.

       if ((float)$weight < 1.0) {

           $weight = 1;

       } else {

           $weight = round($weight, 1);

       }

       $index = $this->items_qty;

       $this->item_length[$index] = ($length ? (string)$length : '0' );

       $this->item_width[$index] = ($width ? (string)$width : '0' );

       $this->item_height[$index] = ($height ? (string)$height : '0' );

       $this->item_weight[$index] = ($weight ? (string)$weight : '0' );

       $this->items_qty++;

   }

 

   //********************

   function getPackages() {

       $packages = array();

       $packages_query = tep_db_query("select * from " . TABLE_PACKAGING . " order by package_cost;");

       while ($package = tep_db_fetch_array($packages_query)) {

           $packages[] = array(

           'id' => $package['package_id'],

           'name' => $package['package_name'],

           'description' => $package['package_description'],

           'length' => $package['package_length'],

           'width' => $package['package_width'],

           'height' => $package['package_height'],

           'empty_weight' => $package['package_empty_weight'],

           'max_weight' => $package['package_max_weight'],

           'cost' => $package['package_cost']);

       }

       return $packages;

   }

 

   //********************************

   function packProducts($productsArray) {

       // A very simple box packing algorithm. Given a list of packages, returns an array of boxes.

       // This algorithm is trivial. It works on the premise that you have selected boxes that fit your products, and that their volumes are resonable multiples

       // of the products they store. For example, if you sell CDs and these CDs are 5x5x0.5", your boxes should be 5x5x0.5 (1 CD mailer), 5x5x2.5 (5 CD mailer)

       // and 5x5x5 (10 CD mailer). No matter how many CDs a customer buys, this routine will always find the optimal packing.

       // Your milage may differ, depending on what variety of products you sell, and how they're boxed. I just made up this algorithm in a hurry to fill a small

       // niche. You are encouraged to find better algorithms. Better algorithms mean better packaging, resulting in higher quoting accuracy and less loss due to

       // inaccurate quoting. The algorithm proceeds as follows:

       // Get the first, smallest box, and try to put everything into it. If not all of it fits, try fitting it all into the next largest box. Keep increasing

       // the size of the box until no larger box can be obtained, then spill over into a second, smallest box. Once again, increase the box size until

       // everything fits, or spill over again. Repeat until everything is boxed. The cost of a box determines the order in which it is tried. There will definitely

       // be cases where it is cheaper to send two small packages rather than one larger one. In that case, you'll need a better algorithm.

       // Get the available packages and "prepare" empty boxes with weight and remaining volume counters. (Take existing box and add 'remaining_volume' and 'current_weight';

       $definedPackages = $this->getPackages();

       $emptyBoxesArray = array();

       for ($i = 0; $i < count($definedPackages); $i++) {

           $definedBox = $definedPackages[$i];

           $definedBox['remaining_volume'] = $definedBox['length'] * $definedBox['width'] * $definedBox['height'];

           $definedBox['current_weight'] = $definedBox['empty_weight'];

           $emptyBoxesArray[] = $definedBox;

       }

       $packedBoxesArray = array();

       $currentBox = NULL;

       // Get the product array and expand multiple qty items.

       $productsRemaining = array();

       for ($i = 0; $i < count($productsArray); $i++) {

           $product = $productsArray[$i];

           for ($j = 0; $j < $productsArray[$i]['quantity']; $j++) {

               $productsRemaining[] = $product;

           }

       }

       // Worst case, you'll need as many boxes as products ordered.

       while (count($productsRemaining)) {

           // Immediately set aside products that are already packed and ready.

           if ($productsRemaining[0]['ready_to_ship'] == '1') {

               $packedBoxesArray[] = array (

               'length' => $productsRemaining[0]['length'],

               'width' => $productsRemaining[0]['width'],

               'height' => $productsRemaining[0]['height'],

               'current_weight' => $productsRemaining[0]['weight']);

               $productsRemaining = array_slice($productsRemaining, 1);

               continue;

           }

           //Cylcle through boxes, increasing box size if all doesn't fit.

           if (count($emptyBoxesArray) == 0) {

               print_r("ERROR: No boxes to ship unpackaged product<br>");

               break;

           }

           for ($b = 0; $b < count($emptyBoxesArray); $b++) {

               $currentBox = $emptyBoxesArray[$b];

               //Try to fit each product in box

               for ($p = 0; $p < count($productsRemaining); $p++) {

                   if ($this->fitsInBox($productsRemaining[$p], $currentBox)) {

                       //It fits. Put it in the box.

                       $currentBox = $this->putProductInBox($productsRemaining[$p], $currentBox);

                       if ($p == count($productsRemaining) - 1) {

                           $packedBoxesArray[] = $currentBox;

                           $productsRemaining = array_slice($productsRemaining, $p + 1);

                           break 2;

                       }

                   } else {

                       if ($b == count($emptyBoxesArray) - 1) {

                           //We're at the largest box already, and it's full. Keep what we've packed so far and get another box.

                           $packedBoxesArray[] = $currentBox;

                           $productsRemaining = array_slice($productsRemaining, $p + 1);

                           break 2;

                       }

                       // Not all of them fit. Stop packing remaining products and try next box.

                       break;

                   }

               }

           }

       }

   

       return $packedBoxesArray;

   }

 

   //*****************************

   function fitsInBox($product, $box) {

       $productVolume = $product['length'] * $product['width'] * $product['height'];

       if ($productVolume <= $box['remaining_volume']) {

           if ($box['max_weight'] == 0 || ($box['current_weight'] + $product['weight'] <= $box['max_weight'])) {

               return true;

           }

       }

       return false;

   }

 

   //***********************************

   function putProductInBox($product, $box) {

       $productVolume = $product['length'] * $product['width'] * $product['height'];

       $box['remaining_volume'] -= $productVolume;

       $box['products'][] = $product;

       $box['current_weight'] += $product['weight'];

       return $box;

   }

 

   //*********************

   function _upsGetQuote() {

 

       // Create the access request

       $accessRequestHeader =

       "<?xml version=\"1.0\"?>\n".

       "<AccessRequest xml:lang=\"en-US\">\n".

       "   <AccessLicenseNumber>". $this->access_key ."</AccessLicenseNumber>\n".

       "   <UserId>". $this->access_username ."</UserId>\n".

       "   <Password>". $this->access_password ."</Password>\n".

       "</AccessRequest>\n";

 

       $ratingServiceSelectionRequestHeader =

       "<?xml version=\"1.0\"?>\n".

       "<RatingServiceSelectionRequest xml:lang=\"en-US\">\n".

       "   <Request>\n".

       "       <TransactionReference>\n".

       "           <CustomerContext>Rating and Service</CustomerContext>\n".

       "           <XpciVersion>". $this->xpci_version ."</XpciVersion>\n".

       "       </TransactionReference>\n".

       "       <RequestAction>Rate</RequestAction>\n".

       "       <RequestOption>shop</RequestOption>\n".

       "   </Request>\n".

       "   <PickupType>\n".

       "       <Code>". $this->pickup_methods[$this->pickup_method] ."</Code>\n".

       "   </PickupType>\n".

       "   <Shipment>\n".

       "       <Shipper>\n".

       "           <Address>\n".

       "               <City>". $this->_upsOriginCity ."</City>\n".

       "               <StateProvinceCode>". $this->_upsOriginStateProv ."</StateProvinceCode>\n".

       "               <CountryCode>". $this->_upsOriginCountryCode ."</CountryCode>\n".

       "               <PostalCode>". $this->_upsOriginPostalCode ."</PostalCode>\n".

       "           </Address>\n".

       "       </Shipper>\n".

       "       <ShipTo>\n".

&

Share this post


Link to post
Share on other sites
Parse error: parse error, unexpected ';' in /home/heckys/public_html/outlet/admin/modules.php(216) : eval()'d code on line 1
You didn't change the column in one of the database tables from varchar(255) to text, or you did it after you installed UPS XML. What happens is that only part of the parameters is now in the database, therefore the error.

 

Your second error I can't explain. The inserted code looks fine to me. Did you add the function remove_white_space to the bottom? :

//******************************
function ready_to_shipCmp( $a, $b) {
   if ( $a['ready_to_ship'] == $b['ready_to_ship'] )
   return 0;
   if ( $a['ready_to_ship'] > $b['ready_to_ship'] )
   return -1;
   return 1;
}
//*******************************
function remove_white_space(&$val, $key) {
$val = trim($val); 
$val = (int)$val;
    }
?>

Apparently, not the whole file could fit into the post.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×