Jump to content

"nleft" "nright" with value 0 in ps_category when creating new categories


usermar

Recommended Posts

Hi. I notice that when I create a new category it is not displayed correctly in the public part, it appears without breadcrumbs and without an apparent parent category. The cause is that the "nleft" and "nright" fields of the ps_category table always appear with value 0 and do not have a correct node value. All other fields such as the parent category etc are correct.

I have done all kinds of tests but I can't figure out why the nodes are not generated.

I have tried disabling most modules, switching to the default theme. I have also upgraded to version 1.7.8.5 in a test environment (I currently have 1.7.8.2 in production). I tried to call the Category::regenerateEntireNtree function to regenerate the categories. None of this seems to work.

I would be very grateful if someone could help me or give me some hint. I have searched a lot and have not found any solution.

Link to comment
Share on other sites

  • 2 weeks later...
On 5/2/2022 at 8:54 PM, usermar said:

Hi. I notice that when I create a new category it is not displayed correctly in the public part, it appears without breadcrumbs and without an apparent parent category. The cause is that the "nleft" and "nright" fields of the ps_category table always appear with value 0 and do not have a correct node value. All other fields such as the parent category etc are correct.

I have done all kinds of tests but I can't figure out why the nodes are not generated.

I have tried disabling most modules, switching to the default theme. I have also upgraded to version 1.7.8.5 in a test environment (I currently have 1.7.8.2 in production). I tried to call the Category::regenerateEntireNtree function to regenerate the categories. None of this seems to work.

I would be very grateful if someone could help me or give me some hint. I have searched a lot and have not found any solution.

Hi,

i am really sorry for the issue you are facing, but Please can you share some screenshots of front office & backoffice category part?

your question seems to be very confusy or not related to what you are talking about, that is why there is no reply since 10 days.

 

Regards

Edited by SMTmardan (see edit history)
Link to comment
Share on other sites

Thank you very much for your reply, sorry for the delay.

I will try to explain the problem in a simpler and clearer way.

In the ps_category table of the BBDD each category has a value "nleft" and "nright". This value is auto-calculated every time any category or subcategory is added, removed or moved (I don't know exactly how the calculation is done). Apparently, Prestashop uses these values to position the category within the tree of categories and subcategories.

My problem is that no matter what I do, since some time ago, any operation with categories gives as value nleft=0 and nright=0.

This generates errors and problems in the Front Office part, for example in breadcrumbs or SEO.

Any help to find out the cause would be welcome, it's very frustrating.

2022-05-18 110331.png

Link to comment
Share on other sites

Hi,

Did you tried these suggestions?

In Back office, I believe add/delete a category or (temporarily) move a category under a new parent and then save it will rebuild the tree structure. 

(maybe make a category 'tempcat' and put it under any parent. Then save the category. Check if the left and right values are added in the database. Then delete the tempcat afterwards)

 

Link to comment
Share on other sites

Thank you very much for your reply,
Yes, I have tried everything.

Every new category I create has "0" values and if I move this category it still has "0"values.
But not only that, whatever I do it doesn't change the values of the rest of the categories. Even if I delete this or another category all the values of the others categories never change.

2022-05-18 180131.png

Link to comment
Share on other sites

  • 3 weeks later...
On 5/2/2022 at 5:54 PM, usermar said:

the "nleft" and "nright" fields of the ps_category table always appear with value 0 and do not have a correct node value.

I am struggling with the same problem. After adding categories from the dash, I have to change manually in the database the values of "nleft" and "nright" fields. Has anyone dealt with this problem? PS v 1.6.1.0

  • Like 1
Link to comment
Share on other sites

The most logical explanation is that there is somewhere a php error that stops the code before it can set nleft/nright. But as most of the action happens in ajax calls it is quite hard to find out. Looking in the error log of the server is often the easiest way.

Prestools has a function to restore the nleft/nright tree (it is in the Integrity Checks).

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...

2024 year i and have this problem too, when adding new category in database are only "0", when i turn on debuge its show:

INSERT INTO `ps_category` (`nleft`, `nright`, `level_depth`, `active`, `id_parent`, `id_shop_default`, `is_root_category`, `position`, `date_add`, `date_upd`) VALUES ('0', '0', '3', '1', '4350', '1', '0', '0', '2024-07-26 10:42:04', '2024-07-26 10:42:04')

 

ps 1.6.1.24, updated classes/ controllers, tools/ from prestashop 1.6.1.24 zip from prestashop site.

editing or moving category not fix nleft and nright pos 😕

<?php
include_once('config/config.inc.php');
include_once('init.php');

Category::regenerateEntireNtree();
?>

in file not working too.

 

 

EDIT, aaaand fixed! :) this tool: Prestools help me check where is problem, show many categories that have id_parent = '0', so first use this:

UPDATE ps_category SET id_parent = '1' WHERE id_parent = '0';

then must change back root category so in id_category=1 set id_parent  to '0', now nleft and right working good,

rest of work its to clean all weird categories who have id_parent = '1'

thx @musicmaster for tip

Edited by mudol (see edit history)
Link to comment
Share on other sites

12 minutes ago, mudol said:

2024 year i and have this problem too, when adding new category in database are only "0", when i turn on debuge its show:

INSERT INTO `ps_category` (`nleft`, `nright`, `level_depth`, `active`, `id_parent`, `id_shop_default`, `is_root_category`, `position`, `date_add`, `date_upd`) VALUES ('0', '0', '3', '1', '4350', '1', '0', '0', '2024-07-26 10:42:04', '2024-07-26 10:42:04')

 

ps 1.6.1.24, updated classes/ controllers, tools/ from prestashop 1.6.1.24 zip from prestashop site.

editing or moving category not fix nleft and nright pos 😕

<?php
include_once('config/config.inc.php');
include_once('init.php');

Category::regenerateEntireNtree();
?>

in file not working too

When I look at your SQL command I see an id_parent of 4350. That means that you have (had) at least 4350 categories in this shop. Sounds very weird. Are you sure this id_category exists?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...