Jonadabe Posted February 7, 2011 Share Posted February 7, 2011 Hi there,If you want to update your store in EU with the European Central Bank Currency please see below.This was made in Prestashop svn version 1.4.0.12 (7-Feb-2011)In the folder: "classes"the file: Currency.phpGo to line 255 (I commented with // the original line. The line above is what I you should have).WARNING: Only use this if you have the EUR currency as default. public function refreshCurrency($data, $isoCodeSource, $defaultCurrency) { if ($this->iso_code != $isoCodeSource) { /* Seeking for rate in feed */ // foreach ($data->currency AS $obj) foreach ($data->Cube->Cube->Cube AS $obj) // if ($this->iso_code == strval($obj['iso_code'])) if ($this->iso_code == strval($obj['currency'])) $this->conversion_rate = round((float)($obj['rate']) / $defaultCurrency->conversion_rate, 6); } else { /* If currency is like isoCodeSource, setting it to default conversion rate */ $this->conversion_rate = round(1 / (float)($defaultCurrency->conversion_rate), 6); } $this->update(); } static public function refreshCurrenciesGetDefault($data, $isoCodeSource, $idCurrency) { $defaultCurrency = new Currency($idCurrency); /* Change defaultCurrency rate if not as currency of feed source */ if ($defaultCurrency->iso_code != $isoCodeSource) // foreach ($data->currency AS $obj) foreach ($data->Cube->Cube->Cube AS $obj) // if ($defaultCurrency->iso_code == strval($obj['iso_code'])) if ($defaultCurrency->iso_code == strval($obj['currency'])) $defaultCurrency->conversion_rate = round((float)($obj['rate']), 6); return $defaultCurrency; } static public function refreshCurrencies() { // if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml')) if (!$feed = @simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')) return Tools::displayError('Cannot parse feed!'); if (!$defaultCurrency = (int)(Configuration::get('PS_CURRENCY_DEFAULT'))) return Tools::displayError('No default currency!'); // $isoCodeSource = strval($feed->source['iso_code']); $isoCodeSource = 'EUR'; $currencies = self::getCurrencies(true); // $defaultCurrency = self::refreshCurrenciesGetDefault($feed->list, $isoCodeSource, $defaultCurrency); $defaultCurrency = self::refreshCurrenciesGetDefault($feed, $isoCodeSource, $defaultCurrency); foreach ($currencies as $currency) if ($currency->iso_code != $defaultCurrency->iso_code) // $currency->refreshCurrency($feed->list, $isoCodeSource, $defaultCurrency); $currency->refreshCurrency($feed, $isoCodeSource, $defaultCurrency); } Ooooooppss. It wasn't very easy but thats it. Log in in your control panel and go to "Payment"->"Currencies" and click "Update currency rates"In attach you have the file for Prestashop 1.4.0.12.Download it and save it to your "classes" folder in your root folder (rename your currency.php to currency.old if you want and try it first).A hug for everyone. ;-) Currency.php Link to comment Share on other sites More sharing options...
Jonadabe Posted February 8, 2011 Author Share Posted February 8, 2011 Hi there again,For the Prestashop version 1.3.6.0 like above:WARNING: Use this only if your default currency is EUR.Go to your "classes" folder on your root, and then open "currency.php". On line 188 you should have this (the original line I have commented it with // and above is my line): public function refreshCurrency($data, $isoCodeSource, $defaultCurrency) { if ($this->iso_code != $isoCodeSource) { /* Seeking for rate in feed */ // foreach ($data->currency AS $obj) foreach ($data->Cube->Cube->Cube AS $obj) // if ($this->iso_code == strval($obj['iso_code'])) if ($this->iso_code == strval($obj['currency'])) $this->conversion_rate = round(floatval($obj['rate']) / $defaultCurrency->conversion_rate, 6); } else { /* If currency is like isoCodeSource, setting it to default conversion rate */ $this->conversion_rate = round(1 / floatval($defaultCurrency->conversion_rate), 6); } $this->update(); } static public function refreshCurrenciesGetDefault($data, $isoCodeSource, $idCurrency) { $defaultCurrency = new Currency($idCurrency); /* Change defaultCurrency rate if not as currency of feed source */ if ($defaultCurrency->iso_code != $isoCodeSource) // foreach ($data->currency AS $obj) foreach ($data->Cube->Cube->Cube AS $obj) // if ($defaultCurrency->iso_code == strval($obj['iso_code'])) if ($defaultCurrency->iso_code == strval($obj['currency'])) $defaultCurrency->conversion_rate = round(floatval($obj['rate']), 6); return $defaultCurrency; } static public function refreshCurrencies() { // if (!$feed = @simplexml_load_file('http://www.prestashop.com/xml/currencies.xml')) if (!$feed = @simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')) return Tools::displayError('Cannot parse feed!'); if (!$defaultCurrency = intval(Configuration::get('PS_CURRENCY_DEFAULT'))) return Tools::displayError('No default currency!'); // $isoCodeSource = strval($feed->source['iso_code']); $isoCodeSource = 'EUR'; $currencies = self::getCurrencies(true); // $defaultCurrency = self::refreshCurrenciesGetDefault($feed->list, $isoCodeSource, $defaultCurrency); $defaultCurrency = self::refreshCurrenciesGetDefault($feed, $isoCodeSource, $defaultCurrency); foreach ($currencies as $currency) if ($currency->iso_code != $defaultCurrency->iso_code) // $currency->refreshCurrency($feed->list, $isoCodeSource, $defaultCurrency); $currency->refreshCurrency($feed, $isoCodeSource, $defaultCurrency); } The code is the same. The difference is that in one file is at line 188 and the PS 1.4 is in line 255.Attached is the file for Prestashop 1.3.6.0 that you can download and put in /classes folder (rename your other file to currency.old if you want).A hug for everyone! Currency.php 1 Link to comment Share on other sites More sharing options...
mecollectibles Posted February 14, 2011 Share Posted February 14, 2011 what about this version:Version 1.3.2.3My website has Euro as the main currency: http://sodamalt.com & I wonder how to get updated changes of the rates. Link to comment Share on other sites More sharing options...
Fabrice Posted May 7, 2011 Share Posted May 7, 2011 GREAT !this also works for PS 1.2.5 :-) very nice... !!! thanks a lot Hug!!!does anyone know how we can create a cron for that, so that we don't need to launch it manualy each day ? Link to comment Share on other sites More sharing options...
Fabrice Posted May 7, 2011 Share Posted May 7, 2011 yes, of course !!thank you guys ! :-)http://www.prestashop.com/forums/viewthread/75337/P15/configuring___using_prestashop/solved_can_currency_auto_update_without_manually_click_on_update_currencies_daily Link to comment Share on other sites More sharing options...
patax Posted June 30, 2011 Share Posted June 30, 2011 Thanks for the hug but many thanks for this currency.phpI use it on PS1.4.3 it works. Thanks again.Patax Hi there,If you want to update your store in EU with the European Central Bank Currency please see below.This was made in Prestashop svn version 1.4.0.12 (7-Feb-2011)In the folder: "classes"the file: Currency.phpGo to line 255 (I commented with // the original line. The line above is what I you should have).WARNING: Only use this if you have the EUR currency as default.Ooooooppss. It wasn't very easy but thats it. Log in in your control panel and go to "Payment"->"Currencies" and click "Update currency rates"In attach you have the file for Prestashop 1.4.0.12.Download it and save it to your "classes" folder in your root folder (rename your currency.php to currency.old if you want and try it first).A hug for everyone. ;-) Link to comment Share on other sites More sharing options...
Jonadabe Posted August 5, 2011 Author Share Posted August 5, 2011 Hi there again, If you still want to update your store in EU with the European Central Bank Currency please see below. This was made in Prestashop 1.4.7.0 (17-Mar-2012) Folder: classes File: Currency.php Go to line 262 (I commented with // the original line. The line above is what you should have). WARNING: Only use this if you have the EUR currency as default. public function refreshCurrency($data, $isoCodeSource, $defaultCurrency) { // fetch the conversion rate of the default currency $conversion_rate = 1; if ($defaultCurrency->iso_code != $isoCodeSource) { // foreach ($data->currency AS $currency) foreach ($data->Cube->Cube->Cube AS $currency) // if ($currency['iso_code'] == $defaultCurrency->iso_code) if ($currency['currency'] == $defaultCurrency->iso_code) { $conversion_rate = round((float)$currency['rate'], 6); break; } } if ($defaultCurrency->iso_code == $this->iso_code) $this->conversion_rate = 1; else { if ($this->iso_code == $isoCodeSource) $rate = 1; else { // foreach ($data->currency AS $obj) foreach ($data->Cube->Cube->Cube AS $obj) // if ($this->iso_code == strval($obj['iso_code'])) if ($this->iso_code == strval($obj['currency'])) { $rate = (float) $obj['rate']; break; } } $this->conversion_rate = round($rate / $conversion_rate, 6); } $this->update(); } /** * @deprecated **/ public static function refreshCurrenciesGetDefault($data, $isoCodeSource, $idCurrency) { Tools::displayAsDeprecated(); $defaultCurrency = new Currency($idCurrency); /* Change defaultCurrency rate if not as currency of feed source */ if ($defaultCurrency->iso_code != $isoCodeSource) foreach ($data->currency AS $obj) if ($defaultCurrency->iso_code == strval($obj['iso_code'])) $defaultCurrency->conversion_rate = round((float)($obj['rate']), 6); return $defaultCurrency; } public static function getDefaultCurrency() { $id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT'); if ($id_currency == 0) return false; return new Currency($id_currency); } public static function refreshCurrencies() { // Parse // if (!$feed = Tools::simplexml_load_file('http://www.prestashop.com/xml/currencies.xml')) if (!$feed = Tools::simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')) return Tools::displayError('Cannot parse feed.'); // Default feed currency (EUR) // $isoCodeSource = strval($feed->source['iso_code']); $isoCodeSource = 'EUR'; if (!$default_currency = self::getDefaultCurrency()) return Tools::displayError('No default currency'); $currencies = self::getCurrencies(true); foreach ($currencies as $currency) // $currency->refreshCurrency($feed->list, $isoCodeSource, $default_currency); $currency->refreshCurrency($feed, $isoCodeSource, $default_currency); } If you want automatic update, you can create a cron job. (See my post from 17-Mar-2012) First you create a file in your prestashop folder, called cron.php (Thanks Rocky. The original post is here.) with this: <?php include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/classes/Currency.php'); if (isset($_GET['secure_key']) AND $_GET['secure_key'] === 'password') Currency::refreshCurrencies(); ?> NOTE: change 'password' to whatever you like. Ex: 'asdERWE#$343344' Then try it first by calling the page, like this: http://www.yourshop....asdERWE#$343344 If it works, then create a cron job in your cpanel (or other): For every day, this: 0 0 * * * The command should be like this: php /home3/myaccountname/public_html/myprestashopfolder/cron.php If you have any doubts, just tell me! ;-) See you and enjoy! Currency.php Link to comment Share on other sites More sharing options...
Jonadabe Posted August 8, 2011 Author Share Posted August 8, 2011 Hi there to everyone, This is no more needed because the rates are identical (Prestashop changed). Check the rates now, they are the same: Prestashop currency rates and the rates a European Central Bank at: European Central Bank rates Prestashop team told me they will be working on a cron job for this. Thanks guys! EDIT: in your admin folder the file is cron_currency_rates.php (See my post here from 17-Mar-2012) Link to comment Share on other sites More sharing options...
Jevgen Posted March 17, 2012 Share Posted March 17, 2012 for automatic update create a file in the root directory cron.php with code: <?php include(dirname(__FILE__).'/config/config.inc.php'); include(dirname(__FILE__).'/classes/Currency.php'); if (isset($_GET['secure_key']) AND $_GET['secure_key'] === 'password') Currency::refreshCurrencies(); ?> change password as you like, for exampe 23Ab09Ce etc. After that in your server control panel create a crontab with name for example Currency and use file URL http://www.yoursite....php?secure_key=password And set the time you want for automatic start of this file (all weekdays, all months, all days, chose the hours and minutes). NB! Rates are usually updated by 3 p.m. C.E.T by Europen Central Bank Link to comment Share on other sites More sharing options...
Jonadabe Posted March 17, 2012 Author Share Posted March 17, 2012 Hi everyone, Thanks Jevgen but you don't need this anymore in version 1.4.7.0. You have a file called cron_currency_rates.php in your admin folder that has that configuration. If you want to see the link, go to your Backoffice -> Payment -> Currencies and a the bottom of the page you can see the link in "Automatically update currency rates". Link to comment Share on other sites More sharing options...
Jevgen Posted March 18, 2012 Share Posted March 18, 2012 Thanks Jevgen but you don't need this anymore in version 1.4.7.0. You have a file called cron_currency_rates.php in your admin folder that has that configuration. If you want to see the link, go to your Backoffice -> Payment -> Currencies and a the bottom of the page you can see the link in "Automatically update currency rates". yeap ) but I have 1.3.6.0 )))))) Link to comment Share on other sites More sharing options...
Jonadabe Posted March 19, 2012 Author Share Posted March 19, 2012 Ok. ;-) Link to comment Share on other sites More sharing options...
SebeyTRF Posted March 24, 2012 Share Posted March 24, 2012 Hi guys, As the currency market is quiet volatile and it's hard to find a instant update feed, I would like to include in the update file a fonctions that add +0.009 to all currency. So it will balance the small differences that can be founded. Anybody know where I can add this ? Link to comment Share on other sites More sharing options...
utopiasl Posted September 29, 2012 Share Posted September 29, 2012 I have expanded Jonadabe's solution, and wanted to share this for Prestashop v1.4.7. Where as his solution only works for EUR as the default currency, my solution will work for any currency as default. /** * Refresh the currency conversion rate * The XML file define conversion rate for each from a default currency ($isoCodeSource). * * @param $data XML content which contains all the conversion rates * @param $isoCodeSource The default currency used in the XML file * @param $defaultCurrency The default currency object */ public function refreshCurrency($data, $isoCodeSource, $defaultCurrency) { // fetch the conversion rate of the default currency $conversion_rate = 1; if ($defaultCurrency->iso_code != $isoCodeSource) { //foreach ($data->currency AS $currency) foreach ($data->Cube AS $currency) //if ($currency['iso_code'] == $defaultCurrency->iso_code) if ($currency['currency'] == $defaultCurrency->iso_code) { $conversion_rate = round((float)$currency['rate'], 6); break; } } if ($defaultCurrency->iso_code == $this->iso_code) $this->conversion_rate = 1; else { if ($this->iso_code == $isoCodeSource) $rate = 1; else { //foreach ($data->currency AS $obj) foreach ($data->Cube AS $obj) // if ($this->iso_code == strval($obj['iso_code'])) if ($this->iso_code == strval($obj['currency'])) { $rate = (float) $obj['rate']; break; } } $this->conversion_rate = round($rate / $conversion_rate, 6); } $this->update(); } /** * @deprecated **/ public static function refreshCurrenciesGetDefault($data, $isoCodeSource, $idCurrency) { Tools::displayAsDeprecated(); $defaultCurrency = new Currency($idCurrency); /* Change defaultCurrency rate if not as currency of feed source */ if ($defaultCurrency->iso_code != $isoCodeSource) //foreach ($data->currency AS $obj) foreach ($data->Cube AS $obj) //if ($defaultCurrency->iso_code == strval($obj['iso_code'])) if ($defaultCurrency->iso_code == strval($obj['currency'])) $defaultCurrency->conversion_rate = round((float)($obj['rate']), 6); return $defaultCurrency; } public static function getDefaultCurrency() { $id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT'); if ($id_currency == 0) return false; return new Currency($id_currency); } public static function refreshCurrencies() { // Parse // if (!$feed = Tools::simplexml_load_file('http://www.prestashop.com/xml/currencies.xml')) if (!$feed = Tools::simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')) return Tools::displayError('Cannot parse feed.'); // Default feed currency (EUR) // $isoCodeSource = strval($feed->source['iso_code']); $isoCodeSource = 'EUR'; if (!$default_currency = self::getDefaultCurrency()) return Tools::displayError('No default currency'); $currencies = self::getCurrencies(true); foreach ($currencies as $currency) // $currency->refreshCurrency($feed->list, $isoCodeSource, $default_currency); $currency->refreshCurrency($feed->Cube[0]->Cube[0], $isoCodeSource, $default_currency); } @SebeyTRF To achieve this functionality just change the line $this->conversion_rate = round($rate / $conversion_rate, 6); with $this->conversion_rate = round($rate * 1.009 / $conversion_rate, 6); //Adding 0.009 to all currencies as requested by [b]SebeyTRF[/b] 1 Link to comment Share on other sites More sharing options...
mehnihma Posted February 23, 2013 Share Posted February 23, 2013 Hi Can be this done in PS 1.5? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now