コード例 #1
0
        /// <summary>
        /// Resolves an imageUrl from an id.
        /// </summary>
        /// <param name="contentId">Id of a sitecore item.</param>
        /// <returns>Link to an .ashx which resolves to an image.</returns>
        /// <remarks>Url must be absolute and return an .ashx page which is the way that SiteCore stores and resolves images.</remarks>
        public virtual UCommerce.Content.Content GetImage(string contentId)
        {
            var content = new UCommerce.Content.Content
            {
                Id   = contentId,
                Name = "",
                Url  = ""
            };

            if (string.IsNullOrEmpty(contentId))
            {
                return(content);
            }

            var item = GetItemFromId(contentId);

            if (item == null)
            {
                _loggingService.Log <SitecoreContentService>(string.Format("Item with id: {0} was not found. Check that content exists in database", contentId));
                return(content);
            }

            content.Name = item.Name;
            content.Url  = MediaManager.GetMediaUrl(item, new MediaUrlOptions {
                AlwaysIncludeServerUrl = true
            });
            content.Icon = item.Appearance.Icon;

            return(content);
        }
コード例 #2
0
        /// <summary>
        /// Resolves a ContentUrl from an id.
        /// </summary>
        /// <param name="contentId">Id of a sitecore item.</param>
        /// <returns>Url to a given item from sitecore.</returns>
        public virtual UCommerce.Content.Content GetContent(string contentId)
        {
            var content = new UCommerce.Content.Content
            {
                Id   = contentId,
                Name = "",
                Url  = ""
            };

            if (string.IsNullOrEmpty(contentId))
            {
                return(content);
            }

            var item = GetItemFromId(contentId);

            if (item == null)
            {
                _loggingService.Log <SitecoreContentService>(string.Format("Item with id: {0} was not found. Check that content exists in database", contentId));
                return(content);
            }

            var urlOptions = new Links.UrlOptions()
            {
                AlwaysIncludeServerUrl = true,
                Language = Context.Language,
                Site     = SiteContext.Current
            };

            content.Url = Links.LinkManager.LanguageEmbedding.ToString().ToLower() == "never"
                ? Links.LinkManager.GetDynamicUrl(item, new Links.LinkUrlOptions()
            {
                Language = Context.Language
            })
                : Links.LinkManager.GetItemUrl(item, urlOptions);

            content.Icon = "/~/icon/" + item.Appearance.Icon;
            content.Name = item.Name;

            return(content);
        }