=== modified file 'shipping/uc_ups/uc_ups.module'
--- shipping/uc_ups/uc_ups.module	2009-02-03 21:33:23 +0000
+++ shipping/uc_ups/uc_ups.module	2009-02-03 22:19:56 +0000
@@ -812,40 +812,67 @@
   $method = uc_ups_shipping_method();
 
   $addresses = array((array)variable_get('uc_quote_store_default_address', new stdClass()));
+  $key = 0;
   $last_key = 0;
   $packages = array();
   if (variable_get('uc_ups_all_in_one', true) && count($products) > 1) {
     foreach ($products as $product) {
       if ($product->nid) {
+        // Packages are grouped by the address from which they will be
+        // shipped. We will keep track of the different addresses in an array
+        // and use their keys for the array of packages.
+
         $address = (array)uc_quote_get_default_shipping_address($product->nid);
         $key = array_search($address, $addresses);
         if ($key === false) {
+          // This is a new address. Increment the address counter $last_key
+          // instead of using [] so that it can be used in $packages and
+          // $addresses.
           $addresses[++$last_key] = $address;
           $key = $last_key;
-          $packages[$key][0] = new stdClass();
         }
       }
-      $packages[$key][0]->weight += $product->weight * $product->qty * uc_weight_conversion($product->weight_units, 'lb');
+
+      // Add this product to the last package from the found address or start
+      // a new package.
+      if (isset($packages[$key]) && count($packages[$key])) {
+        $package = array_pop($packages[$key]);
+      }
+      else {
+        $package = _uc_ups_new_package();
+      }
+
+      $weight = $product->weight * $product->qty * uc_weight_conversion($product->weight_units, 'lb');
+
+      // UPS has a weight limit on packages of 150 lbs. If this product puts
+      // it over the limit, start a new package.
+      if ($package->weight + $weight > 150) {
+        $packages[$key][] = $package;
+        $package = _uc_ups_new_package();
+      }
+
+      $package->weight += $weight;
+      $package->price += $product->price * $product->qty;
+
       $conversion = uc_weight_conversion($product->length_units, 'in');
-      $packages[$key][0]->price += $product->price * $product->qty;
-      $packages[$key][0]->length = max($product->length * $conversion, $package->length);
-      $packages[$key][0]->width = max($product->width * $conversion, $package->width);
-      $packages[$key][0]->height = max($product->height * $conversion, $package->height);
+      $package->length = max($product->length * $conversion, $package->length);
+      $package->width = max($product->width * $conversion, $package->width);
+      $package->height = max($product->height * $conversion, $package->height);
+
+      $packages[$key][] = $package;
     }
-    foreach ($packages as $key => $package) {
-      if (!$package[0]->weight) {
-        unset($packages[$key]);
-        continue;
+    foreach ($packages as $addr_key => $shipment) {
+      foreach ($shipment as $key => $package) {
+        if (!$package->weight) {
+          unset($packages[$addr_key][$key]);
+          continue;
+        }
       }
-      $packages[$key][0]->length_units = 'in';
-      $packages[$key][0]->weight_units = 'lb';
-      $packages[$key][0]->qty = 1;
-      $packages[$key][0]->pkg_type = '02';
     }
   }
   else {
     foreach ($products as $product) {
-      $addr_key = 0;
+      $key = 0;
       if ($product->nid) {
         $address = (array)uc_quote_get_default_shipping_address($product->nid);
         $key = array_search($address, $addresses);
@@ -860,6 +887,7 @@
       $num_of_pkgs = (int)($product->qty / $product->pkg_qty);
       if ($num_of_pkgs) {
         $package = drupal_clone($product);
+        $package->description = $product->model;
         $package->weight = $product->weight * $product->pkg_qty;
         $package->price = $product->price * $product->pkg_qty;
         $package->qty = $num_of_pkgs;
@@ -1495,3 +1523,21 @@
     '30' => t('Pallet'),
   );
 }
+
+function _uc_ups_new_package() {
+  $package = new stdClass();
+
+  $package->weight = 0;
+  $package->price = 0;
+
+  $package->length = 0;
+  $package->width = 0;
+  $package->height = 0;
+
+  $package->length_units = 'in';
+  $package->weight_units = 'lb';
+  $package->qty = 1;
+  $package->pkg_type = '02';
+
+  return $package;
+}

