Prestashop 1.5.6.2 shows wrong products in the category (FrontOffice)

戏子无情 提交于 2019-12-23 17:22:43

问题


I'm using prestashop 1.5.6 and make a bulk category and product operation into mysql via 3rd party libraries (which i was wrote). Everything fine till some of my products show in wrong category. For eg i have A product in A category; But when i go to the B category A product is also there. I think something wrong with my ps_category_product table with position column. I'm updating this table with 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 fine on Backoffice > Products > Filter By Category tab. It shows correct products under category. Is there any specific detail in Front Office? If i truncate table (ps_category_product), my products dont shown in categories in Front Office. What am i missing?

Any help will greatly appricated.

Update

After @bcsteeve s comment, i create a sample category from BackOffice and all products shown in correct categories. When i look at the changes on my mysql tables; only ps_category table has changed some values nleft and nright columns.

In my simple webservice, i assign nleft and nright to 0 (zero). But now they have some values different then 0 (zero).

Now i think my problem is recalculating hierarchy of ps_category table.

Is there any specific prestashop core controller and/or method that can recalculate nleft and nright values on ps_category table? Because i dont want to add category manually after my webservice is update my products and categories.

Thanks in advance!


回答1:


You can regenerate the nleft and nright columns of the ps_category table with the following code:

require_once '../config/config.inc.php';

try {
  Category::regenerateEntireNtree();
} catch (CategoryException $e) {
  echo $e->getMessage();
}



回答2:


I had the same problem in prestashop 1.6. Switch off cache if you have file cache selected. Cache switched on after few minutes and all back to work again.




回答3:


I had a similar problem, products list in category page are wrong, i upgraded the layered navigation module and it had fixed the problem, i think i should create some indexing crons for this module



来源:https://stackoverflow.com/questions/31270704/prestashop-1-5-6-2-shows-wrong-products-in-the-category-frontoffice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!