Wondering if anyone can help me out with the following:

I'm after some kind of if statement to include in the code so that Currency Exchange calculates the rate to include a 3% bank charge.

When converting from GBP to X(anything else), I want the result to be multiplied by 1.03
When converting from X to GBP, I want the result to be multiplied by 0.97

I can do one of the above quite simply by doing $amount*0.97 or $amount*1.03, but I'm not a good enough coder to do both. The if statement needs to be able to tell whether it's converting from or to GBP, and then multiply by the necessary figure (and if converting neither to or from GBP, then do nothing).

Can anybody help me out with this? I would massively appreciate it!

Comments

amateescu’s picture

Status: Active » Fixed

You can override the default theme function provided by the module with something like:

function MYTHEME_currency_result($variables) {
  $output = '';

  $currency_from = $variables['currency_from'];
  $currency_to = $variables['currency_to'];
  $amount = $variables['amount'];

  $url = 'http://finance.yahoo.com/q?s=' . $currency_from . $currency_to . '=X';

  $ret = currency_api_convert($currency_from, $currency_to, $amount);
  if ($ret['status'] == FALSE) { 
    $output .= t('Currency exchange error: @message', array('@message' => $ret['message']));
  }
  else {
    if ($currency_from == 'GBP') {
      $ret['value'] = $ret['value'] * 1.03;
    }
    elseif ($currency_to == 'GBP') {
      $ret['value'] = $ret['value'] * 0.97;
    }

    $output .= '<p class="result">';
    $output .=  t('@amount @from = @value @to', array(
      '@amount' => $amount,
      '@from' => currency_api_get_desc($currency_from),
      '@value' => $ret['value'],
      '@to' => currency_api_get_desc($currency_to)));
    $output .= '</p>';
    $output .= '<p class="detailed-history">' . l(t('Detailed history and chart'), $url) . '</p>';
  }

  $output = '<div class="currency-result">' . $output . '</div>';

  return $output;
}
Corbey’s picture

Ah brilliant. Seems so simple when you put it like that!
Thanks so much!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.