Mind Dump, Tech And Life Blog
written by Ivan Alenko
published under license Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)copy! share!
posted in category Systems Software / PHP
posted at 21. Apr '18
last updated at 11. May '21

Fixing PrestaShop categories - not shown or infinite loop

PrestaShop version 1.6.0.9

Intro

If your categories in PrestaShop front-office are not shown or a browser tells that there is infinite loop in categories admin (back-office), there is a problem in a structure of categories.

There are two basic categories which must exist:

  • Root with id=1
  • Home with id=2

My customer was somehow able to delete Home category and totally broke displaying of categories. Every category in a shop has to be child of Home and Home have to be children of Root. You should see “Root / Home” every time in categories admin (PrestaShop directs there by default).

I’ve encountered the infinite loop when I didn’t fully cleaned up ps_category_shop table which associates categories with respective (virtual) shop.

So, fire up mysql -u user -p console or phpmyadmin and start fixing things!

Fixing

There are five tables for categories, all of them needs inspect:

  • ps_category
  • ps_category_group
  • ps_category_lang
  • ps_category_product
  • ps_category_shop

nright and nleft columns serves for tree set for categories. nleft should be for children bigger than for parent and nright lesser. But do not touch if it works.

Here are rows how they should look like:

ps_category

Note position and is_root_category columns.

mysql> SELECT * FROM ps_category;
+-------------+-----------+-----------------+-------------+-------+--------+--------+---------------------+---------------------+----------+------------------+
| id_category | id_parent | id_shop_default | level_depth | nleft | nright | active | date_add            | date_upd            | position | is_root_category |
+-------------+-----------+-----------------+-------------+-------+--------+--------+---------------------+---------------------+----------+------------------+
|           1 |         0 |               1 |           0 |     1 |     98 |      1 | 2014-11-17 01:25:05 | 2014-11-17 01:25:05 |        0 |                0 |
|           2 |         1 |               1 |           1 |     2 |     97 |      1 | 2014-12-01 13:45:51 | 2014-12-01 13:45:51 |        1 |                1 |

and if you add some category (I listed it only here, not in other tables):

|          26 |         2 |               1 |           2 |     3 |     54 |      1 | 2014-12-01 14:28:35 | 2014-12-01 14:28:35 |        0 |                0 |

ps_category_group

Category accessible for respective customer groups.

mysql> SELECT * FROM ps_category_group;
+-------------+----------+
| id_category | id_group |
+-------------+----------+
|           1 |        0 |
|           2 |        1 |
|           2 |        2 |
|           2 |        3 |

ps_category_lang

i18n for categories. You can rename Home to something else, but id_category must be preserved.

mysql> SELECT * FROM ps_category_lang;
+-------------+---------+---------+-----------------------------+-------------+-----------------------------+------------+---------------+------------------+
| id_category | id_shop | id_lang | name                        | description | link_rewrite                | meta_title | meta_keywords | meta_description |
+-------------+---------+---------+-----------------------------+-------------+-----------------------------+------------+---------------+------------------+
|           1 |       1 |       1 | Root                        |             | root                        |            |               |                  |
|           1 |       1 |       2 | Root                        |             | root                        |            |               |                  |
|           2 |       1 |       1 | Home                        |             | home                        |            |               |                  |
|           2 |       1 |       2 | Home                        |             | home                        |            |               |                  |

ps_category_product

No products, so…

mysql> SELECT * FROM ps_category_product;
Empty set (0.00 sec)

ps_category_shop

Don’t forget to add both 1 and 2 categories, otherwise an infinite loop will occur.

mysql> SELECT * FROM ps_category_shop;
+-------------+---------+----------+
| id_category | id_shop | position |
+-------------+---------+----------+
|           1 |       1 |        1 |
|           2 |       1 |        1 |

Quick SQL commands

SHOW DATABASES;
SHOW TABLES;
USE database;
USE table;
SELECT * FROM ps_category;
SELECT * FROM ps_category LIMIT 20;
INSERT INTO ps_category_shop VALUES (2,1,1);
DELETE FROM ps_category_shop WHERE id_category=21;
UPDATE ps_category_lang SET name="Home" WHERE id_category=2 AND id_lang=2;

That’s all.

Add Comment