protected void PrimeCacheImpl() { ICatalogSystem catalog = ServiceLocator.Current.GetInstance <ICatalogSystem>(); IContentRepository repository = ServiceLocator.Current.GetInstance <IContentRepository>(); ReferenceConverter referenceConverter = ServiceLocator.Current.GetInstance <ReferenceConverter>(); CatalogContentLoader contentLoader = ServiceLocator.Current.GetInstance <CatalogContentLoader>(); // Get all catalogs CatalogDto catalogDto = catalog.GetCatalogDto(); _log.Debug("Found {0} catalogs. Start iterating.", catalogDto.Catalog.Count); foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog) { _log.Debug("Loading all categories for catalog {0} ({1})", catalogRow.Name, catalogRow.CatalogId); // Get all Categories on first level CatalogNodes nodes = catalog.GetCatalogNodes(catalogRow.CatalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo)); _log.Debug("Loaded {0} categories using ICatalogSystem", nodes.CatalogNode.Count()); // Get them as content too foreach (CatalogNode node in nodes.CatalogNode) { ContentReference nodeReference = referenceConverter.GetContentLink(node.CatalogNodeId, CatalogContentType.CatalogNode, 0); NodeContent content = repository.Get <EPiServer.Commerce.Catalog.ContentTypes.NodeContent>(nodeReference); _log.Debug("Loded Category Content: {0}", content.Name); WalkCategoryTree(content, repository, contentLoader, catalog, referenceConverter); } } }
/// <summary> /// Gets the catalog nodes. Results are cached. /// </summary> /// <param name="catalogName">Name of the catalog.</param> /// <param name="parentNodeCode">The parent node code.</param> /// <param name="responseGroup">The response group.</param> /// <returns></returns> internal static CatalogNodes GetCatalogNodes(string catalogName, string parentNodeCode, CatalogNodeResponseGroup responseGroup) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = CatalogCache.CreateCacheKey("catalognodes-catalogname-code", responseGroup.CacheKey, catalogName, parentNodeCode); CatalogNodes nodes = new CatalogNodes(); // check cache first object cachedObject = CatalogCache.Get(cacheKey); if (cachedObject != null) { nodes = (CatalogNodes)cachedObject; } else { CatalogNodeDto dto = GetCatalogNodesDto(catalogName, parentNodeCode, responseGroup); // Load Node if (dto.CatalogNode.Count > 0) { nodes = LoadNodes(dto, null, false, responseGroup); } CatalogCache.Insert(cacheKey, nodes, CatalogConfiguration.Instance.Cache.CatalogNodeTimeout); } return(nodes); }
/// <summary> /// Loads the nodes. /// </summary> /// <param name="dto">The dto.</param> /// <param name="parent">The parent.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <param name="responseGroup">The response group.</param> /// <returns></returns> internal static CatalogNodes LoadNodes(CatalogNodeDto dto, CatalogNode parent, bool recursive, CatalogNodeResponseGroup responseGroup) { List <CatalogNode> nodes = new List <CatalogNode>(); foreach (CatalogNodeDto.CatalogNodeRow childRow in dto.CatalogNode) { CatalogNode childNode = LoadNode(childRow, recursive, responseGroup); childNode.ParentNode = parent; nodes.Add(childNode); } CatalogNodes n = new CatalogNodes(); n.CatalogNode = nodes.ToArray(); return(n); }
/// <summary> /// When overridden in a derived class, retrieves the child nodes of a specific <see cref="T:System.Web.SiteMapNode"></see>. /// </summary> /// <param name="node">The <see cref="T:System.Web.SiteMapNode"></see> for which to retrieve all child nodes.</param> /// <returns> /// A read-only <see cref="T:System.Web.SiteMapNodeCollection"></see> that contains the immediate child nodes of the specified <see cref="T:System.Web.SiteMapNode"></see>; otherwise, null or an empty collection, if no child nodes exist. /// </returns> public override SiteMapNodeCollection GetChildNodes(SiteMapNode node) { lock (this) { SiteMapNodeCollection col = new SiteMapNodeCollection(); if (node == _RootNode)// root node { CatalogNodes nodes = CatalogContext.Current.GetCatalogNodes(CatalogName); if (nodes.CatalogNode != null && nodes.CatalogNode.Length > 0) { foreach (CatalogNode row in nodes.CatalogNode) { col.Add(CreateSiteMapNode(row)); } } } else if (node.Key.IndexOf("c_", 0) == 0) { string[] keys = node.Key.Substring("c_".Length).Split('_'); int catalogNodeId = Int32.Parse(keys[0]); int parentNodeId = Int32.Parse(keys[1]); int catalogId = Int32.Parse(keys[2]); CatalogNodes nodes = CatalogContext.Current.GetCatalogNodes(catalogId, catalogNodeId); if (nodes.CatalogNode != null && nodes.CatalogNode.Length > 0) { foreach (CatalogNode row in nodes.CatalogNode) { col.Add(CreateSiteMapNode(row)); } } } return(col); } }
/// <summary> /// Loads the node. /// </summary> /// <param name="row">The row.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <param name="responseGroup">The response group.</param> /// <returns></returns> internal static CatalogNode LoadNode(/*CatalogNodeDto dto,*/ CatalogNodeDto.CatalogNodeRow row, bool recursive, CatalogNodeResponseGroup responseGroup) { CatalogNode node = null; // Load node if (row != null) { node = new CatalogNode(row); } else { node = new CatalogNode(); } // Populate children if (responseGroup.ContainsGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull) || responseGroup.ContainsGroup(CatalogNodeResponseGroup.ResponseGroup.Children)) { CatalogNodeDto childrenDto = GetCatalogNodesDto(row.CatalogId, row.CatalogNodeId, responseGroup); CatalogNodes nodes = LoadNodes(childrenDto, node, recursive, responseGroup); node.Children = nodes; } return(node); }
protected void Page_Load(object sender, EventArgs e) { CatalogNodes.DataSource = GetCatalogNodeList(); CatalogNodes.DataBind(); DataBind(); }
/// <summary> /// Creates the search criteria. /// </summary> /// <param name="keywords">The keywords.</param> /// <param name="sort">The sort.</param> /// <returns></returns> public CatalogEntrySearchCriteria CreateSearchCriteria(string keywords, SearchSort sort) { NameValueCollection querystring = HttpContext.Current.Request.QueryString; string currentNodeCode = querystring["nc"]; CatalogEntrySearchCriteria criteria = new CatalogEntrySearchCriteria(); if (!String.IsNullOrEmpty(currentNodeCode)) { criteria.CatalogNodes.Add(currentNodeCode); // Include all the sub nodes in our search results CatalogDto catalogs = CatalogContext.Current.GetCatalogDto(CMSContext.Current.SiteId); foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog) { CatalogNodes nodes = CatalogContext.Current.GetCatalogNodes(catalog.Name, querystring["nc"]); if (nodes.CatalogNode != null && nodes.CatalogNode.Length > 0) { foreach (CatalogNode nodeRow in nodes.CatalogNode) { criteria.CatalogNodes.Add(nodeRow.ID); } } } } criteria.SearchPhrase = keywords; criteria.SearchIndex.Add(querystring["filter"]); criteria.Sort = sort; // Add all filters foreach (SearchFilter filter in SearchConfig.SearchFilters) { // Check if we already filtering if (querystring.Get(filter.field) != null) { continue; } criteria.Add(filter); } // Get selected filters SelectedFilter[] filters = SelectedFilters; if (filters.Length != 0) { foreach (SelectedFilter filter in filters) { if (filter.PriceRangeValue != null) { criteria.Add(filter.Filter.field, filter.PriceRangeValue); } if (filter.RangeValue != null) { criteria.Add(filter.Filter.field, filter.RangeValue); } if (filter.SimpleValue != null) { criteria.Add(filter.Filter.field, filter.SimpleValue); } } } return(criteria); }