psynaptic Posted May 7, 2007 Share Posted May 7, 2007 Hi there, I have a client who sells goods sourced from the UK and Japan. The prices for items sourced in Japan are in Japanese Yen (JPY). He currently manages his prices using a spreadsheet and calculates the price based on the current exchange rates manually. I am building him an osCommerce site and it would greatly benefit him to automate this process. The prices from his supplier are fixed at the JPY rate and need converting into GBP. There are also prices in GBP that need to be entered and left out of any conversions. I have read some topics on the forum and had a good think on the matter. I have come up with the following methodology. The simplest way for the store owner to manage his prices is to have the ability to enter the price in the relevant currency. This could be achieved by having two input fields or radio select buttons. We could add two columns to the products table: products_price_currency and products_currency_code. We would then need to place a NULL value in products_price when entering a price in the alternative currency. Once we have a NULL value in products_price we can test for it and calculate the default currency price using the currency exchange rate value from the currencies table (based on whichever currency code was placed in products_currency_code). Preferably this should be done during the add new product process so prices will not show as 0 in the catalog side. Does anyone have any comments or suggestions on this? My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
psynaptic Posted May 7, 2007 Author Share Posted May 7, 2007 Calculating the price based on the new tables should be a simple task. We could test for the value in products_currency_code and calculate the displayed price based on this. If we find the default currency we do nothing. If we find a code other than that the default we can calculate the price from that value. Please, more ideas would be greatly appreciated. My Profile | Contribs I like most: 'On The Fly' Auto Thumbnailer, Active Countries, Header Tags Controller, Ultimate SEO URLs, UK Based osC, UK Postcode Validation, Open Featured Sets, UK Postcode Based Carrier Shipping Link to comment Share on other sites More sharing options...
b_vassy Posted July 7, 2007 Share Posted July 7, 2007 Hi psynaptic, I'm also interested in doing this for my site. Can you tell me if it worked for you? I need to be able to insert prices in either Euro or USD and what i was thinking was to add a new column to the products table (product_currency) where i should enter the currency code. After, I would modify the function that calculates the price in the default currency so that if the new column is set to another currency code than the default one, it should calculate the price based on the exchange rate available. Would you share what you have done so far? It could help me a lot and i'm sure many others are interested in this. Thanks in advance, Vassy Link to comment Share on other sites More sharing options...
Janissary Posted August 20, 2007 Share Posted August 20, 2007 find this in includes/classes/currencies.php // class methods function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') { and change the whole format function to this // class methods function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '',$Write_Second_Curr = false) { global $currency; if (empty($currency_type)) $currency_type = $currency; if($Write_Second_Curr == false) { 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']; } } else { $currency_type = 'TRY'; // second currency $currency_value = ''; if ($calculate_currency_value == true) { $rate = (tep_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value']; $format_string .= "\n" .$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 ( (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 .= "\n" .$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; } find $currency_type = 'TRY'; // second currency and change the code to anything u want. And to display in this second currency you need to add to your $currencies->format(..,true ) where u want to display in second currency.. if u have any further questions feel free to pm me Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.