How to Create a Cron Job for Rebuilding Product Index in Linux Server

How to Create a Cron Job for Rebuilding Product Index in Linux Server

Sometimes we may find that some newly added products are not available to be searched in the shop. The reason is that the product is still not included in the product index.

The situation is like you have bought some books, but haven’t put them onto the book self yet.

However, in PrestaShop, the products should be automatically indexed into the search when they are saved in the Backoffice. But if you are using some third-party software to manage the catalog (where they may directly communicate with the database) etc. The product index may not be complete.

We are going to discuss how to index the product on below.

Requirements

Manually re-build

  • Backoffice access (for manually re-build)

Scheduled re-build by cron job

  • Server access / Web hosting account (for creating cron job)
  • curl / wget command
Indexing in Backoffice

You may find related settings in backoffice under [Shop Parameters] ⇒ [Search]. You should see a section like below picture:

The details are shown here, where you may know how many products are indexed. 2 choices are available in the middle, which allow you to choose whether re-build the whole index or only insert the missing products. Simply clicking on them will do the trick!

Schedule the Task with Cron

Cron is a build-in function in Linux system which allow users to schedule tasks. This can be done directly on the server or some hosting platforms like cPanel or Cloudways.

Basic Concept on Defining the Period

Cron use a row of 5 value to define the schedule time, below are some examples:

* * * * * means to execute at every minute

0 3 * * * means to execute at 3am each day

0 5/12 * * * means to execute at 5am & 5pm each day

0 */3 * * * means to execute every hours

0 0 1,15 * 3 means to execute at 00:00 if it is the 1st or 15th or the month and it is Wednesday

If you are not sure about your inputs, you may check and get a human-readable description here: crontab.guru

On Hosting Platform (Simple)
We are using Cloudways as a example. After logging in, “Cron Job Management” could be found on the left:
Upon clicking “Add New Cron Job”, you may input the details like below and the task is done:
On Server (Advance)
Firstly, connect to your server and then use the below command
crontab -e
You may be asked what editor to be used to edit, just choose you favorite one.
Then the below screen should be shown:

Tasks can be scheduled by inputting entry at the bottom with below format:

[Period] [Command]

For example:

0 3/12 * * * curl "https://xxx....."

There are 2 commands can do the trick:

wget

wget "[URL]" -O /dev/null

wget is usually pre-installed in Linux machine. However, running wget command will save file on the current directory. Using the switch -O /dev/null could prevent this happen

curl

curl "[URL]"

curl looks simply but it is not always pre-installed in Linux machine. Please make sure you have this command available before you create the cron job.

To Be Noted
Pay Attention to PrestaShop Version

There is a BUG in version 1.7.6.0 & 1.7.6.1, where you are not able to re-build the index by using cron job. Please make sure your shop is having a version ≥ 1.7.6.2 to ensure the cron job works.

If you are unfortunately using 1.7.6.0 / 1.7.6.1, we recommend you to upgrade the version or use the fix provided below:

https://github.com/PrestaShop/PrestaShop/pull/15855



Start typing and press Enter to search

slot gacor dana slot deposit dana