Jump to content
Phuah

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

Recommended Posts

I'm using V1.3.2, can we make our currencies auto update without manually click on "update currencies" daily.
Thanks.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Just try to call your cron.php url (http://www.mydomain.com/cron.php?secure_key=update) in your browser.
If you can't, then you didn't put it in the right place.

If it works, in your cron job, try this :
curl http://www.mydomain.com/cron.php?secure_key=update

not just : http://www.mydomain.com/cron.php?secure_key=update:

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

I have another issue also that the currency exchange file for Europe excludes the shekel. I really would prefer an update from a bank that has shekel rates also.

Share this post


Link to post
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.




Working GREAT !

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Hi
Now i am not at my office so i cannot post my php file i'll post it when i get there this afternoon,
In my case is wirking i had to make some twist to my Php file but it finaly worked

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

I am glad that you solved it and I am glad that I could help you

Regards

Hugh

ps. and yes I did it with the help of the php manuals

Share this post


Link to post
Share on other sites

Are the currencies automatically updated in the newest PS version (1.4.1)?

Housy

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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();
?>

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More