Index: cart/cart.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/cart/cart.module,v
retrieving revision 1.133.2.5
diff -u -r1.133.2.5 cart.module
--- cart/cart.module	2 Aug 2006 05:12:54 -0000	1.133.2.5
+++ cart/cart.module	8 Sep 2006 03:43:58 -0000
@@ -707,19 +707,56 @@
         $txn->subtotal += $subtotal;
       }

+      // Since we may remove items, keep a track of the current key.
+      $line = 0;
+      // Keep track of which lines are subtotals.
+      $st = array('#row_type' => 'ST');
+
+      // Create a subtotal line.
+      // If the Total comes immediately afterwards, then it will be repressed later.
+      $form['totals'][$line++] = array('#title' => t('Subtotal'), '#value' => $txn->subtotal, 'info' => $st);
+
       $form['totals'] = array();
       if ($txn->misc) {
         foreach ($txn->misc as $misc) {
+
           if (!$misc->seen) {
-            // Only add the subtotal line if there are other items in misc.
-            if ($form['totals']) {
-              $form['totals'][] = array('#title' => t('Subtotal'), '#value' => $txn->subtotal);
+            // Subtotal
+            if ($misc->subtotal_before && ($form['totals'][$line-1]['info']['#row_type'] != $st['#row_type'])) {
+              $form['totals'][$line++] = array('#title' => t('Subtotal'), '#value' => $txn->subtotal, 'info' => $st);
+            }
+          }
+
+          // Do this just like store_transaction_calc_gross.
+          if (function_exists($misc->callback)) {
+            $f = $misc->callback;
+            $amount = $f($txn, $misc, $txn->subtotal);
+          }
+          elseif ($misc->qty) {
+            $amount = ($misc->price * $misc->qty);
+          }
+          else {
+            $amount = $misc->price;
+          }
+          if(!$misc->already_added) { $txn->subtotal+= $amount; }
+
+          if (!$misc->seen) {
+
+            // Misc Item
+            $form['totals'][$line++] = array('#title' => t($misc->description), '#value' => $amount);
+            // Subtotal
+            if ($misc->subtotal_after) {
+              $form['totals'][$line++] = array('#title' => t('Subtotal'), '#value' => $txn->subtotal, 'info' => $st);
             }
-            $form['totals'][] = array('#title' => t($misc->description), '#value' => $misc->price);
           }
         }
       }
-
+
+      // Remove any subtotal occurring before the total.
+      if ($form['totals'][$line-1]['info']['#row_type'] == $st['#row_type']) {
+        unset($form['totals'][$line-1]);
+      }
+      // Grand total
       $form['totals'][] = array('#title' => t('Total'), '#value' => $txn->gross);

       $form = array('cart' => $form);
Index: store/store.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/store/store.module,v
retrieving revision 1.125.2.12
diff -u -r1.125.2.12 store.module
--- store/store.module	8 Sep 2006 01:35:28 -0000	1.125.2.12
+++ store/store.module	8 Sep 2006 03:44:00 -0000
@@ -2511,13 +2511,18 @@
   foreach ((array)$txn->items as $item) {
     $total+= product_has_quantity($item) ? $item->price * $item->qty : $item-> price;
   }
-  foreach ((array)$txn->misc as $misc) {
-    if ($misc->qty) {
-      $total+= ($misc->price * $misc->qty);
+  foreach ((array)$txn->misc as $key => $misc) {
+    if (function_exists($misc->callback)) {
+      $f = $misc->callback;
+      $amount = $f($txn, $misc, $total);
+    }
+    elseif ($misc->qty) {
+      $amount = ($misc->price * $misc->qty);
     }
     else {
-      $total+= $misc->price;
+      $amount = $misc->price;
     }
+    if(!$misc->already_added) {$total+= $amount;};
   }
   return $total;
 }
