commit 4d404e2e80cb3bef7dcb75539321fc248af57967
Author: Chris Burgess <chris@giantrobot.co.nz>
Date:   Wed Jul 27 14:30:39 2011 +1200

    Issue #621494. Based on existing patch and documentation at http://www.vintagedigital.net/content/how-add-multicurrency-support-ubercart

diff --git a/payment/uc_authorizenet/uc_authorizenet.module b/payment/uc_authorizenet/uc_authorizenet.module
index 72618a1..3b45d01 100644
--- a/payment/uc_authorizenet/uc_authorizenet.module
+++ b/payment/uc_authorizenet/uc_authorizenet.module
@@ -366,6 +366,9 @@ function _uc_authorizenet_cim_profile_charge($order, $amount, $data) {
       $context = array(
         'revision' => 'formatted-original',
         'type' => 'amount',
+        'subject' => array(
+          'order' => $order,
+        ),
       );
       $comment[] = t('<b>@type:</b> @amount', array('@type' => $types[$data['txn_type']], '@amount' => uc_price($amount, $context)));
 
@@ -459,6 +462,9 @@ function _uc_authorizenet_charge($order, $amount, $data) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'amount',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
   $options = array(
     'sign' => FALSE,
@@ -635,6 +641,9 @@ function _uc_authorizenet_charge($order, $amount, $data) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'amount',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
   $comment = t('<b>@type</b><br /><b>@status:</b> @message<br />Amount: @amount<br />AVS response: @avs',
     array('@type' => _uc_authorizenet_txn_type($response[11]), '@status' => $result['success'] ? t('ACCEPTED') : t('REJECTED'), '@message' => $response[3], '@amount' => uc_price($response[9], $context), '@avs' => _uc_authorizenet_avs($response[5])));
diff --git a/payment/uc_credit/test_gateway.module b/payment/uc_credit/test_gateway.module
index 76aa5a9..0aa2f89 100644
--- a/payment/uc_credit/test_gateway.module
+++ b/payment/uc_credit/test_gateway.module
@@ -47,6 +47,9 @@ function test_gateway_charge($order_id, $amount, $data) {
     $context = array(
       'revision' => 'formatted-original',
       'type' => 'amount',
+      'subject' => array(
+        'order' => $order,
+      ),
     );
     $message = t('Credit card charged: !amount', array('!amount' => uc_price($amount, $context)));
     uc_order_comment_save($order_id, $user->uid, $message, 'admin');
diff --git a/payment/uc_credit/uc_credit.admin.inc b/payment/uc_credit/uc_credit.admin.inc
index c410517..1f508d5 100644
--- a/payment/uc_credit/uc_credit.admin.inc
+++ b/payment/uc_credit/uc_credit.admin.inc
@@ -51,6 +51,9 @@ function uc_credit_terminal_form($form_state, $order, $lock_amount = FALSE) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'amount',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
   $options = array(
     'sign' => FALSE,
diff --git a/payment/uc_cybersource/uc_cybersource.module b/payment/uc_cybersource/uc_cybersource.module
index a527782..4942a4e 100644
--- a/payment/uc_cybersource/uc_cybersource.module
+++ b/payment/uc_cybersource/uc_cybersource.module
@@ -448,6 +448,9 @@ function uc_cybersource_hop_form($form_state, $order) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'amount',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
   $options = array(
     'sign' => FALSE,
@@ -676,6 +679,9 @@ function _uc_cybersource_post_charge($order, $amount, $data, $cc_type, $country)
     $context = array(
       'revision' => 'formatted-original',
       'type' => 'amount',
+      'subject' => array(
+        'order' => $order,
+      ),
     );
     $o_comment = t('<b>Credit card !type:</b> !amount<br /><b>Decision: @decision</b><br /><b>Reason:</b> !reason', array('!type' => variable_get('uc_cybersource_transaction_type', 'sale'), '!amount' => uc_price($nvp['orderAmount'], $context), '@decision' => $nvp['decision'], '!reason' => _parse_cs_reason_code($nvp['reasonCode'])));
     $p_comment = t('!id<br />!decision, Reason: !reason', array('!id' => $nvp['orderPage_serialNumber'], '!decision' => $nvp['decision'], '!reason' => $nvp['reasonCode']));
@@ -903,6 +909,9 @@ function _uc_cybersource_soap_charge($order, $amount, $data, $cc_type, $country)
     $context = array(
       'revision' => 'formatted-original',
       'type' => 'amount',
+      'subject' => array(
+        'order' => $order,
+      ),
     );
     $o_comment = t('<b>@type:</b> @amount<br /><b>Decision: @decision</b><br /><b>Reason:</b> !reason', array('@type' => $types[$data['txn_type']], '@amount' => uc_price($amount, $context), '@decision' => $reply->decision, '!reason' => _parse_cs_reason_code($reply->reasonCode)));
     $p_comment = t('<b>@type:</b><br />@id<br />@decision, Reason: !reason', array('@type' => $types[$data['txn_type']], '@id' => $reply->requestID, '@decision' => $reply->decision, '!reason' => $reply->reasonCode));
@@ -988,6 +997,9 @@ function uc_cybersource_tax_test($order) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'line_item',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
 
   // Build an item list for the taxes.
@@ -1207,6 +1219,9 @@ function uc_cybersource_calculate_tax($order) {
         $context = array(
           'revision' => 'formatted-original',
           'type' => 'amount',
+          'subject' => array(
+            'order' => $order,
+          ),
         );
         watchdog('uc_cybersource', 'Tax calculation produced uneven results. Expected a total of @total, received the following: @dump', array('@total' => uc_price($reply->taxReply->totalTaxAmount, $context), '@dump' => '<pre>'. print_r($result, TRUE) .'</pre>'), WATCHDOG_ERROR);
 
diff --git a/payment/uc_google_checkout/uc_google_checkout.admin.inc b/payment/uc_google_checkout/uc_google_checkout.admin.inc
index 022d381..ccdf83b 100644
--- a/payment/uc_google_checkout/uc_google_checkout.admin.inc
+++ b/payment/uc_google_checkout/uc_google_checkout.admin.inc
@@ -327,6 +327,9 @@ function uc_google_checkout_terminal_form($form_state, $order, $amount = 0) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'amount',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
   $options = array(
     'sign' => FALSE,
diff --git a/payment/uc_google_checkout/uc_google_checkout.module b/payment/uc_google_checkout/uc_google_checkout.module
index a246254..f7799c2 100644
--- a/payment/uc_google_checkout/uc_google_checkout.module
+++ b/payment/uc_google_checkout/uc_google_checkout.module
@@ -1014,6 +1014,9 @@ function uc_google_checkout_charge_order($charge) {
     $context = array(
       'revision' => 'formatted-original',
       'type' => 'amount',
+      'subject' => array(
+        'order' => $order,
+      ),
     );
     uc_order_comment_save($order_id, 0, t('Payment of %amount received by Google Checkout.', array('%amount' => uc_price($amount, $context))), 'admin', 'chargeable');
 
diff --git a/payment/uc_payment/uc_payment.admin.inc b/payment/uc_payment/uc_payment.admin.inc
index ea611f4..74c870b 100644
--- a/payment/uc_payment/uc_payment.admin.inc
+++ b/payment/uc_payment/uc_payment.admin.inc
@@ -438,6 +438,7 @@ function uc_payment_delete_confirm_form($form_state, $order, $payment) {
     'type' => 'payment',
     'subject' => array(
       'payment' => $payment,
+      'order' => $order,
     ),
   );
 
diff --git a/payment/uc_payment/uc_payment.module b/payment/uc_payment/uc_payment.module
index 8a97c68..7240d68 100644
--- a/payment/uc_payment/uc_payment.module
+++ b/payment/uc_payment/uc_payment.module
@@ -146,6 +146,9 @@ function uc_payment_token_values($type, $object = NULL) {
       $context = array(
         'revision' => 'formatted',
         'type' => 'amount',
+        'subject' => array(
+          'order' => $order,
+        ),
       );
       $values['order-payment-balance'] = uc_price(uc_payment_balance($order), $context);
       break;
@@ -377,7 +380,7 @@ function uc_payment_get_totals($return = FALSE, $order = NULL) {
 
     $context['revision'] = 'themed';
     $context['type'] = 'amount';
-    unset($context['subject']);
+    unset($context['subject']['line_item']);
     $output .= '<tr><td align="right"><b>'. t('Order total:') .'</b></td>'
               .'<td align="right">'. uc_price(uc_order_get_total($order), $context)
               .'</td></tr></table>';
@@ -609,12 +612,17 @@ function uc_payment_enter($order_id, $method, $amount, $uid, $data, $comment) {
   if (is_array($data)) {
     $data = serialize($data);
   }
+  
+  $order = uc_order_load($order_id);
 
   if (variable_get('uc_payment_logging', TRUE)) {
     global $user;
     $context = array(
       'revision' => 'formatted',
       'type' => 'amount',
+      'subject' => array(
+        'order' => $order,
+      ),
     );
     $log_message = t('@method payment for @amount entered by @user.', array('@method' => $method_name, '@amount' => uc_price($amount, $context), '@user' => uc_get_initials($user->uid)));
     uc_order_log_changes($order_id, array($log_message));
@@ -623,7 +631,6 @@ function uc_payment_enter($order_id, $method, $amount, $uid, $data, $comment) {
   db_query("INSERT INTO {uc_payment_receipts} (order_id, method, amount, uid, data, comment, received) VALUES (%d, '%s', %f, %d, '%s', '%s', %d)",
     $order_id, $method_name, $amount, $uid, $data, $comment, time());
 
-  $order = uc_order_load($order_id);
   $account = user_load($uid);
 
   module_invoke_all('uc_payment_entered', $order, $method, $amount, $account, $data, $comment);
diff --git a/payment/uc_payment_pack/uc_payment_pack.admin.inc b/payment/uc_payment_pack/uc_payment_pack.admin.inc
index 67758b2..2c07572 100644
--- a/payment/uc_payment_pack/uc_payment_pack.admin.inc
+++ b/payment/uc_payment_pack/uc_payment_pack.admin.inc
@@ -18,6 +18,9 @@ function uc_payment_pack_receive_check_form($form_state, $order) {
   $context = array(
     'revision' => 'formatted-original',
     'type' => 'amount',
+    'subject' => array(
+      'order' => $order,
+    ),
   );
   $options = array(
     'sign' => FALSE,
diff --git a/payment/uc_payment_pack/uc_payment_pack.module b/payment/uc_payment_pack/uc_payment_pack.module
index 4223a78..04a9e00 100644
--- a/payment/uc_payment_pack/uc_payment_pack.module
+++ b/payment/uc_payment_pack/uc_payment_pack.module
@@ -161,6 +161,9 @@ function uc_payment_method_cod($op, &$order) {
         $context = array(
           'revision' => 'formatted-original',
           'type' => 'amount',
+          'subject' => array(
+            'order' => $arg1,
+          ),
         );
         $details .= '<p>'. t('Orders totalling more than !number are <b>not eligible</b> for COD.', array('!number' => uc_price($max, $context))) .'</p>';
       }
diff --git a/uc_cart/uc_cart_checkout_pane.inc b/uc_cart/uc_cart_checkout_pane.inc
index bcf9f84..f661b3a 100644
--- a/uc_cart/uc_cart_checkout_pane.inc
+++ b/uc_cart/uc_cart_checkout_pane.inc
@@ -24,7 +24,10 @@ function uc_checkout_pane_cart($op) {
       return array('contents' => $contents, 'next-button' => FALSE);
 
     case 'review':
+      global $user;
       $items = uc_cart_get_contents();
+      $order_id = db_result(db_query_range("SELECT order_id FROM {uc_orders} WHERE order_status = 'in_checkout' AND uid = %d ORDER BY order_id DESC", $user->uid, 0, 1));
+      $order = uc_order_load($order_id);
       $output = '<table>';
       $context = array(
         'revision' => 'themed',
@@ -42,6 +45,7 @@ function uc_checkout_pane_cart($op) {
           'cart' => $items,
           'cart_item' => $item,
           'node' => node_load($item->nid),
+          'order' => $order,
         );
         $output .= '<tr valign="top"><td>'. $item->qty .'&times;</td><td width="100%">'. $desc
                   .'</td><td nowrap="nowrap">'. uc_price($price_info, $context) .'</td></tr>';
diff --git a/uc_order/uc_order.admin.inc b/uc_order/uc_order.admin.inc
index ee8cd0c..17e75c3 100644
--- a/uc_order/uc_order.admin.inc
+++ b/uc_order/uc_order.admin.inc
@@ -489,6 +489,7 @@ function uc_order_admin($sql = NULL, $args = NULL, $search = FALSE) {
         $order_name = t('User: !name', array('!name' => $account));
       }
     }
+    $context['subject']['order'] = $order;
 
     $rows[] = array(
       'data' => array(
