Index: cart/cart.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ecommerce/cart/cart.module,v
retrieving revision 1.133.2.6
diff -u -r1.133.2.6 cart.module
--- cart/cart.module	9 Sep 2006 03:18:14 -0000	1.133.2.6
+++ cart/cart.module	18 Sep 2006 03:38:38 -0000
@@ -1,4 +1,3 @@
-<?php
 // $Id: cart.module,v 1.133.2.6 2006/09/09 03:18:14 neclimdul Exp $

 /********************************************************************
@@ -707,6 +706,15 @@
         $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) {
@@ -714,12 +722,43 @@
             // 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.13
diff -u -r1.125.2.13 store.module
--- store/store.module	9 Sep 2006 03:18:14 -0000	1.125.2.13
+++ store/store.module	18 Sep 2006 03:38:41 -0000
@@ -2508,13 +2508,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;
 }
