Magento News

 

Magento – Loading root collection loads all products

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:

roots

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:

filter

Magento – Loading root collection loads all products

Possibly Related Posts:


 

Leave a Reply