ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/classes/currencies.php
Go to the documentation of this file.
00001 <?php
00010 // Class to handle currencies
00011 // TABLES: currencies
00012   class currencies {
00013     var $currencies;
00014 
00015 // class constructor
00016     function currencies() {
00017       global $db;
00018       $this->currencies = array();
00019       $currencies = $db->Execute("select code, title, symbol_left, symbol_right, decimal_point,
00020                                          thousands_point, decimal_places, value
00021                                   from " . TABLE_CURRENCIES);
00022 
00023       while (!$currencies->EOF) {
00024               $this->currencies[$currencies->fields['code']] = array('title' => $currencies->fields['title'],
00025                                                        'symbol_left' => $currencies->fields['symbol_left'],
00026                                                        'symbol_right' => $currencies->fields['symbol_right'],
00027                                                        'decimal_point' => $currencies->fields['decimal_point'],
00028                                                        'thousands_point' => $currencies->fields['thousands_point'],
00029                                                        'decimal_places' => (int)$currencies->fields['decimal_places'],
00030                                                        'value' => $currencies->fields['value']);
00031         $currencies->MoveNext();
00032       }
00033     }
00034 
00035 // class methods
00036     function format($number, $calculate_currency_value = true, $currency_type = DEFAULT_CURRENCY, $currency_value = '') {
00037       if ($calculate_currency_value) {
00038         $rate = ($currency_value) ? $currency_value : $this->currencies[$currency_type]['value'];
00039         $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number * $rate, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
00040 // if the selected currency is in the european euro-conversion and the default currency is euro,
00041 // the currency will displayed in the national currency and euro currency
00042         if ( (DEFAULT_CURRENCY == 'EUR') && ($currency_type == 'DEM' || $currency_type == 'BEF' || $currency_type == 'LUF' || $currency_type == 'ESP' || $currency_type == 'FRF' || $currency_type == 'IEP' || $currency_type == 'ITL' || $currency_type == 'NLG' || $currency_type == 'ATS' || $currency_type == 'PTE' || $currency_type == 'FIM' || $currency_type == 'GRD') ) {
00043           $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
00044         }
00045       } else {
00046         $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
00047       }
00048 
00049       return $format_string;
00050     }
00051 
00052     function get_value($code) {
00053       return $this->currencies[$code]['value'];
00054     }
00055 
00056     function get_decimal_places($code) {
00057       return $this->currencies[$code]['decimal_places'];
00058     }
00059 
00060     function display_price($products_price, $products_tax, $quantity = 1) {
00061       return $this->format(zen_add_tax($products_price, $products_tax) * $quantity);
00062     }
00063   }
 All Data Structures Namespaces Files Functions Variables Enumerations