如何在 Magento 中显示特定类别的产品(没有子类别)

发布于 2024-12-15 05:59:50 字数 236 浏览 4 评论 0原文

我有一个类别 X,其中有两个子类别 Y 和 Z。X 还绑定了一个产品。 当我尝试像这样选择产品时:

$category_obj->getProductCollection()->addCategoryFilter($category_obj);

我得到 X 中的所有产品以及子类别中的产品。

有没有办法只获得类别 X 中的产品?

提前致谢, 罗氏

I have a Category X with two subcategories Y and Z. X also has one Product bound to it.
When I try to select the Products like this:

$category_obj->getProductCollection()->addCategoryFilter($category_obj);

I get all Products in X plus the ones in the Subcategories.

Is there are way to get only the product/s in Category X?

Thanks in advance,
Rho

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乜一 2024-12-22 05:59:50

当然,它会显示您现在得到的预期结果,因为您正在按 $Category_obj 进行过滤。为什么你不按类别过滤产品,

你需要做这样的事情:-
从category_obj中获取所需类别的ID,然后执行以下操作:-

$category_obj->getProductCollection()->addCategoryFilter($category_id);

Ofcourse it will display the expected result what u are getting now because you are filtering by $Category_obj. Why dont u filter products by category

you need to do something like this :-
Fetch The Needed Category's Id from category_obj and Then do this :-

$category_obj->getProductCollection()->addCategoryFilter($category_id);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文