protected virtual List <CategorySnapshot> ListPocoSnapshot(IQueryable <Data.EF.bvc_Category> items) { List <CategorySnapshot> result = new List <CategorySnapshot>(); if (items != null) { foreach (Data.EF.bvc_Category item in items) { CategorySnapshot temp = new CategorySnapshot(); temp.Bvin = item.bvin; temp.CustomPageId = item.CustomPageId; temp.CustomPageLayout = (CustomPageLayoutType)item.CustomPageLayout; temp.CustomPageOpenInNewWindow = (item.CustomPageNewWindow == 1); temp.CustomPageUrl = item.CustomPageURL; temp.Hidden = (item.Hidden == 1); temp.ImageUrl = item.ImageURL; temp.LatestProductCount = item.LatestProductCount; temp.Name = item.Name; temp.ParentId = item.ParentID; temp.RewriteUrl = item.RewriteUrl; temp.ShowInTopMenu = (item.ShowInTopMenu == 1); temp.SourceType = (CategorySourceType)item.SourceType; temp.StoreId = item.StoreId; temp.SortOrder = item.SortOrder; temp.MetaTitle = item.MetaTitle; result.Add(temp); } } 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 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; }
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>")); } } }
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 void AddCategoryLink(CategorySnapshot c) { HyperLink m = new HyperLink(); m.ToolTip = c.MetaTitle; m.Text = c.Name; m.NavigateUrl = MerchantTribe.Commerce.Utilities.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 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 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 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 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 CategoryPeerSet GetPeerSet(List<CategorySnapshot> allCats, CategorySnapshot cat) { CategoryPeerSet result = new CategoryPeerSet(); CategorySnapshot 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; }
private void AddCategoryName(CategorySnapshot c) { this.TrailPlaceholder.Controls.Add(new LiteralControl("<span class=\"current\">" + c.Name + "</span>")); }
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); }