Here is my problem: I have a vehicle parts site which lets user select their specific model and be saved via a cookie. Then the whole site will be filtered via my module plugin, where I override “Magento/Catalog/Model/ResourceModel/Product/Collection” with the aroundPrepareProductCollection function where I “addattributetofilter” if cookie exists.
I have a megamenu set up on a phtml file with a bunch of categories as an html/css dropdown. (I can provide code.) My issue is that certain vehicle fitments won’t have any products in a few categories. MAIN QUESTION: How can I check whether products exist in a category that’s been filtered, and show them if there are products, and hide if there are not? Kind of like how a layered navigation works (if there is > 0 products in an attribute, show the attribute. If not, don’t show.) My main method I’m thinking is just editing the phtml that contains the megamenu, and add some php in it. But are there other more efficient methods?
The reason this is important is that so users won’t be able to click on a link in the mega menu (which are categories and sub-categories respectively), and then get shown that “We can’t find products matching your selection” aka no products in this category fit your vehicle aka turns people off site. When we can just show them relevant categories in megamenu. Thanks in advanced!!