Jump to content

[SOLVED] Can currency auto update without manually click on "update currencies" daily?


Recommended Posts

No, PrestaShop doesn't have the option to automatically update currencies. You'd have to create a crob job that calls the update function. Create a file similiar to modules/followup/cron.php, but call Currency::refreshCurrencies() instead of the followup module.

Link to comment
Share on other sites

So sorry Rocky, I can't get clearly what you mean? Did you mean we need to create a new module call update function? Or we need to create a cron job at our cpanel? Or we need to create one file similar to Create a file similiar to modules/followup/cron.php but the cron.php file we need to modify the :
$secureKey = Configuration::get into $secureKey = Currency::refreshCurrencies()
and name this new file as update function?

So sorry Rocky, I'm blind in programming. I just try my best to did it. Can you guide me the way how to do it?


Thanks for your warm helpful.

Link to comment
Share on other sites

I'll try to make it easier. Create a file called cron.php in the root directory of PrestaShop with the following 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' to a password only you know that that only you can update your currency rates. Then create a cron job in your cPanel with the URL http://www.yoursite.com/cron.php?secure_key=password where password is the password you entered in cron.php.

  • Like 1
Link to comment
Share on other sites

Hi Rocky, thanks for your good information. But after I create a cron.php and cron job at my Cpanel, it seem nothing for currencies update and we still need to manually login our admin to update a currency for a latest rate. Is it we need to change a Currency::refreshCurrencies(); to Currency::updateCurrencies(); ?? Or we need to modify admincurrencies.php at our admin folder?

Link to comment
Share on other sites

No, refreshCurrencies() is the right function. Modifying AdminCurrencies.php won't make a difference. If clicking on the "Update currencies" button on the Payment > Currencies tab works, then the cron job should also work. Make sure that the cron job is actually executing.

Here's what happens when the "Update currencies" button is clicked:

elseif (Tools::isSubmit('submitExchangesRates'))
{
   if (!$this->_errors[] = Currency::refreshCurrencies())
       Tools::redirectAdmin($currentIndex.'&conf=6'.'&token;='.$this->token);
}



It is just a simple function call.

Link to comment
Share on other sites

I had try it again with notification mail when a cron job is done but the notification I receive is /bin/sh: http://www.mydomain.com/cron.php?secure_key=update: No such file or directory. The password "update" is the same with the password I create in cron.php. But I try to visit my back office, the currencies seem still remain the same rate as yesterday. I suspect is it related with the password I create in "cron.php" file at root directory because I seen the sign in "cron.php" password is woth this "==='update' " but the cron job at cpanel I put is "=update". Is it a cause ?
Thanks.

Link to comment
Share on other sites

No, that won't make a difference. You should have one = in the query string and three = in the cron.php (or maybe two = would work). Try temporarily taking out the if statement. That should let you use it without a password. If that works, then you know the password is causing the problem.

Link to comment
Share on other sites

PianetaModellismo, your currencies can automatically update by using a cron job? How you make it because I had try a several days but it see nothing to my currencies update and I need to login back office manually update. Can share your result? Thanks.

Link to comment
Share on other sites

  • 2 weeks later...
I'll try to make it easier. Create a file called cron.php in the root directory of PrestaShop with the following 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' to a password only you know that that only you can update your currency rates. Then create a cron job in your cPanel with the URL http://www.yoursite.com/cron.php?secure_key=password where password is the password you entered in cron.php.




Working GREAT !
Link to comment
Share on other sites

  • 4 weeks later...
  • 3 months later...
Thanks Patanock. I had try it in few days and I saw the result. I try with "wget", it work for me.
Rocky, thanks for your warm helpful too.

Thanks you for your all.


OK it doesn!t work for me but I have the same problem as Phuah. I added cronjob in my Cpanel- On the e-mail I get this error:
/bin/sh: http://www.mysite.net/cron.php?secure_key=password: No such file or directory


I read that Phuah has the solution but I can't see how you solved it. What is the "wget"????

What do I have to do exactly?. thanks in advance
Link to comment
Share on other sites

I've seen people having this same problem, I have come up with a kind of solution, if you'd want to give it a try just drop a line

regards

Hugh

p.s. it works for cpanel cron jobs


Hi ezakimak!

I consulted with my webhosting support. They always say the same solution and I tried everything. It just doesn't work.
I tried this:
php -q /home/usern5/public_html/scripts/testrun.php

this:
lynx -dump http://domain.com/folder/script.php?dl=file

and this:
curl http://domain.com/folder/script.php?dl=file

I gave 755 permission to the file on my server but no success.
Link to comment
Share on other sites

This is what I got from the hosting support lately:

From review of the cron logs, your script looks to be running without issue. Server side, everything is fine. You will need to check your script to find out why it is emailing blank content.

Also, PHP is located at /usr/local/bin/php

Link to comment
Share on other sites

First of all create a directory in your shops root directory and call it cronjobs, then upload the file attached in this email to that directory and in your cpanel create a cron job with this command:

/usr/bin/php -q /home/youruser/public_html/yourshoprootdir/cronjobs/cronjobs.php --secure_key=123 --type=currency

replace 123 with your password just make sure to change the program to check against that password

hope this help


Hugh

ps. in my isntallation php is located in /usr/bin/ so make sure whre your php is installed in your server

cronjobs.php

  • Like 1
Link to comment
Share on other sites

First of all create a directory in your shops root directory and call it cronjobs, then upload the file attached in this email to that directory and in your cpanel create a cron job with this command:

/usr/bin/php -q /home/youruser/public_html/yourshoprootdir/cronjobs/cronjobs.php --secure_key=123 --type=currency

replace 123 with your password just make sure to change the program to check against that password

hope this help


Hugh

ps. in my isntallation php is located in /usr/bin/ so make sure whre your php is installed in your server


First of all thank you Ezakimak. It just gives me this error in the mail: ..sorry you provided bad arguments..
Than what can be the problem?
Link to comment
Share on other sites

did you change the secure_key value ? if so , did you also changed the program to check for that value ?

regards

Hugh


Hi
This is what I did

I changed cronjobs.php what you uploaded within line 7
if (isset($result['secure_key']) AND $result['secure_key'] === 'mypassword')



I also attached an image how I added the cronjob in my webhosting cPanel.

42006_JQdz9gh4D3A9P2NXNJ8P_t

Link to comment
Share on other sites

in your cpanel you wote -secure_key=xxxx -type=yyy and it must be --secure_key=xxxx --type=yyy


Hi I tried six different '–' none of them is working. Maybe give me the ALT code of this '-' to try. I don't know it's just so upsetting.
Link to comment
Share on other sites

Hi , there is nothing special with those --, they are just two consecutive minus signs.


Yessss! Success. Thank you very much EZAKIMAK. I hate this tiny characters that's what causing me hard time in programming too.
by the way you did this cronjob.php function?
Link to comment
Share on other sites

  • 1 month later...
Are the currencies automatically updated in the newest PS version (1.4.1)?

Housy


I guess they aren't, because you have to update them manually with the update currency rate function within admin area.
Link to comment
Share on other sites

First of all create a directory in your shops root directory and call it cronjobs, then upload the file attached in this email to that directory and in your cpanel create a cron job with this command:

/usr/bin/php -q /home/youruser/public_html/yourshoprootdir/cronjobs/cronjobs.php --secure_key=123 --type=currency

replace 123 with your password just make sure to change the program to check against that password

hope this help


Hugh

ps. in my isntallation php is located in /usr/bin/ so make sure whre your php is installed in your server


Your method is way way too complicated.

Just use file, that was recommended by Rocky and the command below:


Thats it, very simple and it works like a charm =)

Cheers, Housy
Link to comment
Share on other sites

  • 3 weeks later...

I have copy the code above how I know that the following code working.
I have prestashop 1.4.1 and my cron is there http://www.jolie-et-julian.com/cronjobs/cron.php?secure_key=123

<?php

include(dirname(__FILE__).'/../config/config.inc.php');
include(dirname(__FILE__).'/../classes/Currency.php');

if (isset($_GET['secure_key']) AND $_GET['secure_key'] === '123')
  Currency::refreshCurrencies();
?>



Thank you so much

Link to comment
Share on other sites

To prevent creating files each time the cron is executed, rather use the following command:

wget -O /dev/null http://www.your-domain.com/cron.php?secure_key=x2r8tnt > /dev/null 2>&1;



If you use the upper code, you won't have problems, that can be seen on the attached image.

Cheers ;)

First of all create a directory in your shops root directory and call it cronjobs, then upload the file attached in this email to that directory and in your cpanel create a cron job with this command:

/usr/bin/php -q /home/youruser/public_html/yourshoprootdir/cronjobs/cronjobs.php --secure_key=123 --type=currency

replace 123 with your password just make sure to change the program to check against that password

hope this help


Hugh

ps. in my isntallation php is located in /usr/bin/ so make sure whre your php is installed in your server


Your method is way way too complicated.

Just use file, that was recommended by Rocky and the command below:


Thats it, very simple and it works like a charm =)

Cheers, Housy

46751_eFdS0cYOAQB2U5ttHFvP_t

Link to comment
Share on other sites

Just simply visit this URL -> Currencies, then open up your Back Office (log in as admin), go to payment tab and then click currencies. If the currencies from the Back Office match the currencies from the link, then it works ;)

how I know that the following code working
Link to comment
Share on other sites

  • 1 year later...

Hi there.

Currently I'm running prestashop 1.4.3

I just tried what Rocky asked to do and successfully check the link ....secure_key=password result returned.

 

I go back to BO and check the currencies has not been updated.

Any idea?

Does this method compatible with 1.4x version?

 

Thanks Mate

Edited by oondudutz (see edit history)
Link to comment
Share on other sites

  • 5 months later...

Hi there.

Currently I'm running prestashop 1.4.3

I just tried what Rocky asked to do and successfully check the link ....secure_key=password result returned.

 

I go back to BO and check the currencies has not been updated.

Any idea?

Does this method compatible with 1.4x version?

 

Thanks Mate

 

Check paths of including files... Worked for me...

<?php
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../classes/Currency.php');
if (isset($_GET['secure_key']) AND $_GET['secure_key'] === '987654321')
  Currency::refreshCurrencies();
?>

Link to comment
Share on other sites

  • 8 months later...
  • 3 months later...

Does this cron job apply to version 1.5x?

Hi,

I have this version of prestashop and I tried everything, until try to check my files permissions wich was 755. None of the files on admin folder should have a permission bigger then 644. After changing that I put the comand wget http://www.yourdomain....(as shown on currency page of presta) and it worked out! I hope it helps :)

Link to comment
Share on other sites

  • 3 months later...

Hi,

I have this version of prestashop and I tried everything, until try to check my files permissions wich was 755. None of the files on admin folder should have a permission bigger then 644. After changing that I put the comand wget http://www.yourdomain....(as shown on currency page of presta) and it worked out! I hope it helps :)

Hello excuse me how do you do this ? i try to xhange permission to fil cron_.... but nothing what permission do you give to file ? and to what files ? thanks for help

Link to comment
Share on other sites

Hello,

 

where does the PS BO (http://www.myshop.com/admin/index.php?controller=admincurrencies) takes the currency rates from? They seem to be a bit different than http://www.ecb.europa.eu/stats/exchange/eurofxref/html/index.en.html. I was trying to look all the files related to currency but couldn't  locate the source of therates.

Edited by outlet.ee (see edit history)
Link to comment
Share on other sites

  • 1 year later...
  • 4 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...