private void BuildFilter() { _paging.Where("Enabled={0}", true); _paging.Where("AND CategoryEnabled={0}", true); foreach (var c in (CategoryService.GetChildCategoriesByCategoryId(0, true).Where(p => p.Enabled))) { ddlCategory.Items.Add(new ListItem { Text = c.Name, Value = c.CategoryId.ToString(), }); } var listItem = ddlCategory.Items.FindByValue(Request["category"]); if (listItem != null) { ddlCategory.SelectedValue = listItem.Value; } _paging.Where("AND Exists( select 1 from [Catalog].[ProductCategories] INNER JOIN [Settings].[GetChildCategoryByParent]({0}) AS hCat ON hCat.id = [ProductCategories].[CategoryID] and ProductCategories.ProductId = [Product].[ProductID])", ddlCategory.SelectedValue); if (!string.IsNullOrEmpty(Page.Request["name"])) { var name = HttpUtility.UrlDecode(Page.Request["name"]).Trim(); txtName.Text = name; var productIds = LuceneSearch.Search(txtName.Text).AggregateString('/'); _paging.Inner_Join("(select item, sort from [Settings].[ParsingBySeperator]({0},'/') ) as dtt on Product.ProductId=convert(int, dtt.item)", productIds); if (_sort == ESortOrder.NoSorting) { _paging.OrderBy("dtt.sort ASC"); } SearchTerm = HttpUtility.HtmlEncode(name); } filterPrice.CategoryId = 0; filterPrice.InDepth = true; if (!string.IsNullOrEmpty(Request["pricefrom"]) || !string.IsNullOrEmpty(Request["priceto"])) { var pricefrom = Request["pricefrom"].TryParseInt(0); var priceto = Request["priceto"].TryParseInt(int.MaxValue); filterPrice.CurValMin = pricefrom; filterPrice.CurValMax = priceto; _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.Price - Offer.Price * Discount / 100 >= {0} ", pricefrom * CurrencyService.CurrentCurrency.Value); _paging.Where("AND Offer.Price - Offer.Price * Discount / 100 <={0} and Offer.ProductId = [Product].[ProductID])", priceto * CurrencyService.CurrentCurrency.Value); } else { filterPrice.CurValMin = 0; filterPrice.CurValMax = int.MaxValue; } }
private void BuildFilter() { _paging.Where("Enabled={0}", true); _paging.Where("AND CategoryEnabled={0}", true); _paging.Where("AND Offer.Main={0} AND Offer.Main IS NOT NULL", true); switch (_typeFlag) { case ProductOnMain.TypeFlag.Bestseller: _paging.Where("AND Bestseller={0}", true); break; case ProductOnMain.TypeFlag.New: _paging.Where("AND New={0}", true); break; case ProductOnMain.TypeFlag.Discount: _paging.Where("AND Discount > {0}", 0); break; case ProductOnMain.TypeFlag.OnSale: _paging.Where("AND OnSale={0}", true); break; case ProductOnMain.TypeFlag.Recomended: _paging.Where("AND Recomended={0}", true); break; } filterPrice.CategoryId = 0; filterPrice.InDepth = true; if (!string.IsNullOrEmpty(Request["pricefrom"]) || !string.IsNullOrEmpty(Request["priceto"])) { var pricefrom = Request["pricefrom"].TryParseInt(0); var priceto = Request["priceto"].TryParseInt(int.MaxValue); filterPrice.CurValMin = pricefrom; filterPrice.CurValMax = priceto; _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.Price - Offer.Price * Discount / 100 >= {0} ", pricefrom * CurrencyService.CurrentCurrency.Value); _paging.Where("AND Offer.Price - Offer.Price * Discount / 100 <={0} and Offer.ProductId = [Product].[ProductID])", priceto * CurrencyService.CurrentCurrency.Value); } else { filterPrice.CurValMin = 0; filterPrice.CurValMax = int.MaxValue; } filterBrand.CategoryId = 0; filterBrand.InDepth = true; filterBrand.WorkType = _typeFlag; if (!string.IsNullOrEmpty(Request["brand"])) { var brandIds = Request["brand"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList(); filterBrand.SelectedBrandIDs = brandIds; _paging.Where("AND BrandID IN ({0})", brandIds.ToArray()); } else { filterBrand.SelectedBrandIDs = new List <int>(); } }
private void BuildFilter() { _paging.Where("Enabled={0}", true); _paging.Where("AND CategoryEnabled={0}", true); if (Indepth) { _paging.Where("AND Exists( select 1 from [Catalog].[ProductCategories] INNER JOIN [Settings].[GetChildCategoryByParent]({0}) AS hCat ON hCat.id = [ProductCategories].[CategoryID] and ProductCategories.ProductId = [Product].[ProductID])", _categoryId); } if (!string.IsNullOrEmpty(Request["brand"])) { var brandIds = Request["brand"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList(); filterBrand.SelectedBrandIDs = brandIds; _paging.Where("AND BrandID IN ({0})", brandIds.ToArray()); } else { filterBrand.SelectedBrandIDs = new List <int>(); } _paging.Where("AND Offer.Main={0} AND Offer.Main IS NOT NULL", true); if (!string.IsNullOrEmpty(Request["size"])) { var sizeIds = Request["size"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList(); filterSize.SelectedSizesIDs = sizeIds; _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.[SizeID] IN ({0}) and Offer.ProductId = [Product].[ProductID])", sizeIds.ToArray()); } else { filterSize.SelectedSizesIDs = new List <int>(); } if (!string.IsNullOrEmpty(Request["color"])) { var colorIds = Request["color"].Split(',').Select(item => item.TryParseInt()).Where(id => id != 0).ToList(); filterColor.SelectedColorsIDs = colorIds; _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.[ColorID] IN ({0}) and Offer.ProductId = [Product].[ProductID] and Offer.[Amount] > 0)", colorIds.ToArray()); if (SettingsCatalog.ComplexFilter) { _paging.Select( string.Format( "(select Top 1 PhotoName from catalog.Photo inner join catalog.offer on Photo.objid=offer.productid and Type='product'" + " where offer.productid=product.productid and Photo.ColorID in({0}) order by Photo.PhotoSortOrder, Photo.Main)" + " as AdditionalPhoto", colorIds.AggregateString(','))); } else { _paging.Select("null as AdditionalPhoto"); } } else { filterColor.SelectedColorsIDs = new List <int>(); _paging.Select("null as AdditionalPhoto"); } if (!string.IsNullOrEmpty(Request["pricefrom"]) || !string.IsNullOrEmpty(Request["priceto"])) { var pricefrom = Request["pricefrom"].TryParseInt(0); var priceto = Request["priceto"].TryParseInt(int.MaxValue); filterPrice.CurValMin = pricefrom; filterPrice.CurValMax = priceto; _paging.Where("and Exists( select 1 from [Catalog].[Offer] where Offer.Price - Offer.Price * Discount / 100 >= {0} ", pricefrom * CurrencyService.CurrentCurrency.Value); _paging.Where("AND Offer.Price - Offer.Price * Discount / 100 <={0} and Offer.ProductId = [Product].[ProductID])", priceto * CurrencyService.CurrentCurrency.Value); } else { filterPrice.CurValMin = 0; filterPrice.CurValMax = int.MaxValue; } if (!string.IsNullOrEmpty(Request["prop"])) { var selectedPropertyIDs = new List <int>(); var filterCollection = Request["prop"].Split('-'); CheckSelectCategory(); foreach (var val in filterCollection) { var tempListIds = new List <int>(); foreach (int id in val.Split(',').Select(item => item.TryParseInt()).Where(id => id != 0)) { tempListIds.Add(id); selectedPropertyIDs.Add(id); } if (tempListIds.Count > 0) { _paging.Where("AND Exists( select 1 from [Catalog].[ProductPropertyValue] where [Product].[ProductID] = [ProductID] and PropertyValueID IN ({0}))", tempListIds.ToArray()); } } filterProperty.SelectedPropertyIDs = selectedPropertyIDs; } else { filterProperty.SelectedPropertyIDs = new List <int>(); } var rangeIds = new Dictionary <int, KeyValuePair <float, float> >(); var rangeQueries = Request.QueryString.AllKeys.Where( p => p != null && p.StartsWith("prop_") && (p.EndsWith("_min") || p.EndsWith("_max"))).ToList(); foreach (var rangeQuery in rangeQueries) { if (rangeQuery.EndsWith("_max")) { continue; } var propertyId = rangeQuery.Split('_')[1].TryParseInt(); if (propertyId == 0) { continue; } var min = Request.QueryString[rangeQuery].TryParseFloat(); var max = Request.QueryString[rangeQuery.Replace("min", "max")].TryParseFloat(); rangeIds.Add(propertyId, new KeyValuePair <float, float>(min, max)); } if (rangeIds.Count > 0) { foreach (var i in rangeIds.Keys) { _paging.Where("AND Exists( select 1 from [Catalog].[ProductPropertyValue] "); _paging.Where("inner Join [Catalog].[PropertyValue] on [PropertyValue].[PropertyValueID] = [ProductPropertyValue].[PropertyValueID]"); _paging.Where("where [Product].[ProductID] = [ProductID] and PropertyId = {0}", i); _paging.Where("And RangeValue >= {0}", rangeIds[i].Key); _paging.Where("And RangeValue <= {0})", rangeIds[i].Value); } } filterProperty.SelectedRangePropertyIDs = rangeIds; switch (Request["available"]) { case "1": filterExtra.AvailableSelected = true; break; case "0": filterExtra.AvailableSelected = false; break; default: filterExtra.AvailableSelected = SettingsCatalog.AvaliableFilterSelected; break; } if (filterExtra.AvailableSelected) { _paging.Where("AND MaxAvailable>{0}", 0); } switch (Request["preorder"]) { case "1": filterExtra.PreOrderSelected = true; break; case "0": filterExtra.PreOrderSelected = false; break; default: filterExtra.PreOrderSelected = SettingsCatalog.PreorderFilterSelected; break; } if (filterExtra.PreOrderSelected) { _paging.Where("AND AllowPreOrder={0}", true); _paging.Where("AND MaxAvailable={0}", false); } }