Close

Instant Search - top level category

Freddy1234
6 years ago
#13705 Quote
Avatar
  • 41
Hello

Is it  possible getting the same function show only top level categories on the Instant search dropdown on the basic/standard Nopcommerce advanceed search page?

I have ten main categories and abit over 150 subcategories

So having both the searches showing the same amount of categories instead of one is showng top levels and one is showing all of the categories.
SDobrev
6 years ago
#13706 Quote
Avatar
  • Moderator
  • 283
Hi,

It is possible if you are using the Source version of nopCommerce because you will have to modify the nopCommerce source code.

1. Find the PrepareSearchModel method in the CatalogModelFactory (For nopCommerce 3.9. if you are using some other version this method won't be there).

2. The top level categories have parentCategoryId = 0.
Replace "var allCategories = _categoryService.GetAllCategories(storeId: _storeContext.CurrentStore.Id);"
with "var allCategories = _categoryService.GetAllCategories(storeId: _storeContext.CurrentStore.Id).Where(c => c.ParentCategoryId == 0).ToList();"

Please note that this is a sample code and it is not tested. If you are not using nopCommerce 3.9 it is possible that the methods, properties, names, etc. to be different.
Also, you will have to check "Automatically search sub categories" by default otherwise the search results won't be correct.

Hope this helps.
Best Regards,
Stoyan Dobrev
Nop-Templates.com