CRELoaded Currencies

LoadedCommerce CRELoaded 6.5 has the ability to update currency rates automatically using Oanda.com and xe.net using the Update Exchange Rate button:

Unfortunately, the code uses file URL functions which are insecure and often disabled on PHP websites meaning they won't manage to contact the servers. In addition, Oanda don't want you to use the service like that so they've introduced changes which make the software malfunction sometimes.

Update to admin/includes/functions/localization.php

  function quote_oanda_currency($code, $base = DEFAULT_CURRENCY) {
    // $page = file('http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=' . $code .  
    // '&format=CSV&dest=Get+Table&sel_list=' . $base);

    $url = 'http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=' . $code .  
      '&format=CSV&dest=Get+Table&sel_list=' . $base;
    $curlSession = curl_init();
    curl_setopt($curlSession, CURLOPT_URL, $url);
    curl_setopt($curlSession, CURLOPT_HEADER, 0);
    curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curlSession, CURLOPT_TIMEOUT, 25);
    curl_setopt($curlSession, CURLOPT_USERAGENT, BROWSER_AGENT);
    curl_setopt($curlSession, CURLOPT_FOLLOWLOCATION, 1);
    
    
    $page = curl_exec($curlSession);
    $p2 = $page;

//oanda does all sort of tricks to return the results in a way 
// that breaks code that doesn't cope with it.

    $page = strip_tags(preg_replace('/\/','',$page));

    $page = str_replace(
              array('.','0','1','2','3','4','5','6','7','8','9'),
              array('.',    '0',    '1',    '2',    '3',    '4',    '5',    '6',    '7',    '8'    ,'9'),
              $page
            );


    if (preg_match('/,'.DEFAULT_CURRENCY.',([0-9\.]+),/',$page,$matches)) {
        $rate = (float)$matches[1];
        if ($rate > 0) {
          return ($rate);
        } 
    }


    $match = array();




    preg_match('/(.+),(\w{3}),([0-9.]+),([0-9.]+)/i', $page, $match);


    if (sizeof($match) > 0) {
      return $match[3];
    } else {
      return false;
    }
  }

  function quote_xe_currency($to, $from = DEFAULT_CURRENCY) {
    // $page = file('http://www.xe.net/ucc/convert.cgi?Amount=1&From=' . $from . '&To=' . $to);
    $url = 'http://www.xe.net/ucc/convert.cgi?Amount=1&From=' . $from . '&To=' . $to;
    $curlSession = curl_init();
    curl_setopt($curlSession, CURLOPT_URL, $url);
    curl_setopt($curlSession, CURLOPT_HEADER, 0);
    curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curlSession, CURLOPT_TIMEOUT, 25);
    curl_setopt($curlSession, CURLOPT_USERAGENT, BROWSER_AGENT);
    curl_setopt($curlSession, CURLOPT_FOLLOWLOCATION, 1);
    
    
    $page = curl_exec($curlSession);

    $match = array();

    preg_match('/[0-9.]+\s*' . $from . '\s*=\s*([0-9.]+)\s*' . $to . '/', implode('', $page), $match);

    if (sizeof($match) > 0) {
      return $match[1];
    } else {
      return false;
    }
  }
      

The above code replaces the two functions in admin/includes/functions/localization.php and uses CURL rather than file() to get the latest exchange rate for any particular currency. This will make the button work reliably when only a small number of currencies are in your system.

New Opportunities

Google really likes websites that present a customer with products for sale in their currency, but this is a really US viewpoint. In Europe, we have a large market but many different currencies, so Google penalises websites unless you can be a bit more dynamic in the display of currency.

Using the customer IP address, if we can look up the country that belongs to and then lookup the currency for that country, if it's a currency we support then the customer should have their website display in that currency. There's an IP to country look up https://db-ip.com/db/download/country and Maxmind.com. Graith Internet have used this to change customer currency based on IP address.

It's also possible to install 43 currencies and have them all update daily using CRON. Customers would see their own currency even if you don't take payment in that currency. All you need to do is ensure they change to your desired currency when they go through the checkout. We'll help you with that if you buy the code below.

   £20

Buy the fix for the above and code to detect country from IP address and change currency to that: only £20 GBP;


The process isn't automatic. You'll be sent an email by a real person and you can converse by email if you have problems or questions. Please allow extra time if ordering in the evening or weekend (UK time - currently 21:36pm.) If you pay for Install, there is no guarantee given about when the work can be done, but if you're unhappy, you'll get a refund.

Back

featured website
Cycle Sports

Cycle Sports

Customisation of this OSCommerce site