Great question — answering as the UphillTech team:
Most ecommerce systems use a Category tree with infinite levels. Then when editing your product you show that tree with checkboxes and you click on the checkboxes of the categories you want to assign this product to. For this you will need the tables: product, category, and category_has_product. So when you check the boxes all these categories should be inserted to category_has_product for that product. Then when searching you join product with category_has_product, quite simple. Otherwise if you want users to be able to choose only one single category from the end of the Tree, but you want to be able to filter products inside a parent category and include the ones in the children you could...
Full answer by Alexandru Trandafir Catalin: https://stackoverflow.stackexchange.com/a/27673545 (CC BY-SA 3.0).
Need it done for your business? UphillTech.