Magento - 加载根集合加载所有产品
关于使用具有不同根类别的多个商店:
我设置了 2 个具有不同根的商店。一个有 14 个产品,另一个有 6 个。
如果我在主页上使用以下内容(只是为了显示该商店的根类别中有多少产品 - 在本例中 ID 为 8),我会得到 20 个产品 - 所以所有产品在商店中,从所有根源:
$_testproductCollection = Mage::getModel('catalog/category')->load(8)
->getProductCollection()
->addAttributeToSelect('*')->load();
echo "NO. OF PRODUCTS IS ".$_testproductCollection->count();
但是,如果我将 ID 更改为子类别,我会获得正确数量的产品。此根目录中只有 6 个产品:
但计数显示 20 个(因为整个商店中有 20 个 - 或两者都有根)。
有人知道怎么回事吗?这是一个错误吗?
我还注意到,如果您转到“管理产品”并使用商店视图过滤器,它不会执行任何操作,仍然在商店视图中显示 20 个产品,其根目录只有 6 个产品
: sstatic.net/NrFwS.jpg" alt="过滤器">
Regarding using multiple stores, with different root categories:
I have 2 stores set up, with different roots. One has 14 products, the other 6.
If I use the following on my homepage (simply to show how many products are in the root category for that store - in this case with an ID of 8) I get 20 products - so all products in the store, from all roots:
$_testproductCollection = Mage::getModel('catalog/category')->load(8)
->getProductCollection()
->addAttributeToSelect('*')->load();
echo "NO. OF PRODUCTS IS ".$_testproductCollection->count();
However, if I change the ID to a sub-category, I get the correct amount of products. There are only 6 products in this root:
But the count shows 20 (as there's 20 in the whole store - or both roots).
Anyone know what's up? Is it a bug?
I also noticed that if you go to Manage Products and use the store view filter, it doesn't do anything, still showing 20 products in the store view whose root has only 6 products:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我认为这可行,没有测试太多,但似乎已经成功了。您需要首先获取商店根类别 id,然后加入一些字段,以便您可以访问产品“category_id”,然后使用它进行过滤:
OK, I think this works, haven't tested too much but seems to have done the trick. You need to first get your stores root category id, then join some fields so you have access to the products "category_id", then filter using that: