0

I am using the Magento 2.1.8 version.

Facing an issue of products count next to the category name.

enter image description here

The categories of Anchor is enabled.

I did reindex and flush the Magento cache.

In addition, some products are shown in the frontend, which are not assigned for that category.

Can anyone advise on this?

  • 1
    check after disable anchor. because if anchor is enable then it will add sub category products count to parent. – Satish Dubariya Feb 9 at 7:36
  • okay, I'll try it – Shesh Feb 9 at 7:40
  • tried, but still the issue persists. – Shesh Feb 9 at 7:45
  • @Shesh Please check magento.stackexchange.com/a/261081/62611 hope will help you. – Jignesh Baldha Feb 9 at 11:21
  • 1
    @SatishDubariya thanks :) disabled is_Anchor but after reindex and flush the cache the problem seems to resolve. – Shesh Feb 9 at 12:33
3

Don't be confused. Product count display is different than actual product count in a category because Anchor is enabled.

The Anchor display setting for categories allows a category to inherit and display all products from its child categories. When Anchor Enable, products assigned to child categories will be combined and displayed in the parent category along with any products directly assigned to it. This means you can use Anchor at upper-level categories to avoid having to explicitly assign products all the way along a branch of the category tree. Instead, simply assign products to their lowest level (most specific) category and they will then be displayed automatically in parent categories.

I hope this will make sense.

1

There may be many reasons for it. Few which I can list

  • Product is out of stock
  • Product status is Disabled
  • Product visibility does not include Catalog
  • Product is not assigned to that particular website

Another possibility may be "Magento 1.9 has this issue but I am not sure about Magento 2"

In normal case, when you assign products to category then those products will be linked with that category and linked product count will be increased for that category. And if you unlink that product from that category then linked product count will be decreased.

Now problem will be arise when you delete product from catalog->product section. Still category will have entry for that product. So old product count will be in category.

Please check above scenario as well

I hope this will help

  • I checked.. everything is fine as per suggestion. I am confused where is the fault. – Shesh Feb 9 at 9:18
  • @shesh I added one more scenario in answer please check it – Muhammad Hasham Feb 9 at 10:10
  • Thanks a lot Muhammad bhai.. It's also helpful for me and others :) – Shesh Feb 9 at 12:35
  • Hello @MuhammadHasham How can I fix the count if I have removed products? – chirag May 30 at 7:04
1

If you put Anchor in Display Settings to yes this category shows all of the products of its own and all of its subcategories in the frontend.

Therefore the 13 products you see are a subset of what you see in frontend (if all of this 13 products have the right visibility and are saleable of course).

The 17 in the category tree is the sum of all unique products of the category itself and the products of subcategories (given the fact that Anchor is enabled). So if you have some products in the category itself and in one of the subcategories this product is counted only once.

You can check if everything is ok in your system with that category by running this SQL statement:

select count(distinct product_id) from catalog_category_product where 
category_id in (
   select entity_id from catalog_category_entity where parent_id = [YOUR 
   CATEGORY_ID HERE]
);

If the result is 17 everything is fine.

I hope that helps.

  • Your welcome, since I posted my answer before the one you accepted, I hope that gave you some added value :-) – HelgeB Feb 9 at 13:07

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.