--- D:/xampplite/htdocs/vat.69/sites/all/modules/ubercart/uc_store/uc_store.module.2009-02-13.bak	Fri Feb 13 17:42:02 2009
+++ D:/xampplite/htdocs/vat.69/sites/all/modules/ubercart/uc_store/uc_store.module	Mon Mar 02 17:12:12 2009
@@ -792,9 +792,18 @@
 
 /**
  * Format an amount for display with the store's currency settings.
+ * added: $curr for support of a different currency sign (multi currency)
+ * added: $prec for controlling of:
+ *        - different currency precission
+ *        - different precission for taxes.
+ *          (The usual case in countries with a currency precission different from '2')
+ * Note: Order of added variables is worth to think about once more.
  */
-function uc_currency_format($value, $sign = TRUE, $thou = TRUE, $dec = NULL) {
-  if (variable_get('uc_currency_prec', 2) > 0) {
+function uc_currency_format($value, $curr = NULL, $sign = TRUE, $thou = TRUE, $prec = NULL, $dec = NULL) {
+  if (!$curr) {
+    $curr = variable_get('uc_currency_sign', '$');
+  }
+  if ($prec > 0) {
     if (abs($value) < '.'. str_repeat('0', variable_get('uc_currency_prec', 2) - 1) .'1') {
       $value = 0;
     }
@@ -810,16 +819,155 @@
   }
 
   if ($sign && !variable_get('uc_sign_after_amount', FALSE)) {
-    $format .= variable_get('uc_currency_sign', '$');
+    $format .= $curr;
   }
 
-  $format .= number_format($value, variable_get('uc_currency_prec', 2), !is_null($dec) ? $dec : variable_get('uc_currency_dec', '.'), $thou ? variable_get('uc_currency_thou', ',') : '');
+  $format .= number_format($value, $prec, !is_null($dec) ? $dec : variable_get('uc_currency_dec', '.'), $thou ? variable_get('uc_currency_thou', ',') : '');
 
   if ($sign && variable_get('uc_sign_after_amount', FALSE)) {
-    $format .= variable_get('uc_currency_sign', '$');
+    $format .= $curr;
   }
 
   return $format;
+}
+
+
+/**
+ * Format an amount for display opening the opportunity for contribs to hook in
+ * and e.g. test for CA conditions or change the currency on all prices.
+ * Fallback: If there is no Price Display Handler installed, Item price and Qty are put together again
+ * and uc_currency_format() is returned.
+ * @param $data:
+ *   Object containing for products the Item Price, Qty (defaults to 1), the type, optional $order_id, $cart_id,
+ *   for line_items if available all line_item data + optional $order_id, $cart_id
+ * @param $sign, $thou, $dec are just passed through for uc_currency_format()
+ */
+function uc_display_price($data, $sign = TRUE, $thou = TRUE, $dec = NULL) {
+
+  $output = module_invoke_all('uc_price', $data, $sign, $thou, $dec);
+  if ($output['0']) {
+    if (!$output['0']->price['display_price']) {
+      $output['0']->price['display_value'] = uc_get_price($data);
+      $output['0']->price['display_sign'] = variable_get('uc_currency_sign', '$');
+      $output['0']->price['display_thou'] = variable_get('uc_currency_thou', ',');
+      $output['0']->price['display_dec'] = variable_get('uc_currency_dec', '.');
+      $output['0']->price['display_curr'] = variable_get('uc_currency_sign', '$');
+      $output['0']->price['display_prec'] = variable_get('uc_currency_prec', 2);
+    }
+
+    return uc_price_format($output);
+  }
+  else {
+    $price = uc_get_price($data);
+    return uc_currency_format($price, $sign, $thou, $dec);
+  }
+}
+
+/**
+ * Bring data provided by the price handler(s) together
+ * @return the formated display price incl suffix(es)
+ * working, but still under development.
+ */
+function uc_price_format($data) {
+  foreach ($data as $key => $value) {
+    if ($value->price) {
+      switch ($value->price['operand']) {
+        case '*':
+          if ($display_value) {
+            $display_value *= $value->price['display_value'];
+          }
+          else {
+            $display_value = $value->price['display_value'];
+          }
+          break;
+        case '+': default:
+          $display_value += $value->price['display_value'];
+          break;
+      }
+      // Not perfect. I see the responsibility on the latest display price modifier as I would like to summarize the suffixes.
+      $display_sign = $value->price['sign'] ? $value->price['sign'] : variable_get('uc_currency_sign', '$');
+      $display_thou = $value->price['thou'] ? $value->price['thou'] : variable_get('uc_currency_thou', ',');
+      $display_dec = $value->price['dec'] ? $value->price['dec'] : variable_get('uc_currency_dec', '.');
+      // Needed for some tax rules e.g. Switzerland, CR and display of two currencies, e.g. Slovakia
+      $display_curr = $value->price['curr'] ? $value->price['curr'] : variable_get('uc_currency_sign', '$');
+      $display_prec = $value->price['prec'] ? $value->price['prec'] : variable_get('uc_currency_prec', 2);
+    }
+    else {
+      // Fallback if the only handler installed is a suffix modifier.
+      $display_value = uc_get_price($value);
+      $display_sign = variable_get('uc_currency_sign', '$');
+      $display_thou = variable_get('uc_currency_thou', ',');
+      $display_dec = variable_get('uc_currency_dec', '.');
+      $display_curr = variable_get('uc_currency_sign', '$');
+      $display_prec = variable_get('uc_currency_prec', 2);
+    }
+
+    if ($value->suffix) {
+      // Add or Multiply the value provided by the handler.
+      // incl. fallback if there would be no display value (uc_get_price()).
+      $display_value = $display_value ? $display_value : uc_get_price($data);
+      switch ($value->suffix['operand']) {
+        case '*': $suffix_value = $display_value * $value->suffix['factor'];
+          break;
+        case '+': default: $suffix_value = $display_value + $value->suffix['display_value'];
+          break;
+      }
+      // IMO the responsibility is on the latest display price modifier
+      $suffix_sign = $value->suffix['sign'] ? $value->suffix['sign'] : variable_get('uc_currency_sign', '$');
+      $suffix_thou = $value->suffix['thou'] ? $value->suffix['thou'] : variable_get('uc_currency_thou', ',');
+      $suffix_dec = $value->suffix['dec'] ? $value->suffix['dec'] : variable_get('uc_currency_dec', '.');
+      // Needed for some tax rules e.g. Switzerland, CR and display of two currencies, e.g. Slovakia
+      $suffix_curr = $value->suffix['curr'] ? $value->suffix['curr'] : variable_get('uc_currency_sign', '$');
+      $suffix_prec = $value->suffix['prec'];
+      $suffix_prefix = $value->suffix['prefix'] ?  $value->suffix['prefix'] : '';
+      $suffix_suffix = $value->suffix['suffix'] ?  $value->suffix['suffix'] : '';
+      // The informations provided by the modules we can make collectable. Example: plus shipping.
+      if ($infos && $value->suffix['info']) {
+        $infos .= ', '. $value->suffix['info'];
+      }
+      elseif ($value->suffix['info']) {
+        $infos = $value->suffix['info'];
+      }
+
+    }
+  }
+  $output = '<span class="bold">'. uc_currency_format($display_value, $display_curr, $display_sign, $display_thou, $display_prec, $display_dec) .'</span>';
+  $output .= $suffix_prefix;
+  if ($suffix_value) {
+    $output .= '<span class="bold">'. uc_currency_format($suffix_value, $suffix_curr, $suffix_sign, $suffix_thou, $suffix_prec, $suffix_dec) .'</span>';
+    if ($infos) {
+      $output .= ', ';
+    }
+  }
+  $output .= $infos . $suffix_suffix;
+  return $output;
+}
+
+/**
+ * Fallback function for the US used in uc_display_price().
+ * Filters the amount and quantity both for products as well for line_items and puts the total amount
+ * together again to be displayed through uc_currency_format()
+ */
+function uc_get_price($data){
+  $qty = '1';
+  if ($data->price) {
+    $amount = $data->price;
+    if ($data->qty) {
+      $qty = $data->qty;
+    }
+  }
+  elseif ($data->line_items['amount']) {
+    $amount = $data->line_items['amount'];
+    if ($data->line_items['qty']) {
+      $qty = $data->line_items['qty'];
+    }
+  }
+  // prevents zero values from not updated modules.
+  elseif (is_numeric($data)) {
+    $amount = $data;
+  }
+  $price = $amount * $qty;
+  return $price;
 }
 
 /**
