Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,245
    Plugin Contributions
    1

    Default Update currencies from timegenie.com's xml feed

    I wonder if someone can spare a few lines of code to alter admin/includes/functions/localization.php so that exchange rates are taken from timegenie's xml file rather than ecb's.

    I've added this to init_general_funcs.php

    PHP Code:
    define('CURRENCY_SERVER_PRIMARY''timegenie'); 
    and have this at the top of localization.php

    PHP Code:
    function quote_timegenie_currency($currencyCode ''$base DEFAULT_CURRENCY)
    {
      
    $requested $currencyCode;
      
    $url 'http://rss.timegenie.com/forex.xml';
      
    $data '';
      
    // check via file() ... may fail if php file Wrapper disabled.
      
    $XMLContent = @file($url);
      if (! 
    is_object($XMLContent) && function_exists('curl_init')) {
        
    // check via CURL instead.
        
    $XMLContent doCurlCurrencyRequest('POST'$url$data);
        
    $XMLContent explode("\n"$XMLContent);
      }
      
    $currencyArray = array();
      
    $rate 1;
      
    $line '';
    //  $currencyCode = '';
      
    $currencyArray['EUR'] = 1;
      foreach (
    $XMLContent as $line) {
        if (
    preg_match("/currency='([[:alpha:]]+)'/"$line$currencyCode)) {
          if (
    preg_match("/rate='([[:graph:]]+)'/"$line$rate)) {
            
    $currencyArray[$currencyCode[1]] = (float)$rate[1];
          }
        }
      }
      if (
    $requested == $base) {
        
    $rate 1;
      } else {
        
    $rate = (string)((float)$currencyArray[$requested] / $currencyArray[DEFAULT_CURRENCY]);
      }
      return 
    $rate;

    timegenie's xml format is

    Code:
    <credit>
    <!--
    In order to use this data feed from timegenie.com, you have to display the following text, or something similar, clearly visible on your web page. The text should be a link to www.timegenie.com
    -->
    <!--
    Please read more about our conditions and guidelines at http://rss.timegenie.com/free_xml_csv_feeds
    -->
    <text>Courtesy of Time Genie</text>
    <url>http://www.timegenie.com/</url>
    <title>foreign exchange rates courtesy of Time Genie</title>
    </credit>
    <data>
    <code>BSD</code>
    <description>Bahamas Dollar</description>
    <rate>1.3176</rate>
    </data>
    whereas the existing ecb's format was

    Code:
    <Cube currency="USD" rate="1.3160"/>
    I'm unsure as to how to make the necessary edits, although this has prompted me to start learning more about php.

  2. #2
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,245
    Plugin Contributions
    1

    Default Re: Update currencies from timegenie.com's xml feed

    From what I've gathered so far, it appears that I should probably not try parsing timegenie's feed using regular expression, as is the existing method for the ecb feed, due to its nested tags. Instead use an xml parser - need to look into this.

  3. #3
    Join Date
    Jan 2004
    Posts
    66,379
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Update currencies from timegenie.com's xml feed

    Why is it you want to use timegenie specifically?
    What about their terms and conditions?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,245
    Plugin Contributions
    1

    Default Re: Update currencies from timegenie.com's xml feed

    Timegenie provides a more comprehensive list of currencies than those on currently updated by zencart.

    As far as I can see, their terms are simply to provide attribution, which I don't see as a problem.
    Last edited by simon1066; 7 Feb 2012 at 11:02 AM.

  5. #5
    Join Date
    Jan 2004
    Posts
    66,379
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Update currencies from timegenie.com's xml feed

    I'll be happy to take a look, but it might be several days til I get to it.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,245
    Plugin Contributions
    1

    Default Re: Update currencies from timegenie.com's xml feed

    Thank you. Absolutely no rush - I'll obviously be updating manually in the meantime.

  7. #7
    Join Date
    Jan 2004
    Posts
    66,379
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Update currencies from timegenie.com's xml feed

    /admin/includes/functions/extra_functions/currency_timegenie.php
    Code:
    <?php
    /**
     * @package admin
     * @copyright Copyright 2003-2012 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: currencyupdate_timegenie.php 2012-02-09 drbyte $
     */
    /**
     * This allows you to extract currency exchange rates from TimeGenie
     * YOU MUST GIVE CREDIT TO THEM VIA A LINK ON YOUR SITE. THIS IS REQUIRED ACCORDING TO THEIR TERMS AND CONDITIONS:
     * Please read more about TimeGenie conditions and guidelines at http://rss.timegenie.com/foreign_exchange_rates_forex
     *
     * In order to use this data feed from timegenie.com, you have to display the following text, or something similar, clearly visible on your web page. The text should be a link to www.timegenie.com
     * Foreign exchange rates courtesy of Time Genie http://www.timegenie.com/
     */
    /**
     * EUR|Euro|1
     */
    function quote_timegenie_currency($code, $base = DEFAULT_CURRENCY)
    {
      if ($code == $base) return 1;
      $url = 'http://rss.timegenie.com/forex.txt';
      // check via file() ... may fail if php file Wrapper disabled.
      $page = @file($url);
      if ((!isset($page) || $page == '') && function_exists('curl_init')) {
        // check via cURL instead.
        $page = doCurlCurrencyRequest('GET', $url);
        $page = explode("\n", $page);
      }
      if ($page !='') {
        $currencyArray = array();
        foreach($page as $key) {
          $val = explode('|', $key);
          $currencyArray[$val[0]] = (float)$val[2];
        }
        return (string)((float)$currencyArray[$code] / $currencyArray[DEFAULT_CURRENCY]);
      }
    }
    /admin/includes/extra_configures/currency_timegenie.php
    Code:
    <?php
    /**
     * @package admin
     * @copyright Copyright 2003-2012 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: currencyupdate_timegenie.php 2012-02-09 drbyte $
     */
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    define('CURRENCY_SERVER_PRIMARY', 'TimeGenie');
    YOU MUST GIVE CREDIT TO THEM VIA A LINK ON YOUR SITE. THIS IS REQUIRED ACCORDING TO THEIR TERMS AND CONDITIONS:
    See and follow their conditions and guidelines at http://rss.timegenie.com/foreign_exchange_rates_forex
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Nov 2011
    Posts
    67
    Plugin Contributions
    0

    Default Re: Update currencies from timegenie.com's xml feed

    nice work

  9. #9
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,245
    Plugin Contributions
    1

    Default Re: Update currencies from timegenie.com's xml feed

    That's great, thanks for doing this.

  10. #10
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,245
    Plugin Contributions
    1

    Default Re: Update currencies from timegenie.com's xml feed

    The reason for my original question is that I'm carrying out an exercise to include all of the world's currencies in a zen cart site.

    In order to maximise the automatic update of exchange rates and avoiding paid subscriptions I believe the best way is to gather rates from Timegenie, Ecb & Boc. I've successfully added a 'tertiary' server reference but am having trouble with Boc's feed.

    On a 'pre-timegenie' copy of the site and setting Boc as the primary server the automatic update only gets the rate for USD and errors out on the others - picking them up from the secondary server.

    Could it be that the code for retrieving the Boc feed needs revising?

    Has anyone else been able to retrive rates from this source?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Auto Update Product Inventory From XML or CSV File?
    By yorkshiregc in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 29 Sep 2010, 02:59 PM
  2. Googlebase XML Errors From Feed
    By mtysocks in forum General Questions
    Replies: 0
    Last Post: 24 Aug 2010, 05:17 PM
  3. changing categories from Xml feed from 3rd party
    By roofus in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 12 Oct 2008, 11:04 AM
  4. Update Inventory with Suppliers XML inventory feed?
    By mafiasam in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 21 Jun 2007, 11:44 AM
  5. Xml feed from supplier
    By fats1964 in forum General Questions
    Replies: 3
    Last Post: 2 Mar 2007, 07:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR