Post by deanfourie » Fri Nov 21, 2014 11:42 am

So, ive been having these issues now for over 3 months and still not able to find a solution! Im sure if its opencart itself or if what im trying to accomplish is just something uncommon!

Im running an online store based in New Zealand. All suppliers are based in the US and all purchases are made in the US in USD. My problem is displaying prices in NZD based on USD prices and exchange rates. I found that manually converting the currencies is obviously not the right way to do this, as the prices change to ofter so what I would like to do is have a automatic currency conversion take place based on the USD price in back end, then display the price in NZD based on the USD pirce and current exchange rate! This way I know that when a customer places an order, it has calculated the order price based on the current exchange rate on the USD price, so im not left with any nasty surprises when it comes to ordering stock!

Why am I having so much trouble getting the pricing correct? I mean, how do other stores get around this?

Thanks, and apologies for the frustration but ive basically had to take my website down until I can find a solution, just when it started actually getting good recognition from google! :(

New member

Posts

Joined
Sat Mar 22, 2014 9:01 pm

Post by clorne » Fri Nov 21, 2014 4:22 pm

The last time you posted this in October it was suggested
This is just a quick and untested idea for you.

Go to the currency update file

admin/model/localisation/currency.php

find the following code block in the updateCurrencies function

Code: Select all

foreach ($lines as $line) {
				$currency = utf8_substr($line, 4, 3);
				$value = utf8_substr($line, 11, 6);
immediately under this insert

Code: Select all

If ($currency == 'USD') {
                                    $original_exchange_rate = ' ## put your current NZD-USD exchange rate here ## ';
                                    $new_exchange_rate = $value;
                                    $per_cent = ($new_exchange_rate-$original_exchange_rate)/$original_exchange_rate;
                                    
                                $this->db->query("UPDATE " . DB_PREFIX . "product SET price = ROUND (price * '" . (float)$per_cent . "', 2) + price") ; 
                                }
As you can see, each time the rates are automatically updated a comparison is made between the new and original exchange rate for NZD/USD and your product prices set accordingly.

Try this on your test/development site not production site as the code hasn't been tried but it should work.
Did you try this on a test site?

EDIT/CORRECTION
The code above is incorrect instead try

immediately above

Code: Select all

foreach ($lines as $line) {
				$currency = utf8_substr($line, 4, 3);
				$value = utf8_substr($line, 11, 6);
put

Code: Select all

                        $query_current = $this->db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE code = 'USD'");
                       
                        $currency_current = $query_current->row;
and immediately below

Code: Select all

foreach ($lines as $line) {
				$currency = utf8_substr($line, 4, 3);
				$value = utf8_substr($line, 11, 6);
put

Code: Select all

If ($currency == 'USD') {
                                    $original_exchange_rate = $currency_current['value'] ;
                                    $new_exchange_rate = $value;
                                    $per_cent = ($original_exchange_rate-$new_exchange_rate)/$new_exchange_rate;
                                    
                                $this->db->query("UPDATE " . DB_PREFIX . "product SET price = ROUND (price * '" . (float)$per_cent . "', 2) + price") ; 
                                }
again try this in your test site until you are sure it works!
Last edited by clorne on Thu Nov 27, 2014 5:49 pm, edited 3 times in total.

Active Member

Posts

Joined
Fri Dec 23, 2011 6:03 pm

Post by deanfourie » Sat Nov 22, 2014 9:44 am

ok cheers I will try this now

New member

Posts

Joined
Sat Mar 22, 2014 9:01 pm

Post by deanfourie » Sun Nov 30, 2014 3:20 pm

Will this effect shipping prices etc?

New member

Posts

Joined
Sat Mar 22, 2014 9:01 pm

Post by deanfourie » Sun Nov 30, 2014 3:20 pm

Will this effect shipping prices etc?

New member

Posts

Joined
Sat Mar 22, 2014 9:01 pm
Who is online

Users browsing this forum: No registered users and 54 guests