Jump to content

Archived

This topic is now archived and is closed to further replies.

Moxamint

Why can't I use function format() in a payment module

Recommended Posts

Hi,

 

I wanted to show cart total in the title text of my bank payment module, so I used function format() to format the currency. Then I received the following error message:

 

Fatal error: Call to a member function format() on a non-object in /home/httpd/vhosts/xxx.com/httpdocs/includes/modules/payment/bank.php on line 77

 

Why couldn't I call function format() in a payment module? What should I do to make it work?

 

Thank you very much in advance if anyone can point me to the right direction.

 

Best wishes, Eddy

Share this post


Link to post
Share on other sites

you could take a look at for example the paypal express payment module:

 

// format prices without currency formatting
function format_raw($number, $currency_code = '', $currency_value = '') {
 global $currencies, $currency;
 if (empty($currency_code) || !$currencies->is_set($currency_code)) {
 $currency_code = $currency;
 }
 if (empty($currency_value) || !is_numeric($currency_value)) {
 $currency_value = $currencies->currencies[$currency_code]['value'];
 }
 return number_format(tep_round($number * $currency_value, $currencies->currencies[$currency_code]['decimal_places']), $currencies->currencies[$currency_code]['decimal_places'], '.', '');
}

 

if look at the function format you try to use (inside includes/classes/currencies.php) :

 

// class methods
function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
 global $currency;
 if (empty($currency_type)) $currency_type = $currency;
 if ($calculate_currency_value == true) {
 $rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
 $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
 } else {
 $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
 }
 return $format_string;
}

Share this post


Link to post
Share on other sites

×