如何在 Magento 中显示特定类别的产品(没有子类别)
我有一个类别 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,它会显示您现在得到的预期结果,因为您正在按 $Category_obj 进行过滤。为什么你不按类别过滤产品,
你需要做这样的事情:-
从category_obj中获取所需类别的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 :-