private void LoadTrailForCategory(BreadCrumbViewModel model, CategorySnapshot cat, bool linkAll) { if (cat == null) { return; } if (cat.Hidden) { return; } var allCats = HccApp.CatalogServices.Categories.FindAllSnapshotsPaged(1, int.MaxValue); var trail = Category.BuildTrailToRoot(cat.Bvin, HccApp.CatalogServices.Categories); if (trail == null) { return; } // Walk list backwards for (var j = trail.Count - 1; j >= 0; j += -1) { if (j != 0 || linkAll) { model.Items.Enqueue(AddCategoryLink(trail[j])); } else { model.Items.Enqueue(new BreadCrumbItem { Name = trail[j].Name }); } } }
private void BuildParentTrail(List <CategorySnapshot> allCats, string currentId, ref List <CategorySnapshot> trail) { if (currentId == "0" || currentId == string.Empty) { return; } CategorySnapshot current = Category.FindInList(allCats, currentId); if (current != null) { trail.Add(current); if (current.ParentId == "0") { return; } if (current.ParentId != null) { if (current.ParentId != string.Empty) { BuildParentTrail(allCats, current.ParentId, ref trail); } } } }
private void LoadCategory(SingleCategoryViewModel model, string categoryId) { var c = HccApp.CatalogServices.Categories.Find(categoryId); if (c != null) { var catSnapshot = new CategorySnapshot(c); var destination = UrlRewriter.BuildUrlForCategory(catSnapshot); var imageUrl = DiskStorage.CategoryIconUrl(HccApp, c.Bvin, c.ImageUrl, Request.IsSecureConnection); model.IconUrl = ImageHelper.SafeImage(imageUrl); model.LinkUrl = destination; model.AltText = c.MetaTitle; model.Name = c.Name; model.LocalCategory = catSnapshot; if (c.SourceType == CategorySourceType.CustomLink) { model.OpenInNewWindow = c.CustomPageOpenInNewWindow; } } }
private BreadCrumbItem AddCategoryLink(CategorySnapshot c) { BreadCrumbItem result = new BreadCrumbItem(); result.Name = c.Name; result.Title = c.MetaTitle; result.Link = UrlRewriter.BuildUrlForCategory(c, MTApp.CurrentRequestContext.RoutingContext); return(result); }
protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); string categoryId = SessionManager.CategoryLastId; CategorySnapshot currentCategory = null; currentCategory = new CategorySnapshot(MyPage.MTApp.CatalogServices.Categories.Find(categoryId)); LoadTrail(currentCategory); }
private BreadCrumbItem AddCategoryLink(CategorySnapshot c) { var result = new BreadCrumbItem { Name = c.Name, Title = c.MetaTitle, Link = UrlRewriter.BuildUrlForCategory(c) }; return(result); }
public void LoadTrail(CategorySnapshot category) { this.TrailPlaceholder.Controls.Clear(); if ((category != null)) { List <CategorySnapshot> allCats = MyPage.MTApp.CatalogServices.Categories.FindAllPaged(1, int.MaxValue); if (!category.Hidden) { this.TrailPlaceholder.Controls.Add(new LiteralControl("<div class=\"singletrail\">")); List <CategorySnapshot> trail = new List <CategorySnapshot>(); if (category != null && category.Bvin != string.Empty) { trail = Category.BuildTrailToRoot(category.Bvin, MyPage.MTApp.CurrentRequestContext); } HyperLink m = new HyperLink(); m.CssClass = "home"; m.ToolTip = SiteTerms.GetTerm(SiteTermIds.Home); m.Text = SiteTerms.GetTerm(SiteTermIds.Home); m.NavigateUrl = this.Page.ResolveUrl("~/Default.aspx"); m.EnableViewState = false; this.TrailPlaceholder.Controls.Add(m); this.TrailPlaceholder.Controls.Add(new LiteralControl("<span class=\"spacer\">" + _Spacer + "</span>")); if (trail != null) { // Walk list backwards for (int j = trail.Count - 1; j >= 0; j += -1) { if (j != trail.Count - 1) { this.TrailPlaceholder.Controls.Add(new LiteralControl("<span class=\"spacer\">" + _Spacer + "</span>")); } if (j != 0) { AddCategoryLink(trail[j]); } else { AddCategoryLink(trail[j]); } } } this.TrailPlaceholder.Controls.Add(ExtrasLiteral); this.TrailPlaceholder.Controls.Add(new LiteralControl("</div>")); } } }
private CategoryPeerSet GetPeerSet(List <CategorySnapshot> allCats, CategorySnapshot cat) { var result = new CategoryPeerSet(); var parent = Category.FindInList(allCats, cat.ParentId); if (parent != null) { result.Parents = Category.FindChildrenInList(allCats, parent.ParentId, false); } result.Peers = Category.FindChildrenInList(allCats, cat.ParentId, false); result.Children = Category.FindChildrenInList(allCats, cat.Bvin, false); return(result); }
public static string BuildUrlForCategory(CategorySnapshot c, string pageNumber, object additionalParams = null) { if (c.SourceType == CategorySourceType.CustomLink) { if (c.CustomPageUrl != string.Empty) { return(c.CustomPageUrl); } } var parameters = Merge(new { slug = c.RewriteUrl, page = pageNumber }, additionalParams); var routeValues = new RouteValueDictionary(parameters); return(HccUrlBuilder.RouteHccUrl(HccRoute.Category, routeValues)); }
public ActionResult CategoryTrail(Category cat, List <BreadCrumbItem> extras) { var snap = new CategorySnapshot(cat); var model = new BreadCrumbViewModel(); LoadTrailForCategory(model, snap, false); if (extras != null && extras.Count > 0) { foreach (var item in extras) { model.Items.Enqueue(item); } } return(View("BreadCrumb", model)); }
private void LoadTrailForProduct(BreadCrumbViewModel model, Product p) { if (p == null) { return; } CategorySnapshot currentCategory = null; var cats = HccApp.CatalogServices.FindCategoriesForProduct(p.Bvin); if (cats.Count > 0) { currentCategory = cats[0]; } LoadTrailForCategory(model, currentCategory, true); model.Items.Enqueue(new BreadCrumbItem { Name = p.ProductName }); }
private void LoadTrailForProduct(BreadCrumbViewModel model, Product p, MerchantTribeApplication app) { if (p == null) { return; } CategorySnapshot currentCategory = null; List <CategorySnapshot> cats = app.CatalogServices.FindCategoriesForProduct(p.Bvin); if ((cats.Count > 0)) { currentCategory = cats[0]; } LoadTrailForCategory(model, currentCategory, true, app); model.Items.Enqueue(new BreadCrumbItem() { Name = p.ProductName }); }
private void AddCategoryLink(CategorySnapshot c) { HyperLink m = new HyperLink(); m.ToolTip = c.MetaTitle; m.Text = c.Name; m.NavigateUrl = UrlRewriter.BuildUrlForCategory(c, MyPage.MTApp.CurrentRequestContext.RoutingContext); if (c.SourceType == CategorySourceType.CustomLink) { if (c.CustomPageOpenInNewWindow == true) { m.Target = "_blank"; } } m.EnableViewState = false; this.TrailPlaceholder.Controls.Add(m); }
public ActionResult CategoryTrail(Category cat, List <BreadCrumbItem> extras) { CategorySnapshot snap = new CategorySnapshot(cat); BreadCrumbViewModel model = new BreadCrumbViewModel(); model.HomeName = MerchantTribe.Commerce.Content.SiteTerms.GetTerm(MerchantTribe.Commerce.Content.SiteTermIds.Home); LoadTrailForCategory(model, snap, false); if (extras != null) { foreach (BreadCrumbItem item in extras) { model.Items.Enqueue(item); } } return(View("BreadCrumb", model)); }
private void AddCategoryLink(CategorySnapshot c) { var m = new HyperLink { ToolTip = c.MetaTitle, Text = c.Name, NavigateUrl = UrlRewriter.BuildUrlForCategory(c) }; if (c.SourceType == CategorySourceType.CustomLink) { if (c.CustomPageOpenInNewWindow) { m.Target = "_blank"; } } m.EnableViewState = false; TrailPlaceholder.Controls.Add(m); }
public string RenderCategory(MerchantTribeApplication app, List <BreadCrumbItem> extras, Category cat) { CategorySnapshot snap = new CategorySnapshot(cat); BreadCrumbViewModel model = new BreadCrumbViewModel(); model.HomeName = MerchantTribe.Commerce.Content.SiteTerms.GetTerm(MerchantTribe.Commerce.Content.SiteTermIds.Home); LoadTrailForCategory(model, snap, false, app); if (extras != null && extras.Count > 0) { foreach (BreadCrumbItem item in extras) { model.Items.Enqueue(item); } } return(Render(app, model)); }
private void AddSingleLink(CategoryMenuViewModel model, CategorySnapshot c, List <CategorySnapshot> allCats) { if (c.Bvin == model.CurrentId) { model.sb.Append("<li class=\"current\">"); } else { model.sb.Append("<li>"); } string title = c.MetaTitle; string text = c.Name; int childCount = 0; if (model.ShowProductCounts) { childCount += (MTApp.CatalogServices.CategoriesXProducts.FindForCategory(c.Bvin, 1, int.MaxValue).Count); } if (model.ShowCategoryCounts) { childCount += Category.FindChildrenInList(allCats, c.Bvin, false).Count; } if (childCount > 0) { text += " (" + childCount.ToString() + ")"; } string url = UrlRewriter.BuildUrlForCategory(c, MTApp.CurrentRequestContext.RoutingContext); bool openNew = false; if (c.SourceType == CategorySourceType.CustomLink) { openNew = c.CustomPageOpenInNewWindow; } model.sb.Append("<a href=\"" + url + "\" title=\"" + title + "\">" + text + "</a>"); }
private CategoryMenuItemViewModel BuildPeersAndChildren(CategoryPeerSet neighbors, CategorySnapshot currentCategory, bool isDisplayProductsCount) { var result = new CategoryMenuItemViewModel(); foreach (var peer in neighbors.Peers) { var item = new CategoryMenuItemViewModel(); item.Title = peer.Name; item.Description = peer.Description; item.Url = UrlRewriter.BuildUrlForCategory(peer); if (peer.Bvin == currentCategory.Bvin) { item.IsCurrent = true; // Load Children foreach (var c in neighbors.Children) { var childItem = new CategoryMenuItemViewModel(); childItem.Title = c.Name; childItem.Description = c.Description; if (isDisplayProductsCount) { item.Bvin = c.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(c.Bvin, false); } childItem.Url = UrlRewriter.BuildUrlForCategory(c); item.Items.Add(childItem); } } if (isDisplayProductsCount) { item.Bvin = peer.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(peer.Bvin, false); } result.Items.Add(item); } return(result); }
private CategoryMenuItemViewModel BuildParentsPeersChildren(CategoryPeerSet neighbors, CategorySnapshot currentCategory, bool isDisplayProductsCount) { CategoryMenuItemViewModel result; if (neighbors.Parents.Count > 0) { result = new CategoryMenuItemViewModel(); foreach (var parent in neighbors.Parents) { CategoryMenuItemViewModel item; if (parent.Bvin == currentCategory.ParentId) { item = BuildPeersAndChildren(neighbors, currentCategory, isDisplayProductsCount); } else { item = new CategoryMenuItemViewModel(); } item.Title = parent.Name; item.Description = parent.Description; item.Url = UrlRewriter.BuildUrlForCategory(parent); if (isDisplayProductsCount) { item.Bvin = parent.Bvin; item.ProductsCount = HccApp.CatalogServices.FindProductCountsForCategory(parent.Bvin, false); } result.Items.Add(item); } } else { result = BuildPeersAndChildren(neighbors, currentCategory, isDisplayProductsCount); } return(result); }
private void LoadTrailForCategory(BreadCrumbViewModel model, CategorySnapshot cat, bool linkAll) { if (cat == null) { return; } if (cat.Hidden) { return; } List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAllPaged(1, int.MaxValue); List <CategorySnapshot> trail = new List <CategorySnapshot>(); trail = Category.BuildTrailToRoot(cat.Bvin, MTApp.CurrentRequestContext); if (trail == null) { return; } // Walk list backwards for (int j = trail.Count - 1; j >= 0; j += -1) { if (j != 0 || linkAll == true) { model.Items.Enqueue(AddCategoryLink(trail[j])); } else { model.Items.Enqueue(new BreadCrumbItem() { Name = trail[j].Name }); } } }
private void RenderParentsPeersChildren(CategoryMenuViewModel model, CategoryPeerSet neighbors, CategorySnapshot currentCategory, List <CategorySnapshot> allCats) { if (neighbors.Parents.Count < 1) { RenderPeersChildren(model, neighbors, currentCategory, allCats); } else { // Add Parents foreach (CategorySnapshot parent in neighbors.Parents) { if (!parent.Hidden) { AddSingleLink(model, parent, allCats); // Add Peers if (parent.Bvin == currentCategory.ParentId) { bool peerInitialized = false; foreach (CategorySnapshot peer in neighbors.Peers) { if (!peer.Hidden) { if (!peerInitialized) { model.sb.Append("<ul>"); peerInitialized = true; } AddSingleLink(model, peer, allCats); if (peer.Bvin == currentCategory.Bvin) { // Load Children if (neighbors.Children.Count > 0) { bool childInitialized = false; foreach (CategorySnapshot child in neighbors.Children) { if (!child.Hidden) { if (!childInitialized) { model.sb.Append("<ul>" + System.Environment.NewLine); childInitialized = true; } AddSingleLink(model, child, allCats); model.sb.Append("</li>" + System.Environment.NewLine); } } if (childInitialized) { model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>" + System.Environment.NewLine); } } if (peerInitialized) { model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>" + System.Environment.NewLine); } } }
private void RenderPeersChildren(CategoryMenuViewModel model, CategoryPeerSet neighbors, CategorySnapshot currentCategory, List <CategorySnapshot> allCats) { // No Parents, start with peers foreach (CategorySnapshot peer in neighbors.Peers) { if (!peer.Hidden) { AddSingleLink(model, peer, allCats); if (peer.Bvin == currentCategory.Bvin) { // Load Children if (neighbors.Children.Count > 0) { bool initialized = false; foreach (CategorySnapshot child in neighbors.Children) { if (!child.Hidden) { if (!initialized) { model.sb.Append("<ul>" + System.Environment.NewLine); initialized = true; } AddSingleLink(model, child, allCats); model.sb.Append("</li>" + System.Environment.NewLine); } } if (initialized) { model.sb.Append("</ul>" + System.Environment.NewLine); } } } model.sb.Append("</li>" + System.Environment.NewLine); } } }
private void LoadPeersAndChildren(CategoryMenuViewModel model) { List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAll(); // Get Current Category CategorySnapshot currentCategory = Category.FindInList(allCats, model.CurrentId); // Trick system into accepting root category of zero which never exists in database if (model.CurrentId == "0") { currentCategory = new CategorySnapshot(); currentCategory.Bvin = "0"; } if (currentCategory != null) { if (currentCategory.Bvin != string.Empty) { model.CurrentId = currentCategory.Bvin; } // Find the trail from this category back to the root of the site List <CategorySnapshot> trail = new List <CategorySnapshot>(); BuildParentTrail(allCats, model.CurrentId, ref trail); if (trail == null) { trail = new List <CategorySnapshot>(); } if (trail.Count < 1) { // Load Roots Only LoadRoots(model); } else { CategoryPeerSet neighbors = GetPeerSet(allCats, currentCategory); if (trail.Count == 1) { // special case where we want only peers and children RenderPeersChildren(model, neighbors, currentCategory, allCats); } else { if (trail.Count >= 3) { if (neighbors.Children.Count < 1) { // Special case where we are at the end of the tree and have // no children. Reset neighbors to parent's bvin CategorySnapshot parent = Category.FindInList(allCats, currentCategory.ParentId); if (parent == null) { parent = new CategorySnapshot(); } neighbors = GetPeerSet(allCats, parent); RenderParentsPeersChildren(model, neighbors, trail[1], allCats); } else { RenderParentsPeersChildren(model, neighbors, currentCategory, allCats); } } else { // normal load of peers RenderParentsPeersChildren(model, neighbors, currentCategory, allCats); } } } } else { model.sb.Append("Invalid Category Id. Contact Administrator"); } }
private void LoadRootPlusExpandedChildren(CategoryMenuViewModel model) { List <CategorySnapshot> allCats = MTApp.CatalogServices.Categories.FindAll(); // Get Current Category CategorySnapshot currentCategory = Category.FindInList(allCats, model.CurrentId); if (currentCategory != null) { if (currentCategory.Bvin != string.Empty) { model.CurrentId = currentCategory.Bvin; } // Find the trail from this category back to the root of the site List <CategorySnapshot> trail = new List <CategorySnapshot>(); BuildParentTrail(allCats, model.CurrentId, ref trail); if (trail == null) { trail = new List <CategorySnapshot>(); } if (trail.Count < 1) { // Load Roots Only LoadRoots(model); } else { string StartingRootCategoryId = currentCategory.Bvin; StartingRootCategoryId = trail[trail.Count - 1].Bvin; List <CategorySnapshot> roots = Category.FindChildrenInList(allCats, "0", false); if (roots != null) { model.sb.Append("<ul>" + System.Environment.NewLine); foreach (CategorySnapshot c in roots) { if (IsInTrail(c.Bvin, trail)) { AddSingleLink(model, c, allCats); List <CategorySnapshot> children = new List <CategorySnapshot>(); children = Category.FindChildrenInList(allCats, StartingRootCategoryId, false); if (children != null) { model.sb.Append("<ul>" + System.Environment.NewLine); ExpandInTrail(model, allCats, children, trail); model.sb.Append("</ul>" + System.Environment.NewLine); } model.sb.Append("</li>"); break; } } model.sb.Append("</ul>" + System.Environment.NewLine); } } } else { model.sb.Append("Invalid Category Id. Contact Administrator"); } }
public static string BuildUrlForCategory(CategorySnapshot c, RequestContext routingContext, string pageNumber, object additionalParams = null) { return(BuildUrlForCategory(c, pageNumber, additionalParams)); }
private void AddCategoryName(CategorySnapshot c) { TrailPlaceholder.Controls.Add(new LiteralControl("<span class=\"current\">" + c.Name + "</span>")); }
public static string BuildUrlForCategoryFull(CategorySnapshot c, HotcakesApplication app) { return(BuildUrlForCategory(c)); }