Prestashop 1.5.6.2 在类别中显示错误的产品 (FrontOffice) [英] Prestashop 1.5.6.2 shows wrong products in the category (FrontOffice)
问题描述
我正在使用 prestashop 1.5.6 并通过 3rd 方库(我写的)将批量类别和产品操作放入 mysql.一切都很好,直到我的一些产品显示在错误的类别中.例如,我有 A 类产品;但是当我去 B 类时 A 产品也在那里.我认为我的带有位置列的 ps_category_product
表有问题.我正在用下面的代码更新这个表;
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();
}
但是在 Backoffice 上一切都很好 >产品 >按类别过滤
选项卡.它在类别下显示正确的产品.前台有没有具体的细节?如果我截断表 (ps_category_product)
,我的产品不会显示在前台的类别中.我错过了什么?
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?
任何帮助都会非常有用.
更新
@bcsteeve 发表评论后,我从 BackOffice 创建了一个示例类别,所有产品都显示在正确的类别中.当我查看 mysql 表上的更改时;只有 ps_category
表更改了一些值 nleft
和 nright
列.
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.
在我的简单网络服务中,我将 nleft
和 nright
分配给 0(零).但是现在它们有一些不同于 0(零)的值.
In my simple webservice, i assign nleft
and nright
to 0 (zero). But now they have some values different then 0 (zero).
现在我认为我的问题是重新计算 ps_category
表的层次结构.
Now i think my problem is recalculating hierarchy of ps_category
table.
是否有任何特定的 prestashop 核心控制器和/或方法可以重新计算 ps_category
表上的 nleft 和 nright 值吗?因为我不想在我的网络服务之后手动添加类别更新我的产品和类别.
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.
提前致谢!
推荐答案
您可以重新生成 ps_category
表的 nleft
和 nright
列使用以下代码:
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();
}
这篇关于Prestashop 1.5.6.2 在类别中显示错误的产品 (FrontOffice)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!