How can I disable the price filter for some categories? I know how to turn it on or off completely, but we have to be able to show it for only some categories.
Thanks!
private string PriceRangeFilterClass(int CategoryId)
{
List<int> lstCategoryIds = new List<int>();
List<string> lstExclusions = new List<string>();
try
{
// Fill lstExclusions with category names from the setting.
lstExclusions = _settingService.GetSettingByKey<string>("nopajaxfilterssettings.disablepricerangefilterforcategories").Split(',').ToList();
}
catch
{
// Do nothing. The setting does not exist.
return string.Empty;
}
// Iterate through exclusions. Add the IDs to the list of IDs.
foreach (string s in lstExclusions)
{
int intCatId;
try
{
intCatId = _categoryService.GetAllCategories().Where(x => x.Name == s).FirstOrDefault().Id;
}
catch
{
intCatId = 0;
}
lstCategoryIds.Add(intCatId);
}
// If the list of IDs contains this category's ID...
if (lstCategoryIds.Contains(CategoryId))
{
return "hide-price-range";
}
else
{
return String.Empty;
}
}
@model string
@String.Format("{0}", Model)
var currentCategoryId = Convert.ToInt32(Url.ActionContext.RouteData.Values["categoryId"].ToString());
var priceRangeFilterClassResult = await Component.InvokeAsync("NopAjaxFiltersSettingsExtend", new { CategoryId = currentCategoryId });
string priceRangeFilterClass = priceRangeFilterClassResult.RenderHtmlContent();
<div class="block filter-block priceRangeFilterPanel7Spikes @priceRangeFilterClass" data-currentcurrencysymbol="@Model.CurrencySymbol">