[TEP-COMMIT] CVS: catalog/catalog/includes/classes currencies.php,1.17,1.18 order.php,1.34,1.35
Harald Ponce de Leon <[email protected]>
| Newsgroups | gmane.comp.web.oscommerce.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tep/catalog/catalog/includes/classes
In directory sc8-pr-cvs1:/tmp/cvs-serv10016/catalog/includes/classes
Modified Files:
currencies.php order.php
Log Message:
update the currencies class
* $currencies -> $osC_Currencies
* $currencies->display_price() -> $osC_Currencies->displayPrice()
+-- now passes the product tax class id as a parameter instead of the
product tax rate value (saves queries when DISPLAY_PRICES_WITH_TAX
is disabled)
* $currencies->is_set()
+-- removed due to $osC_Currencies->exists()
* $currencies->get_decimal_places() -> $osC_Currencies->decimalPlaces()
* $currencies->get_value() -> $osC_Currencies->value()
* $osC_Currencies->format()
+-- removed $calculate_currency_value (second) parameter due to
redundancy - if the number should not be calculated with the currency
rate, a value of '1' should be passed as the currency rate value
Index: currencies.php
===================================================================
RCS file: /cvsroot/tep/catalog/catalog/includes/classes/currencies.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- currencies.php 17 Nov 2003 19:15:06 -0000 1.17
+++ currencies.php 18 Dec 2003 23:52:14 -0000 1.18
@@ -10,14 +10,11 @@
Released under the GNU General Public License
*/
-////
-// Class to handle currencies
-// TABLES: currencies
- class currencies {
+ class osC_Currencies {
var $currencies;
// class constructor
- function currencies() {
+ function osC_Currencies() {
$this->currencies = array();
$currencies_query = tep_db_query("select code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);
while ($currencies = tep_db_fetch_array($currencies_query)) {
@@ -32,49 +29,51 @@
}
// class methods
- function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
+ function format($number, $currency_code = '', $currency_value = '') {
global $osC_Session;
- if (empty($currency_type)) $currency_type = $osC_Session->value('currency');
+ if (empty($currency_code) || ($this->exists($currency_code) == false)) {
+ $currency_code = $osC_Session->value('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'];
-// if the selected currency is in the european euro-conversion and the default currency is euro,
-// the currency will displayed in the national currency and euro currency
- 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') ) {
- $format_string .= ' <small>[' . $this->format($number, true, 'EUR') . ']</small>';
- }
- } 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'];
+ if (empty($currency_value) || (is_numeric($currency_value) == false)) {
+ $currency_value = $this->currencies[$currency_code]['value'];
}
- return $format_string;
+ return $this->currencies[$currency_code]['symbol_left'] . number_format(tep_round($number * $currency_value, $this->currencies[$currency_code]['decimal_places']), $this->currencies[$currency_code]['decimal_places'], $this->currencies[$currency_code]['decimal_point'], $this->currencies[$currency_code]['thousands_point']) . $this->currencies[$currency_code]['symbol_right'];
}
- function is_set($code) {
- if (isset($this->currencies[$code]) && tep_not_null($this->currencies[$code])) {
- return true;
- } else {
- return false;
- }
- }
+ function displayPrice($price, $tax_class_id, $quantity = 1) {
+ global $osC_Tax;
- function get_value($code) {
- return $this->currencies[$code]['value'];
- }
+ $price = tep_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
- function get_decimal_places($code) {
- return $this->currencies[$code]['decimal_places'];
- }
+ if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax_class_id > 0) ) {
+ $price += tep_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
+ }
- function display_price($products_price, $products_tax, $quantity = 1) {
- return $this->format(tep_add_tax($products_price, $products_tax) * $quantity);
+ return $this->format($price * $quantity);
}
function exists($code) {
if (isset($this->currencies[$code])) {
return true;
+ }
+
+ return false;
+ }
+
+ function decimalPlaces($code) {
+ if ($this->exists($code)) {
+ return $this->currencies[$code]['decimal_places'];
+ }
+
+ return false;
+ }
+
+ function value($code) {
+ if ($this->exists($code)) {
+ return $this->currencies[$code]['value'];
}
return false;
Index: order.php
===================================================================
RCS file: /cvsroot/tep/catalog/catalog/includes/classes/order.php,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- order.php 17 Nov 2003 19:29:44 -0000 1.34
+++ order.php 18 Dec 2003 23:52:14 -0000 1.35
@@ -131,7 +131,7 @@
}
function cart() {
- global $osC_Session, $osC_Customer, $osC_Tax, $cart, $currencies;
+ global $osC_Session, $osC_Customer, $osC_Tax, $cart, $osC_Currencies;
$this->content_type = $cart->get_content_type();
@@ -152,7 +152,7 @@
$this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
'currency' => $osC_Session->value('currency'),
- 'currency_value' => $currencies->currencies[$osC_Session->value('currency')]['value'],
+ 'currency_value' => $osC_Currencies->currencies[$osC_Session->value('currency')]['value'],
'payment_method' => $payment,
'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
@@ -221,6 +221,7 @@
'model' => $products[$i]['model'],
'tax' => $osC_Tax->getTaxRate($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
'tax_description' => $osC_Tax->getTaxRateDescription($products[$i]['tax_class_id'], $tax_address['entry_country_id'], $tax_address['entry_zone_id']),
+ 'tax_class_id' => $products[$i]['tax_class_id'],
'price' => $products[$i]['price'],
'final_price' => $products[$i]['price'] + $cart->attributes_price($products[$i]['id']),
'weight' => $products[$i]['weight'],
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click