Post by hm2k » Tue Jul 01, 2008 5:54 pm

OpenCart Currency Updater v0.1 by HM2K

I decided to do this because someone was offering this on the forum at a cost, I needed this function for myself anyway, it took me about half an hour to code.

If you find this useful please donate to paypal@hm2k.org

I called the file "update_currency.php".

Enjoy...

Code: Select all

<?php

//OpenCart Currency Updater v0.1 by HM2K

//If you find this useful please donate to paypal@hm2k.org

// Configuration
require('config.php');

// Locator
include(DIR_LIBRARY . 'locator.php');
$locator =& new Locator();

// Config
$config =& $locator->get('config');

// Database
$database =& $locator->get('database');

// Settings
$settings = $database->getRows("select * from setting where type = 'catalog' or type = 'global'");

foreach ($settings as $setting) {
	$config->set($setting['key'], $setting['value']);
}

// Request
$request =& $locator->get('request');

//Rest Of Code

$default=$config->get('config_currency');

echo "Default code is $default<br>\n";

$sql = "select currency_id, title, code, value, date_modified from currency";
$sql .= " order by title asc";

$results = $database->getRows($sql);

foreach ($results as $result) {
	$id=$result['currency_id'];
	$code=$result['code'];
	$value=$result['value'];
	$new=ucc(1,$default,$code);
	echo "$code = $value => $new <br>\n";
	$sql = "update currency set value = '?', date_modified = now() where currency_id = '?'";
	$database->query($database->parse($sql, $new, $id));
}

function ucc ($amount,$from,$to) {
	$url='http://www.xe.com/ucc/convert.cgi?Amount=%s&From=%s&To=%s';
	$url=sprintf($url,$amount,$from,$to);
	ini_set('user_agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.12) Gecko/20050919 Firefox/1.0');
	$c=file_get_contents($url);
	$c=strip_tags($c);
	preg_match("/1 $from = (.+?) $to/s",$c,$matches);
	return $matches[1];
}

?>

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by bruce » Tue Jul 01, 2008 9:03 pm

Congratulations hm2k!
  • The existing contribution for sale was $10 per copy.
  • You clearly don't value your own time very highly...
  • You have provided nothing new with this post...
  • You have probably alienated a community member of much longer standing than yourself who has made several useful contributions in the past (some for free)
  • And after all that, you have the cheek to ask for payment for yourself as well.
I had hoped for more when Daniel handed over forum moderation so that he could concentrate on development but I have to say that your presence on the forums is and has been, at best, a tolerated irritation.

Oh, and before you decide to use your powers as forum Administrator to delete this post, as you did the last one I put up that criticised you, note that a copy is already going by email to Daniel.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by david.gilbert » Tue Jul 01, 2008 9:07 pm

Thanks Bruce!

If I were to say what I really feel right now, hm2k would feel it within his powers to ban me forever !

And yes, the opencart community will have to face the fact I'm now reluctant to release anything free or commercial  and my many mods will not be available via the forums anymore. As a true professional I will cop it on the chin and write it off as a bad loss, however take caution to future contributions and not publicly release anything in this forum.

In addition to this, All of my current contributions are going to be removed from this forum. If you require help regarding one of my contributions or would like to obtain a contribution, your welcome to PM me.

It's a shame when other developers (not mentioning any names) feel they have the right to undermine the work of others and their rights to make it worth while them spending the time to make such contributions.

Furthermore, open source projects rely on a strong balance of free vs. commercial. Commercial contributions allow developers to sustain development on other free and core sections of a project rather than concentrate on earning a wage from an employer. While $10 isn't a lot, it all helps. Without supplemental income, developers such as myself cannot dedicate as much quality time to the project. A concept that hm2k seems to not comprehend.

my 2 cents

-Dave
Last edited by david.gilbert on Tue Jul 01, 2008 9:36 pm, edited 1 time in total.

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by hm2k » Wed Jul 02, 2008 12:15 am

Daniel has always encouraged people to offer things as open source, and accept donations, instead of demanding payments.

I'm simply setting an example.

Take it or leave it.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Daniel » Wed Jul 02, 2008 4:08 am

This is not communist china. You can say what you want on the forums and you won't get banned.

I wanted to have a forum where people can offer their work open source and commercial. I can see this problem happening many times if the project gets bigger. I think it might be better to just offer open source contributions in the forum. People will still be able to offer their services and scripts via their forum signatures.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Luvz2drv » Wed Jul 02, 2008 10:06 am

we -CAN- express wow i too and have rec'd a few pms about having posts deleted.

oh well,  thats life

more info posted in mod section when i have time
Jonathon

Global Moderator

Posts

Joined
Fri Mar 21, 2008 10:58 am

Post by Daniel » Thu Jul 03, 2008 12:27 am

Ok I have discussed with hm2k and there will not be any more posts being deleted. They maybe moved to the relevent section though.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by sereast » Sat Jul 05, 2008 12:19 am

I don't want to be sucked into the arguements, just want to implement this function, where in opencart and exactly what do you do with the file?

Sereast

Newbie

Posts

Joined
Sun Apr 13, 2008 6:42 am

Post by Luvz2drv » Sat Jul 05, 2008 1:48 am

after review of this mod - i recommend it be removed.

xe site does not allow such actions to there data.

except from the source file your looking at to get your data


1.00 AFN
=
1.34069 DZD


as a mod note to all who choose to use this...  you could be liable for using it.

for more info  i encourage all to visit http://www.xe.com/legal/

Global Moderator

Posts

Joined
Fri Mar 21, 2008 10:58 am

Post by nde » Sat Jul 05, 2008 3:39 am

haha, oh the drama...


hm2k, if you're interested, here are a few other data sources.


for Euro values, the European Central Bank provides free rates and various XML feeds:
http://www.ecb.eu/stats/exchange/eurofx ... ex.en.html

for US$, the Federal Reserve provides something similar:
http://www.federalreserve.gov/releases/h10/update/


other links of interest:
http://xurrency.com/
http://www.bloomberg.com/markets/curren ... ncies.html
http://www.newyorkfed.org/markets/fxrates/noon.cfm

nde
New member

Posts

Joined
Sat Jun 30, 2007 7:32 am

Post by Luvz2drv » Sat Jul 05, 2008 7:01 am

its not drama.. its copywrite. and what you can and cannot do with other sites information.

We as a community do not want issues of that i am sure.  You have to look at the larger picture.

Global Moderator

Posts

Joined
Fri Mar 21, 2008 10:58 am

Post by Qphoria » Tue Jul 22, 2008 5:00 am

I too must express some disappointment with the excessive costs of some paid contributions. Authorize.net AIM in particular. One thing that makes some Open source carts like osCommerce and Zen-Cart flourish is the community giving back to its community. If you want to charge for contribs, then use a pay cart and follow suit. But a community driven cart can only grow when its community gives back, and not necessarily in money, but code.

This is all, of course, IMHO

I am looking forward to creating some contribs for OpenCart, but rest assured they will be completely donation based. My first step will likely be an Authorize.net AIM module.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by bruce » Tue Jul 22, 2008 11:10 am

Hi Qphoria,

I am reluctantly compelled to reply, especially since I am the provider of the Authorize.net AIM module.  :)

The cost of this module is not excessive when you consider
  • the cost of an ssl certificate ( a mandatory requirement when using Authorize.net AIM)
  • the cost of development and testing
  • the fact that installation and support is included
  • professional software development rates are around USD$160 per hour
Those who have purchased this payment extension are not unhappy with the bargain they have struck. Just the opposite in fact. Further work has come after several of these sales.

Finally, I also should point out that I am not part of the OpenCart development team. My contribution to the community has been in the form of support. I am a huge supporter of open source software and opencart is great... and free. However, that does not mean that services and extensions must also be free. Everyone who uses a shopping cart is trying to make some money and those who support that effort are entitled to do the same.

cheers

Bruce

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by activeebiz » Tue Jul 22, 2008 11:33 am

Open Source does not necessarily mean that all is free of cost.

This is from the Gnu website:
The word “free” has two legitimate general meanings; it can refer either to freedom or to price. When we speak of “free software”, we're talking about freedom, not price. (Think of “free speech”, not “free beer”.) Specifically, it means that a user is free to run the program, change the program, and redistribute the program with or without changes.

Read more here: http://www.gnu.org/philosophy/selling.html

Newbie

Posts

Joined
Mon Jun 09, 2008 2:10 am

Post by Qphoria » Tue Jul 22, 2008 11:48 am

bruce wrote: Hi Qphoria,

I am reluctantly compelled to reply, especially since I am the provider of the Authorize.net AIM module.  :)

The cost of this module is not excessive when you consider
  • the cost of an ssl certificate ( a mandatory requirement when using Authorize.net AIM)
  • the cost of development and testing
  • the fact that installation and support is included
  • professional software development rates are around USD$160 per hour
Those who have purchased this payment extension are not unhappy with the bargain they have struck. Just the opposite in fact. Further work has come after several of these sales.

Finally, I also should point out that I am not part of the OpenCart development team. My contribution to the community has been in the form of support. I am a huge supporter of open source software and opencart is great... and free. However, that does not mean that services and extensions must also be free. Everyone who uses a shopping cart is trying to make some money and those who support that effort are entitled to do the same.

cheers

Bruce
I fully understand where you are coming from, as I have been a part of the Zen-Cart community for nearly 5 years, I've created a few contribs myself. So I know it can be quite a bit of work.. But a few counter points:
- SharedSSL is free. But even a GoDaddy one with coupon is like $19
- Development and testing really is nothing but your time. Its not like its Windows XP.. its an extension of existing code
- If coded correctly, installation should be as easy as uploading some files and running a sql file. Support is answering a few questions in the forums, and if you don't answer them, other forum members usually can help.
- Its only a payment gateway.. they are a dime-a-dozen and the API interface directions are on the Authorize.net site. Not to mention that there are tons of other carts out there that offer it and plenty of reference code.

I speak only from my personal experience with Zen-Cart community and I'm not here to attack or judge, and I'm not even familiar with OpenCart code yet so it might be harder than it was in Zen-Cart. And I'm not saying that your code isn't great and didn't take you a bunch of time. I'm not in it to run anyone out of business, but I believe that the community makes the biggest impact for this type of product... the more robust it is without pay, the more people that will learn and use it, therefore more modules and support, and its good for everyone. The community created contribs for ZC are what make it so successful.

And in all honesty, Auth.net is the most popular CC gateway in USA, and an ecommerce solution should probably have one included in the core code anyway.

But still i have no qualms about you selling your code, you worked hard for it and it might be an important part of your income.. I on the other hand code for hobby and have no need to charge. I also know enough coding to avoid paying for something that I can create in at least a rudimentary way. At the end its up to the customer to decide whether he wants the pay for the support, or just take the budget version and run with it. It's Microsoft vs Linux.  ;)
Last edited by Qphoria on Tue Jul 22, 2008 6:57 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by ogun » Sun Aug 17, 2008 10:45 am

started noodling at the idea of a currency converter before i realised the commercial add-on was now free. tried using rss from currencysource.com but the rss was up and down like a dock whore's knickers so gave up on it as unreliable and used the ECB one from this thread.

seems to work ok on localhost, posted in case it's of use to anyone else.

noticed in another thread that bruce had said to let the payment gateway handle conversion and only provide foreign prices as a guide - which i heartily agree with.

Code: Select all

<?php
/*
	Another OpenCart Currency Updater v0.1, by Ogun.
	Derived from 'OpenCart Currency Updater v0.1 by HM2Kv'
	If you find this useful please donate to paypal@hm2k.org
*/

// Reinvent wheel
function array_sample($array,$key) {
	$result = array();
	foreach($array as $sample) {
		if(isset($sample[$key])) $result[] = $sample[$key];
	}
	return $result;
}
function array_remove(&$array,$key) {
	$result = $array[$key];
	unset($array[$key]);
	return $result;
}

// Locator
$locator =& new Locator();

// Database
$database =& $locator->get('database');

/*
	OC uses a reserved word for a column name, so put it in backticks.
	TODO: Check the other tables and have a look at database.php.
*/
// Default currency
$default = $database->getRow("
	SELECT value
	FROM setting
	WHERE `key` = 'config_currency'
");
$default = $default['value'];

$codes = $database->getRows("
	SELECT code, value
	FROM currency
	ORDER BY title ASC
");
$codes = array_sample($codes,'code');

// Grab the XML feed from the ECB. Not worth XML'ing, just explode.
$tmp = file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
$tmp = explode('<Cube currency=',$tmp);
unset($tmp[0]);

// The ECB file is in euros, so they won't be in the list.
$rates = array('EUR' => 1);
// Only include the rate if it's in the list of required currency codes.
foreach($tmp as $rate) {
	$rate = explode("'",$rate);
	if(in_array($rate[1],$codes)) $rates[$rate[1]] = $rate[3];
}

/*
	What does OC do for errors/exceptions?
*/

// Bomb out if the default currency isn't in the ECB'd list.
if(!in_array($default,array_keys($rates))) die("ERROR: No data for $default.");
// Remove the default currency from the ECB'd list (Assuming it'll always be 1).
else $default_value = array_remove($rates,$default);

// If euros aren't the default currency, we'll need to convert them (and everything else).
if($default != 'EUR') {
	foreach($rates as $key => $value) $rates[$key] = 1/$default_value * $value;
	$rates['EUR'] = 1/$default_value;
}

// Update the database
foreach($rates as $key => $value) {
	$database->query("
		UPDATE currency
		SET value = $value, date_modified = NOW()
		WHERE code = '$key'
	");
}

echo '<pre>' . count($rates) . ' record(s) updated.<br />';
print_r($rates);
echo '</pre>';

?>
Last edited by ogun on Sun Aug 17, 2008 12:05 pm, edited 1 time in total.

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am

Post by Qphoria » Sun Aug 17, 2008 11:08 am

ogun wrote: but the rss was up and down like a dock whore's knickers
ROFL!  ;D :D

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by david.gilbert » Tue Aug 19, 2008 8:29 pm

ogun,

The reason it will be working on localhost and not a live webserver is because alot of websites block any requests direct from other servers to prevent leeching.

You can fool these sites into thnking your using a web browser to access their code using a similar snipplet to the code below.

Code: Select all

$query,
         $correct,
         $m_host = "www.website.com/content.xml";

     function file_get_contents($url)
      {
      $out = "GET /$url HTTP/1.1\r\n";
      $out .= "Host: {$this->m_host}\r\n";
      $out .= "User-Agent: Mozilla 4.0\r\n";
      $out .= "Connection: close\r\n\r\n";

    $h = fsockopen($this->m_host,80);
    fwrite($h,$out);
    for($a = 0,$r = '';!$a;)
    {
       $b = fread($h,8192);
       $r .= $b;
       $a = (($b=='') ? 1 : 0);
    }
    fclose($h);
    return $r;
  }

$xmldata = $this->file_get_contents($this->m_url);
             
Then all you need to do is parse the $xmldata to get your variables.

Professional Website Services - http://www.davidmgilbert.com/


User avatar
Active Member

Posts

Joined
Sun Jan 06, 2008 5:02 pm
Location - Mount Compass, South Australia

Post by hm2k » Tue Aug 19, 2008 9:24 pm

You're probably best using the yahoo feed if you don't want to use xe.com

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by ogun » Tue Aug 19, 2008 9:46 pm

david.gilbert wrote: The reason it will be working on localhost and not a live webserver..
sorry, i should've chosen my words more carefully. i mentioned localhost to illustrate that i hadn't properly tested the script and that it was just a thing to work from if anyone was interested. hm2k's original post did include emulating a user agent, i'd just chopped that bit out.

Active Member

Posts

Joined
Tue Aug 14, 2007 6:04 am
Who is online

Users browsing this forum: No registered users and 2 guests