I need to display categories in header main navigation but only categories which has at least one instock product (configurable) , currently I tried by checking whole product collection for each category and check weather they have at least one instock product but it kills the mysql server and taking much time as my catalog is almost more than 50,000+ . Second option I thought is running a cron but it will also not give realtime result. So is there any other way to do this ? perhaps using model_save_after event or something

1 Answer 1


Building a universal solution might be too big of a scope as there are a number of configurations to consider:

  • Parent may be disabled
  • Child products may be disabled
  • Stock may not be managed for some products
  • Minimum stock amount
  • Minimum allowed-in-cart amount
  • etc.

I'd recommend to standardize and document the relevant configuration for your store, perhaps noting these assumptions wherever you store your code. You might even want to set up config save observers which enforce these business rules. Assuming this is in place you may also want to enforce that all child products mirror their parent's category/categories association, as this will allow you to work with IDs from cataloginventory_stock_item which you can use to filter your category collection.

You'll definitely need to rewrite Mage_Catalog_Block_Navigation as it contains a the logic related to cache keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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