Index: uc_upsell_core.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_upsell/uc_upsell_core.inc,v
retrieving revision 1.1.2.27
diff -u -p -r1.1.2.27 uc_upsell_core.inc
--- uc_upsell_core.inc	6 Sep 2009 02:35:22 -0000	1.1.2.27
+++ uc_upsell_core.inc	20 Nov 2009 23:34:37 -0000
@@ -88,9 +88,27 @@ function uc_upsell_resolve_associates(&$
   // Set msg based on strict flag and number of sources...
   $msg = ($primary && ($sources == 1 || $config['global']['loose_msg_req'])) ? (($context == 'pane') ? $config['pane']['msg_related'] : $config['block'][$context]['msg_related']) : (($context == 'pane') ? $config['pane']['msg_mixed'] : $config['block'][$context]['msg_mixed']);
 
+  // If this is a form submission, the contents of the upsell products
+  // must stay fixed; otherwise the form we are posting to may not exist.
+  if (isset($_POST['form_id'])) {
+    if (strpos($_POST['form_id'], 'uc_product_add_to_cart_form_') === 0) { // todo don't forget buy now
+      if (isset($_SESSION['uc_upsell_related'][$dpath])) {
+        $products = array_map('node_load', $_SESSION['uc_upsell_related'][$dpath]);
+        return $products;
+      }
+    }
+  }
+
   // Shuffle the products
   if ($config['global']['shuffle']) shuffle($related);
   $related = array_slice($related, 0, $vars['max']);
+
+  // Store the product list in the session, it's needed later if one of the forms gets submitted.
+  if (!isset($_SESSION['uc_upsell_related'])) {
+    $_SESSION['uc_upsell_related'] = array();
+  }
+  $_SESSION['uc_upsell_related'][$dpath] = $related;
+
   $products = array_map('node_load', $related);
   return $products;
 }
