Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Oanda failure in localization.php


Philip79

Recommended Posts

It appears that Oanda has discontinued or changed the access to their currency rates as the program \admin\includes\functions\localization.php is erroring out with the URL previously that worked for years.  Anyone with any information?  This happened with XE in 2015.  Thanks.

Link to comment
Share on other sites

I believe it is not just oanda as xe is also getting errors.

 

Warning: file_get_contents(http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=USD&format=CSV&dest=Get+Table&sel_list=USD): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in  /home/XXXXXXXX/public_html/XXXXXXX/includes/functions/localization.php on line 14

Warning: file_get_contents(http://www.xe.net/ucc/convert.cgi?Amount=1&From=USD&To=USD): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in  /home/XXXXXXXX/public_html/XXXXXXX/includes/functions/localization.php on line 25

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks Gary. Your solution is working perfectly and is very much appreciated. 

Link to comment
Share on other sites

I been having the same problem, no currencies updating. has anyone found a solution to this problem ? Im really new to oscom. I dont understand the above "solution"

Link to comment
Share on other sites

@@burt here is some sample code that includes the address to google's API. I use this in a cron job to update automatically.

 

<code>

<?php

$from_currency = 'USD';

$to_currency = 'INR';

$amount = 1;

$results = converCurrency($from_currency,$to_currency,$amount);

$regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';

preg_match($regularExpression, $results, $finalData);

echo $finalData[0];

 

function converCurrency($from,$to,$amount){

$url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";

$request = curl_init();

$timeOut = 0;

curl_setopt ($request, CURLOPT_URL, $url);

curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");

curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);

$response = curl_exec($request);

curl_close($request);

return $response;

}

?><\code>

Link to comment
Share on other sites

Oh gosh no. 

 

That relies on a regex to find bld class, which is a similar thing to the problems in the USPS (or maybe UPS) addon.

That just brings so many problems to the table.

 

Avoid, like the plague.

 

I wonder why Google don't have a proper API for this?

Link to comment
Share on other sites

@@burt that is a little beyond me... lol...

 

At the end of the day below is the address - I'm not 100% sure but I presume you can develop your own code to call it (the sample I provide was a super quick google search). There are many many more examples to call this address.

 

https://www.google.com/finance/converter

Link to comment
Share on other sites

Thanks @@greasemonkey & burt. I had more than a few beers trying to fix this problem so will be great if I can get it done for a few bucks rather than going mad. I will put up a ticket one of the next days as the problem is more annoying than urgent. I want to give the exchange rate option for my customers. Great forum here, im sure I will be bak . thanks.

Link to comment
Share on other sites

Pretty much that is not good for relying upon as it does not give the "answer" in a clear format @@greasemonkey

It would take 10 minutes to knock up script to drop into admin to do it, but it would be so much better if Google allowed to append an output such as:

 

http://www.google.com/finance/converter?a=1&from=USD&to=GBP&outout=json

 

This would allow developers to write good code to get the result rather than this kludge;

 

$regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';
 

 

to get the answer....

 

Put more simply, if Google decided to change the output to (say): 

 

 

<span class="currency">12.34</span>
 

 

the code as written would break.  Which is similar to what happens each year in the U(S)PS module...

Link to comment
Share on other sites

Its a clearing localization problem. Hungarian Central Bank (MNB) is for me. There should be selectable currency info modules.

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

@@burt

 

In our country we should use MNB (Hungarian Central Bank) currency exchange rates between bank account clearing. ECB exchange rates gives only informal data. Secondary options to use own bank currencies exchange rates.
There are a lot of cases depends on self bank or money markets and national accounting rules. One option is very bound. I dont mind I could use MNB for me :)

:blink:
osCommerce based shop owner with minimal design and focused on background works. When the less is more.
Email managment with tracking pixel, package managment for shipping, stock management, warehouse managment with bar code reader, parcel shops management on 3000 pickup points without local store.

Link to comment
Share on other sites

Hi, I tested the following changes for the standard version as suggested by G Burton for the responsive version

of osCommerce 2.3.4, running on a Linux server with PHP Version 5.6.29, It worked! First delete
the rows marked with a minus sign, then add the rows marked with the plus signs. Please remove
the line numbers, minus signs and plus signs if any in the beginning of the rows.
Edit the file admin/includes/application_top.php
54 require(DIR_WS_INCLUDES . 'database_tables.php');
55
56 // Define how do we update currency exchange rates
57 - // Possible values are 'oanda' 'xe' or ''
58 - define('CURRENCY_SERVER_PRIMARY', 'oanda');
59 - define('CURRENCY_SERVER_BACKUP', 'xe');
57 +// Possible values are 'oanda' 'xe' 'fixer' or ''
58 +// fixer is the lastest added, more details at
59 + define('CURRENCY_SERVER_PRIMARY', 'fixer');
60 + define('CURRENCY_SERVER_BACKUP', '');
61 // include the database functions
62 require(DIR_WS_FUNCTIONS . 'database.php');
63
Edit the file admin/includes/functions/localization.php
NOTE!!!: I made a mistake when I edited this file. I put the ?> marker at the end of the file, and that
resulted in a blank screen at admin login, so don't add ?> at the end of this file!
37 return false;
38 }
39 }
40 - ?>
 
40 +
41 +
function quote_fixer_currency($to, $from = DEFAULT_CURRENCY) {
42 + if ($to == $from) return 1;
43 +
44 + $ch = curl_init('http://api.fixer.io/latest?base='. $from . '&symbols=' . $to);
45 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
46 + $data = curl_exec($ch);
47 + curl_close($ch);
48 +
49 +
$currencies = json_decode($data, true);
50 +
51 + if (isset($currencies['rates'][$to])) {
52 + return $currencies['rates'][$to];
53 + } else {
54 + return false;
55 + }
56 + }
57 +
tep_not_null
Replace admin side tep_not_null with shop side function of the same name.
This solves a show-stopping bug where values less than 1.0 are seen as null
(admin side).
Edit the file admin/includes/functions/general.php
326 return false;
327 }
328 } else {
329 - if ( (is_string($value) || is_int($value)) && ($value != '') && ($value != 'NULL') &&
(strlen(trim($value)) > 0)) {
329 + if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
330 return true;
331 } else {

332 return false;

 

It worked like a charm, for most currencies but not for TWD Taiwan new dollar. Why is that?

Another question: Is it time now to update to the responsive version of osCommerce?

/Bertil

Link to comment
Share on other sites

  • 2 weeks later...

So as everyone knows this started december 2016, i've read the thread, i've updated the git changes proposed by gburton, and sure enough USD now updates, however none of the other currencies will update:

 

Heres my error:

 

success.gif The exchange rate for U.S. Dollar (USD) was updated successfully via fixer.

error.gif Error: The exchange rate for Euro (EUR) was not updated via fixer. Is it a valid currency code?

error.gif Error: The exchange rate for UK Pound (GBP) was not updated via fixer. Is it a valid currency code?

error.gif Error: The exchange rate for NZ Dollar (NZD) was not updated via fixer. Is it a valid currency code?

error.gif Error: The exchange rate for Australian Dollar (AUD) was not updated via fixer. Is it a valid currency code?

 

Please help!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...