Magento 1.7 – Admin Category Product Count Shows Wrong Value When Is Anchor Is Yes

categorymagento-1.7

I was having an issue of product count in the admin, I used the following query

DELETE FROM catalog_category_product where product_id NOT IN (SELECT entity_id FROM (catalog_product_entity))

Now at least I can see the correct count but as soon I change the Is Anchor to Yes, it shows wrong count again. why is that?
enter image description here
enter image description here

Best Answer

Ah. This is an old debate.
This is actually a feature not a bug.
Once you set a category to be anchor the product count for that category is determined by the products in that category and all its child categories.
For a technical view, take a look at Mage_Catalog_Model_Resource_Category_Collection::loadProductCount. Specially in the if ($countAnchor) { section.
It does exactly what I described above.

Related Topic