Пример #1
0
        /// <summary>
        /// Gets the store.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>
        /// Store.
        /// </returns>
        protected virtual Store GetStore(HttpContext context)
        {
            var loadDefault = true;
            var storeClient = DependencyResolver.Current.GetService <StoreClient>();
            var storeid     = GetStoreIdFromRoute(context.Request.RequestContext.RouteData.Values);

            if (string.IsNullOrEmpty(storeid))
            {
                storeid = GetStoreIdFromUrl(context.Request.Url.Segments);
            }
            Store store = null;

            if (String.IsNullOrEmpty(storeid))
            {
                // try getting store from URL
                storeid = storeClient.GetStoreIdByUrl(context.Request.Url.AbsoluteUri);
                if (String.IsNullOrEmpty(storeid))
                {
                    // try getting store from the cookie
                    storeid = StoreHelper.GetCookieValue(StoreCookie, false);

                    // try getting default store from settings
                    if (String.IsNullOrEmpty(storeid))
                    {
                        storeid = ConfigurationManager.AppSettings["DefaultStore"];
                    }
                }
            }

            if (!String.IsNullOrEmpty(storeid))
            {
                store = storeClient.GetStoreById(storeid);

                if (store != null)
                {
                    if (store.StoreState != (int)StoreState.Closed)
                    {
                        loadDefault = false;
                    }
                    else
                    {
                        store = null;
                    }
                }
            }


            if (store == null)
            {
                if (loadDefault)
                {
                    StoreHelper.ClearCookie(StoreCookie, String.Empty, false);
                    storeid = ConfigurationManager.AppSettings["DefaultStore"];
                    store   = storeClient.GetStoreById(storeid);
                }
                else
                {
                    store = storeClient.GetStores().FirstOrDefault();
                }
            }

            return(store);
        }