How to Auto-Update the Exchange Rates with Cron Job

How to Auto-Update the Exchange Rates with Cron Job

As a professional e-Commerce solution, PrestaShop does support multi-currency on selling products certainly. The related setting can be found in backoffice in InternationalLocalization

Don’t know how to set up currencies?  Check out our video!

We can find a option on bottom like the below picture, which enable to update the exchange rate periodically. However, you can see that the switch is greyed out with a text saying to let you install the cronjobs module.

It used to be a cron job module available in the add-on marketplace, which able user to set cron job with this module. However, this module was removed, as it was not working reliably, while it is actually hard to cover different OS with only one module. Therefore, the best practice would always be setting it directly on the server, or via the hosting.

But how do we set this?

What do we need?

No idea how to set up Cron Job?  Check out our article!

We are using curl / wget to browse a PHP file inside the admin folder, so you need:

  • Figure out the complete URL which link to that PHP file

A secure key is also required to access the function by passing to the url and you will need the below to get the key:

  • COOKIE_KEY
  • Shop Name
  • MD5 Generator
Assumption
  • The backoffice folder is named admin2021
  • We are updating the exchange at 6am per day
  • The domain of the website is: http://shop.genkiware.com/
PHP File

The PHP file is named cron_currency_rates.php inside the admin folder. Therefore, in this exmaple, the URL to the file will be:
http://shop.genkiware.com/admin2021/cron_currency_rates.php

Secure Key

COOKIE_KEY

  • This is a 56-char string and unique for every shop, which could be found easily in app/config/parameters.php
    We are using this as example: HaNS1NpRvOFSmcOuaxu1OAhA7JYzAi5BHqHs3B4SrfL7E3LgjBWI7O2x

Shop Name

There are 2 ways to find it:

  • Go to Shop ParametersContact. Look for the Stores tab, then get the shop name on the bottom “Contact Detail”
  • Run the following SQL on your database:
    SELECT `value` FROM `ps_configuration` WHERE `name` = 'PS_SHOP_NAME'

MD5 Generator

Process

  1. Join the COOKIE KEY and shop name:
    HaNS1NpRvOFSmcOuaxu1OAhA7JYzAi5BHqHs3B4SrfL7E3LgjBWI7O2xGenkiStore
  2. Digest with MD5 you will get the secure key:
    dd8de15a41ed5815785a08f1256dbd8c
Cron Job Setting

As we are updating it 6am per day, so the period should write 0 6 * * *

The complete URL will be http://shop.genkiware.com/admin2021/cron_currency_rates.php?secure_key=dd8de15a41ed5815785a08f1256dbd8c

Finally, the full sentence to be written in crontab -e on the server would be:
0 6 * * * curl "http://shop.genkiware.com/admin2021/cron_currency_rates.php?secure_key=dd8de15a41ed5815785a08f1256dbd8c"

And…Done! Your shop would now update the exchange rate automatically at 6am per day, Yay!



Start typing and press Enter to search

slot gacor dana slot deposit dana