Exemple #1
0
        public override void Process(RenderRenderingArgs args)
        {
            if (args.Rendered || HttpContext.Current == null || (!args.Cacheable || args.Rendering.RenderingItem == null))
            {
                return;
            }

            var obj = args.PageContext.Database.GetItem(args.Rendering.RenderingItem.ID);

            if (obj == null || obj["VaryByStoreCatalog"] != "1")
            {
                return;
            }

            var storeHelper = new StoreHelper();
            var storeId     = storeHelper.GetCookie()?.StoreId ?? ((BackEnd.Catalog.Models.CommerceStorefront)StorefrontContext.CurrentStorefront).DefaultStoreID;

            if (string.IsNullOrWhiteSpace(args.CacheKey))
            {
                args.CacheKey = string.Format(CultureInfo.InvariantCulture, "_#varyByStoreCatalog_{0}_{1}_{2}_{3}_{4}", Context.Site.Name, Context.Language.Name, HttpContext.Current.Request.Url.AbsoluteUri, args.Rendering.RenderingItem.ID.ToString(), storeId);
            }
            else
            {
                args.CacheKey = string.Format(CultureInfo.InvariantCulture, "_#varybyStoreCatalog_{0}_{1}_{2}", args.CacheKey, args.Rendering.RenderingItem.ID.ToString(), storeId);
            }
        }
Exemple #2
0
        public override List <Item> GetNavigationCategories()
        {
            var objList = new List <Item>();

            try
            {
                var index       = CommerceTypeLoader.CreateInstance <ICommerceSearchManager>().GetIndex();
                var storeHelper = new StoreHelper();
                var storeId     = storeHelper.GetCookie()?.StoreId ?? ((Models.CommerceStorefront)StorefrontContext.CurrentStorefront).DefaultStoreID;
                var idString    = ((Models.CommerceStorefront)StorefrontContext.CurrentStorefront).GetStartNavigationCategoryID(storeId).Guid.ToString();
                using (var searchContext = index.CreateSearchContext(SearchSecurityOptions.Default))
                {
                    var list = searchContext.GetQueryable <CommerceCategorySearchResultItem>()
                               .Where(item => item.SitecoreId == idString)
                               .Where(item => item.Language == CurrentLanguageName)
                               .Select(p => p).ToList();
                    if (list.Count > 0)
                    {
                        objList = ExtractChildrenCategories(list[0]);
                    }
                }
            }
            catch (DirectoryNotFoundException ex)
            {
                Helpers.LogErrorMessage(StorefrontContext.GetSystemMessage("Search Index Directory Not Found Error", true), ex, ex);
            }
            catch (IndexNotFoundException ex)
            {
                Helpers.LogErrorMessage(StorefrontContext.GetSystemMessage("Search Index Not Found Error", true), ex, ex);
            }
            catch
            {
                throw;
            }

            return(objList);
        }