Prestashop 1.5.6.2 shows wrong products in category (FrontOffice)
I am using prestashop 1.5.6 and doing bulk category and product manipulation in mysql through 3rd party libraries (which I wrote). All is well until some of my products show up in the wrong category. For example, I have product A in category A; But when I go to Product B of Category A, there is also. I think there is something wrong with my table ps_category_product
with position column. I am updating this table with the code below;
$sqlFirst = 'SELECT id_product, id_category_default, xml_id_product FROM ps_shop_product';
$queryFirst = $db->prepare($sqlFirst);
$queryFirst->execute();
while ($rowFirst = $queryFirst->fetch(PDO::FETCH_OBJ)){
$sqlProductAddCatPosFirst = '
INSERT INTO ps_shop_category_product
(id_product, id_category, position)
VALUES
(?, ?, ?)
';
// ps_shop_category_product Sql sorgumuzu hazırlayalım
$queryProductAddCatPosFirst = $db->prepare($sqlProductAddCatPosFirst);
$queryProductAddCatPosFirst->bindParam(1, $rowFirst->id_product, PDO::PARAM_INT);
$queryProductAddCatPosFirst->bindParam(2, $rowFirst->id_category_default, PDO::PARAM_INT);
$queryProductAddCatPosFirst->bindParam(3, $rowFirst->id_product, PDO::PARAM_INT);
// ps_shop_category_product Hazır Sql sorgumuzu çalıştıralım
$queryProductAddCatPosFirst->execute();
}
But everything is fine on the tab Backoffice > Products > Filter By Category
. It shows the correct products under the category. Are there any specific details in Front Office? If I truncate the table (ps_category_product)
, my products are not showing up in categories in Front Office. What am I missing?
Any help would be very helpful.
Update
Following @bcsteeve's comment, I create a sample category from BackOffice and all products listed in the correct categories. When I look at changes in my mysql tables; only the table ps_category
changed some of the column values nleft
and nright
.
In my simple web service, I assign nleft
and the nright
value 0 (zero). But now they have some values other than 0 (zero).
Now I think my problem is recalculating the table hierarchy ps_category
.
Is there any particular main controller and / or method that can recalculate the nleft and nright values in the table
ps_category
? Because I don't want to add a category manually after my webservice has updated my products and categories.
Thanks in advance!
You can regenerate columns nleft
and nright
tables ps_category
with the following code:
require_once '../config/config.inc.php';
try {
Category::regenerateEntireNtree();
} catch (CategoryException $e) {
echo $e->getMessage();
}
I had the same problem in pre-step 1.6. Disable cache if cache file is selected. The cache turns on after a few minutes and everything goes back to work again.
I had a similar problem, the list of products on the category page is wrong, I updated the layered navigation module and it fixed the problem, I think I should create some indexing clones for this module