3

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

  • Can you give an example? – Marius Jul 21 '14 at 10:27
  • @Marius, added screenshots – MTM Jul 21 '14 at 10:36
3

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.

  • ok, let me confirm by counting the child and its own products. – MTM Jul 21 '14 at 10:46
  • @marius: is there a way to undo this behaviour. As earlier my client didn't wanted this behaviour. I had to convince him to go with it... – Dexter Jul 21 '14 at 10:50
  • @MTM. You can try making the 3rd parameter of the method loadProductCount default to false instead of true but I don't know the implications for the rest of the application. – Marius Jul 21 '14 at 10:53
  • The site is live, I can't take chances, better convince the client like Dexter :) – MTM Jul 21 '14 at 10:59
  • @Marius: what do you think is suppose to be the logic behind this implementation? – Dexter Jul 21 '14 at 11:02
1

This is a normal behavior of Magento for displaying products when category are Anchored. I don't know the exact logic behind it but, this is what i have observed.

1) Suppose you have a Main category Office Chairs in your case. Now this category may be having three subcatgory ie: Rolling chair, Steel Chairs and Wooden chair

2) Suppose you have inserted 10 products in each of subcategories and 5 in Main category ie: Office Chairs

3) Now when the category is not Anchored ie: Is Anchor -> NO, The category Office Chairs will only show the 5 products associated with it.

4) When you make this category Anchored ie: Is Anchor -> YES It will show the products of the Main Cateory ie Office Chairs and also the products of its child category ie 'Rolling, steel and wooden chairs'. This is how Magento behaves.

Conclusion: The Anchored Category will display all the products ie: Products associated with Main category and also the products associated to its children category.

I don't know the exact reason for implementing it in the manner it is at present. Hope others at forum can provide light on it.

1

I have the same issue and just tested this. Without any issue, it works perfectly.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.