private bool ExistsAlready(CategoryFacetManager manager, string categoryBvin, long propertyId)
 {
     var facets = manager.FindByCategory(categoryBvin);
     if (facets != null)
     {
         var count = facets.Where(y => y.PropertyId == propertyId).Count();
         if (count > 0)
         {
             return true;
         }
     }
     return false;
 }
        public ActionResult DrillDownIndex(string slug)
        {
            ViewBag.BodyClass = "store-categorydrilldown-page";

            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug,
                                                                               MTApp.CurrentRequestContext.CurrentStore.Id);

            if (cat == null)
            {
                cat = new Category();
            }

            ViewBag.Title = cat.MetaTitle;
            if (String.IsNullOrEmpty(ViewBag.Title))
            {
                ViewBag.Title = cat.Name;
            }
            ViewBag.MetaKeywords    = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;
            ViewBag.DisplayHtml     = TagReplacer.ReplaceContentTags(cat.Description,
                                                                     this.MTApp,
                                                                     "",
                                                                     Request.IsSecureConnection);

            string key = Request.QueryString["node"] ?? string.Empty;

            if (key == "-")
            {
                key = string.Empty;
            }
            ViewBag.Key = key;

            int pageNumber = GetPageNumber();
            int pageSize   = 9;
            int totalItems = 0;



            CategoryPageViewModel model = new CategoryPageViewModel();


            CategoryFacetManager   manager    = CategoryFacetManager.InstantiateForDatabase(MTApp.CurrentRequestContext);
            List <CategoryFacet>   facets     = manager.FindByCategory(cat.Bvin);
            List <ProductProperty> properties = LoadProperties(facets);

            if (key == string.Empty)
            {
                key = CategoryFacetKeyHelper.BuildEmptyKey(facets.Count);
            }
            List <long> parsedKey = CategoryFacetKeyHelper.ParseKeyToList(key);

            List <Product> products = MTApp.CatalogServices.FindProductsMatchingKey(key,
                                                                                    pageNumber,
                                                                                    pageSize,
                                                                                    ref totalItems);

            List <ProductFacetCount> productCounts = manager.FindCountsOfVisibleFacets(key, facets, properties);
            List <long> visibleIds = manager.FindVisibleFacetsIdsForKey(key, facets);

            model.Products                 = PrepProducts(products);
            model.LocalCategory            = cat;
            model.PagerData.PageSize       = pageSize;
            model.PagerData.TotalItems     = totalItems;
            model.PagerData.CurrentPage    = pageNumber;
            model.PagerData.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                                             MTApp.CurrentRequestContext.RoutingContext,
                                                                             "{0}");
            model.PagerData.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                                                  MTApp.CurrentRequestContext.RoutingContext);
            model.SubCategories = PrepSubCategories(MTApp.CatalogServices.Categories.FindVisibleChildren(cat.Bvin));



            StringBuilder sbNotSelected = new StringBuilder();

            List <BreadCrumbItem> extraCrumbs = new List <BreadCrumbItem>();

            for (int i = 0; i < facets.Count; i++)
            {
                if (visibleIds.Contains(facets[i].Id))
                {
                    // Find the property that matches the facet
                    var p = (from pr in properties
                             where pr.Id == facets[i].PropertyId
                             select pr).SingleOrDefault();
                    if (p != null)
                    {
                        if (parsedKey[i] < 1)
                        {
                            // not selected
                            this.RenderNonSelection(sbNotSelected, i, parsedKey[i], key, facets[i], p, productCounts, model);
                        }
                        else
                        {
                            // selected
                            this.RenderSelection(sbNotSelected, i, parsedKey[i], key, facets[i], p, facets, model, extraCrumbs);
                        }
                    }
                }
            }

            ViewBag.ExtraCrumbs = extraCrumbs;
            ViewBag.Filters     = sbNotSelected.ToString();



            // Banner
            if (cat.BannerImageUrl.Trim().Length > 0)
            {
                ViewBag.ShowBanner = true;
                ViewBag.BannerUrl  = MerchantTribe.Commerce.Storage.DiskStorage.CategoryBannerUrl(
                    MTApp,
                    cat.Bvin,
                    cat.BannerImageUrl,
                    Request.IsSecureConnection);
            }
            else
            {
                ViewBag.ShowBanner = false;
            }

            // Record Category View
            MerchantTribe.Commerce.SessionManager.CategoryLastId = cat.Bvin;

            return(View("DrillDown", model));
        }
        private void RenderChildren(long id, List<CategoryFacet> allFacets, StringBuilder sb, CategoryFacetManager manager)
        {

            List<CategoryFacet> children = manager.FindByParentInList(allFacets, id);
            if (children == null) return;
            if (children.Count > 0)
            {
                sb.Append("<div id=\"children" + id.ToString() + "\" class=\"ui-sortable nested\" unselectable=\"on\" style=\"-moz-user-select: none;\">");
                foreach (CategoryFacet child in children)
                {

                    sb.Append("<div id=\"" + child.Id.ToString() + "\" class=\"dragitem2\">");
                    sb.Append("<table width=\"100%\" class=\"formtable\">");
                    sb.Append("<tbody><tr><td>");
                    sb.Append("<a href=\"#\">" + child.FilterName + "</a>");
                    //sb.Append("<br /><div class=\"nested\">+ new</div>");
                    sb.Append("</td>");
                    sb.Append("<td width=\"75\">");                    
                    //sb.Append("<a href=\"#\">");
                    //sb.Append("<img alt=\"edit\" src=\"/bvadmin/images/buttons/edit.png\"></a>");
                    sb.Append("&nbsp;");
                    sb.Append("</td>");


                    if (manager.FindByParentInList(allFacets, child.Id).Count > 0)
                    {
                        sb.Append("<td width=\"30\">&nbsp;</td>");
                    }
                    else
                    {
                        sb.Append("<td width=\"30\"><a id=\"rem" + child.Id.ToString() + "\" class=\"trash\" href=\"#\">");
                        sb.Append("<img alt=\"Delete\" src=\"/images/system/trashcan.png\"></a></td>");
                    }


                    sb.Append("<td width=\"30\"><a class=\"handle\" href=\"#\">");
                    sb.Append("<img alt=\"Move\" src=\"/images/system/draghandle.png\"></a></td></tr></tbody></table>");
                    RenderChildren(child.Id, allFacets, sb, manager);
                    sb.Append("</div>");
                }
                sb.Append("</div>");
            }
        }
Exemple #4
0
        private void RenderChildren(long id, List <CategoryFacet> allFacets, StringBuilder sb, CategoryFacetManager manager)
        {
            List <CategoryFacet> children = manager.FindByParentInList(allFacets, id);

            if (children == null)
            {
                return;
            }
            if (children.Count > 0)
            {
                sb.Append("<div id=\"children" + id.ToString() + "\" class=\"ui-sortable nested\" unselectable=\"on\" style=\"-moz-user-select: none;\">");
                foreach (CategoryFacet child in children)
                {
                    sb.Append("<div id=\"" + child.Id.ToString() + "\" class=\"dragitem2\">");
                    sb.Append("<table width=\"100%\" class=\"formtable\">");
                    sb.Append("<tbody><tr><td>");
                    sb.Append("<a href=\"#\">" + child.FilterName + "</a>");
                    //sb.Append("<br /><div class=\"nested\">+ new</div>");
                    sb.Append("</td>");
                    sb.Append("<td width=\"75\">");
                    //sb.Append("<a href=\"#\">");
                    //sb.Append("<img alt=\"edit\" src=\"/hcc/admin/images/buttons/edit.png\"></a>");
                    sb.Append("&nbsp;");
                    sb.Append("</td>");


                    if (manager.FindByParentInList(allFacets, child.Id).Count > 0)
                    {
                        sb.Append("<td width=\"30\">&nbsp;</td>");
                    }
                    else
                    {
                        sb.Append("<td width=\"30\"><a id=\"rem" + child.Id.ToString() + "\" class=\"trash\" href=\"#\">");
                        sb.Append("<img alt=\"Delete\" src=\"/hcc/images/system/trashcan.png\"></a></td>");
                    }


                    sb.Append("<td width=\"30\"><a class=\"handle\" href=\"#\">");
                    sb.Append("<img alt=\"Move\" src=\"/hcc/images/system/draghandle.png\"></a></td></tr></tbody></table>");
                    RenderChildren(child.Id, allFacets, sb, manager);
                    sb.Append("</div>");
                }
                sb.Append("</div>");
            }
        }