Add a column showing values of a custom field added to PrestaShop

Published : 01/03/2018 11:22:51
Categories : Sitolog tips Rss feed

Add a column showing values of a custom field added to PrestaShop

Level : advanced

Display an HTML block or additional text in PrestaShop

For this you often use an external addon, or a custom made module which will for example allow to add an additional HTML block to the location of your choice, with a different content for each product.

Most of the time, this type of module adds a new table to the database, to store the contents of the field.

In other cases, it just adds a new topic to an already existing PrestaShop table, such as the "product" or "product_shop" table.

The question that you often ask us is: is it possible to display the contents of this type of
non-standard fields in PrestaPricing or Merlin Backoffice ®, to see and modify its content for each product ?
The answer is yes, of course, thanks to the "Custom" columns.

For this tutorial, we will take a very concrete case, with the use of a colleague's module: "Products Stock Threshold". This addon does not add a field to the display but a numeric parameter to each product. In this case a quantity threshold, which triggers an alert when it is reached. Once installed, this addon adds a new tab entry in the product listing back office to enter this "Stock threshold":

Stock threshold alert addon

The principle remains the same,  this module has added its own table in the database (pss_products_stock_threshold), and saves the values ​​in a field called "quantity". This information is rarely documented, but most of the time, the name of the added table or tables refers to the name of the module. It is therefore quite easy, in PHPMyAdmin, to find this information. If you do not find this info, simply ask the developer of the module: "What are the names of the table and the field containing the values ​​of the custom field?".

For the module used in this tutorial, here is a cature of PHPMyAdmln, showing the structure of the table found in the database, after its installation:

Tables added by the addon, shown in PHPMyAdmin

How to display this non-standard topic in Merlin Backoffice?

1 / Place yourself in the "Products" view and first open the column configurator by clicking on the "Columns" button in the title of the main window.

2 / Place yourself in the "Products" sub-tab of the table configuration window and right-click in the list on the left, in order to open the custom columns configurator:

Merlin Backoffice tables configurator

3 / You have just two fields to fill, in the columns indicated by arrows in the capture below, the name of the table (1) and the name of the non-standard field to display (2).

Warning, the name of the table must be entered without its prefix (here I removed the prefix pss_):

CMerlin Backoffice custom columns configurator

4/Then drag and drop the line "Perso 1" from the left table to the right table in the position (order) of your choice (1) :

Addition of a custom column

You can also (2), give the title you want to your column.

Change of title given to the column:

Change the title of the personnalized column

(3) validate.

5 / The product display automatically refreshes, adding your customized column and displaying the value it contains for each product:

Result, the custome columns is displayed in Merlin backoffice products table

From there, it is possible to:

-View the values

-Edit values, cell by cell (one row at a time)

-Filter on this column


It is not possible (for the moment):

-To make mass modifications

-To import into this type of field via a csv / xls file.

Additional note: The above case was fairly simple because the pss_products_stock_threshold table contained an id_product colmn. This is called a direct link. Sometimes it will require to enter sql code to define a connection between the tables of the database. You may alos need to define filters by language, by shop ... All this requires a good technical knowledge of the sql syntax and was not covered in this tutorial. But be aware that it is feasible ....

Share this content

You must be register

Clic here to register

Add a comment