示例#1
0
        /// <summary>
        /// Checks to see if there is a catalog item that maps to the current id
        /// </summary>
        /// <param name="itemId">The ID of the catalog item.</param>
        /// <param name="catalogName">The name of the catalog that contains the catalog item.</param>
        /// <param name="isProduct">Specifies whether the item is a product.</param>
        /// <returns>An item if found, otherwise null</returns>
        public static Sitecore.Data.Items.Item ResolveCatalogItem(string itemId, string catalogName, bool isProduct)
        {
            Sitecore.Data.Items.Item foundItem = null;

            // If we make it here, the right route was used, but might have an empty value
            if (!string.IsNullOrEmpty(itemId))
            {
                var            cachekey      = "FriendlyUrl-" + itemId + "-" + catalogName;
                ICacheProvider cacheProvider = CommerceTypeLoader.GetCacheProvider(CommerceConstants.KnownCacheNames.FriendlyUrlsCache);
                var            id            = cacheProvider.GetData <ID>(CommerceConstants.KnownCachePrefixes.Sitecore, CommerceConstants.KnownCacheNames.FriendlyUrlsCache, cachekey);

                if (ID.IsNullOrEmpty(id) || id == ID.Undefined)
                {
                    if (isProduct)
                    {
                        foundItem = SearchNavigation.GetProduct(itemId, catalogName);
                    }
                    else
                    {
                        foundItem = SearchNavigation.GetCategory(itemId, catalogName);
                    }

                    if (foundItem != null)
                    {
                        cacheProvider.AddData <ID>(CommerceConstants.KnownCachePrefixes.Sitecore, CommerceConstants.KnownCacheNames.FriendlyUrlsCache, cachekey, foundItem.ID);
                    }
                    else
                    {
                        cacheProvider.AddData <ID>(CommerceConstants.KnownCachePrefixes.Sitecore, CommerceConstants.KnownCacheNames.FriendlyUrlsCache, cachekey, ID.Undefined);
                    }
                }
                else if (id != ID.Undefined && id != ID.Null)
                {
                    foundItem = Context.Database.GetItem(id);
                }
            }

            return(foundItem);
        }