/// <summary>
    /// Initializes the control properties.
    /// </summary>
    protected void SetupControl()
    {
        if (this.StopProcessing)
        {
            // Do not process
        }
        else
        {
            var category = SiteContext.Current.CatalogContext.CurrentCategory;
            var product  = SiteContext.Current.CatalogContext.CurrentProduct;

            if (category == null && product == null && CurrentDocument.NodeAlias == "Catalog")
            {
                category = ObjectFactory.Instance.Resolve <IDefaultCatalogDataProvider>().GetDefaultCategory();
            }

            if (category == null || product != null)
            {
                return;
            }

            IList <Facet> facetsForQuerying = GetFacets();
            IList <Facet> facets            = SearchLibrary.GetFacetsFor(category, facetsForQuerying);

            rptFacets.DataSource = facets;
            rptFacets.DataBind();
            FindChildControlsRecursive(rptFacets);
            EnsureCheckboxesAreChecked();

            if (!_anyFacetHits)
            {
                facetsDiv.Visible = false;
            }
        }
    }
        private IList <Facet> GetFacetRecursive(Category category, IList <Facet> facetsQuery)
        {
            List <Facet> facets = new List <Facet>();

            foreach (var subCategory in category.Categories)
            {
                var facetsList = GetFacetRecursive(subCategory, facetsQuery);
                if (facetsList != null)
                {
                    facetsList = facetsList.Where(x => x.FacetValues.Any(y => y.Hits > 0)).ToList();
                    if (facetsList.Any())
                    {
                        facets.AddRange(facetsList);
                    }
                }
            }

            var facetListMain = SearchLibrary.GetFacetsFor(category, facetsQuery);

            if (facetListMain.Any())
            {
                facetListMain = facetListMain.Where(x => x.FacetValues.Any(y => y.Hits > 0)).ToList();
                if (facetListMain.Any())
                {
                    facets.AddRange(facetListMain.ToList());
                }
            }

            return(facets);
        }
Ejemplo n.º 3
0
        // GET: Facets
        public ActionResult Index()
        {
            var           category = SiteContext.Current.CatalogContext.CurrentCategory;
            var           facetValueOutputModel = new FacetsDisplayedViewModel();
            IList <Facet> facetsForQuerying     = System.Web.HttpContext.Current.Request.QueryString.ToFacets();

            if (ShouldDisplayFacets(category))
            {
                IList <Facet> facets = SearchLibrary.GetFacetsFor(category, facetsForQuerying);
                if (facets.Any(x => x.FacetValues.Any(y => y.Hits > 0)))
                {
                    facetValueOutputModel.Facets = MapFacets(facets);
                }
            }

            return(View("/Views/PartialView/Facets.cshtml", facetValueOutputModel));
        }
        private IList <FacetViewModel> GetAllFacets(Category category)
        {
            var facetsResolver    = new FacetResolver(this.queryStringBlackList);
            var facetsForQuerying = facetsResolver.GetFacetsFromQueryString();
            IList <UCommerce.Search.Facets.Facet> allFacets;

            if (category != null)
            {
                allFacets = SearchLibrary.GetFacetsFor(category, facetsForQuerying);
            }
            else
            {
                allFacets = SearchLibrary.FacetedQuery()
                            .WithFacets(facetsForQuerying)
                            .ToFacets()
                            .ToList();
            }

            return(this.MapToFacetsViewModel(allFacets));
        }