public IPagedList<ContentItem> LoadContentItemsByUrl(string url, Store store, Language language, Func<string, ContentItem> contentItemFactory, int pageIndex = 1, int pageSize = 10)
 {
     var retVal = new List<ContentItem>();
     var totalCount = 0;
     url = Uri.UnescapeDataString(url);
     var parts = url.Split('/');
     var localPath = _baseLocalPath + "\\" + store.Id + "\\" + String.Join("\\", parts);
     var searchPattern = "*." + language.CultureName + ".*";
     if (!Directory.Exists(localPath))
     {
         localPath = _baseLocalPath + "\\" + store.Id + "\\" + String.Join("\\", parts.Take(parts.Count() - 1));
         searchPattern = parts.Last() + "." + language.CultureName + ".*";
     }
     if (Directory.Exists(localPath))
     {
         var files = Directory.GetFiles(localPath, searchPattern, SearchOption.TopDirectoryOnly)
                                      .Where(x => _extensions.Any(y => x.EndsWith(y)));
         totalCount = files.Count();
         foreach (var file in files.OrderBy(x => x).Skip((pageIndex - 1) * pageSize).Take(pageSize))
         {
             var contentItem = contentItemFactory(GetUrlFromPath(file, url));
             LoadAndRenderContentItemFromFile(contentItem, file);
             retVal.Add(contentItem);
         }
     }
     return new StaticPagedList<ContentItem>(retVal, pageIndex, pageSize, totalCount);
 }
        public static Store ToWebModel(this VirtoCommerce.Client.Model.VirtoCommerceStoreModuleWebModelStore storeDto)
        {
            var retVal = new Store();
            retVal.InjectFrom(storeDto);
            if(storeDto.SeoInfos != null)
            {
                retVal.SeoInfos = storeDto.SeoInfos.Select(x => x.ToWebModel()).ToList();
            }
            retVal.DefaultLanguage = storeDto.DefaultLanguage != null ? new Language(storeDto.DefaultLanguage) : new Language("en-US");
            if(storeDto.Languages != null)
            {
                retVal.Languages = storeDto.Languages.Select(x => new Language(x)).ToList();
            }

            if (storeDto.Currencies != null)
            {
                retVal.Currencies.AddRange(storeDto.Currencies.Select(x => new Currency(Language.InvariantLanguage, x)));
            }
            retVal.DefaultCurrency = retVal.Currencies.FirstOrDefault(x => x.Equals(storeDto.DefaultCurrency));

            if (storeDto.DynamicProperties != null)
            {
                retVal.DynamicProperties = storeDto.DynamicProperties.Select(x => x.ToWebModel()).ToList();
                retVal.ThemeName = retVal.DynamicProperties.GetDynamicPropertyValue("DefaultThemeName");
            }

            return retVal;
        }
Esempio n. 3
0
        public async Task<CartBuilder> GetOrCreateNewTransientCartAsync(Store store, Customer customer, Language language, Currency currency)
        {
            _store = store;
            _customer = customer;
            _currency = currency;
            _language = language;
            _cartCacheKey = GetCartCacheKey(store.Id, customer.Id);

            _cart = await _cacheManager.GetAsync(_cartCacheKey, _cartCacheRegion, async () =>
            {
                ShoppingCart retVal;

                var cartSearchResult = await _cartApi.CartModuleGetCurrentCartAsync(_store.Id, _customer.Id);
                if (cartSearchResult == null)
                {
                    retVal = CreateNewTransientCart();
                }
                else
                {
                    var detalizedCart = await _cartApi.CartModuleGetCartByIdAsync(cartSearchResult.Id);
                    retVal = detalizedCart.ToWebModel(_currency, _language);
                }

                return retVal;
            });

            await EvaluatePromotionsAsync();

            return this;
        }
Esempio n. 4
0
 public static Store ToWebModel(this VirtoCommerce.Client.Model.VirtoCommerceStoreModuleWebModelStore storeDto)
 {
     var retVal = new Store();
     retVal.InjectFrom(storeDto);
     if(storeDto.SeoInfos != null)
     {
         retVal.SeoInfos = storeDto.SeoInfos.Select(x => x.ToWebModel()).ToList();
     }
     retVal.DefaultLanguage = storeDto.DefaultLanguage != null ? new Language(storeDto.DefaultLanguage) : new Language("en-US");
     if(storeDto.Languages != null)
     {
         retVal.Languages = storeDto.Languages.Select(x => new Language(x)).ToList();
     }
     retVal.DefaultCurrency = Currency.Get(EnumUtility.SafeParse(storeDto.DefaultCurrency, CurrencyCodes.USD));
     if(storeDto.Currencies != null)
     {
         retVal.Currencies = storeDto.Currencies.Select(x => Currency.Get(EnumUtility.SafeParse(x, CurrencyCodes.USD))).ToList();
     }
     if(storeDto.DynamicProperties != null)
     {
         retVal.DynamicProperties = storeDto.DynamicProperties.Select(x => x.ToWebModel()).ToList();
         retVal.ThemeName = retVal.DynamicProperties.GetDynamicPropertyValue("DefaultThemeName");
     }
     
 
     return retVal;
 }
        public string ToAppRelative(string virtualPath, Store store, Language language)
        {
            var result = new StringBuilder("~");
            //Do not add storeId to Url if it single or have strict  defined Url
            if (store != null && !store.IsStoreUri(_workContext.RequestUrl))
            {
                //Do not use store in url if it single
                if (_workContext.AllStores.Length > 1)
                {
                    //Check that store exist for not exist store use current
                    store = _workContext.AllStores.Contains(store) ? store : _workContext.CurrentStore;
                    if (!virtualPath.Contains("/" + store.Id + "/"))
                    {
                        result.Append("/");
                        result.Append(store.Id);
                    }
                }
            }

            //Do not use language in url if it single for store
            if (language != null && store != null && store.Languages.Count > 1)
            {
                language = store.Languages.Contains(language) ? language : store.DefaultLanguage;
                if (!virtualPath.Contains("/" + language.CultureName + "/"))
                {
                    result.Append("/");
                    result.Append(language.CultureName);
                }
            }

            result.Append("/");
            result.Append(virtualPath.TrimStart('~', '/'));

            return result.ToString();
        }
Esempio n. 6
0
        /// <summary>
        /// Method for switching between multiple stores
        /// </summary>
        /// <param name="input"></param>
        /// <param name="storeId"></param>
        /// <param name="languageCode"></param>
        /// <returns></returns>
        public static string StoreAbsoluteUrl(string input, string storeId = null, string languageCode = null)
        {
            var themeAdaptor = (ShopifyLiquidThemeEngine)Template.FileSystem;

            storefrontModel.Store store = null;
            if (!string.IsNullOrEmpty(storeId))
            {
                store = themeAdaptor.WorkContext.AllStores.FirstOrDefault(x => string.Equals(x.Id, storeId, StringComparison.InvariantCultureIgnoreCase));
            }
            store = store ?? themeAdaptor.WorkContext.CurrentStore;

            var retVal = AbsoluteUrl(input, storeId, languageCode);

            var isHttps = themeAdaptor.WorkContext.RequestUrl.Scheme == Uri.UriSchemeHttps;

            //If store has defined url need redirect to it
            if (isHttps)
            {
                retVal = String.IsNullOrEmpty(store.SecureUrl) ? retVal : store.SecureUrl;
            }
            else
            {
                retVal = String.IsNullOrEmpty(store.Url) ? retVal : store.Url;
            }
            return(retVal);
        }
Esempio n. 7
0
        public static Store ToWebModel(this VirtoCommerce.Client.Model.VirtoCommerceStoreModuleWebModelStore storeDto)
        {
            var retVal = new Store();
            retVal.InjectFrom<NullableAndEnumValueInjecter>(storeDto);
            if(!storeDto.SeoInfos.IsNullOrEmpty())
            {
                retVal.SeoInfos = storeDto.SeoInfos.Select(x => x.ToWebModel()).ToList();
            }
            retVal.DefaultLanguage = storeDto.DefaultLanguage != null ? new Language(storeDto.DefaultLanguage) : Language.InvariantLanguage;
            if(!storeDto.Languages.IsNullOrEmpty())
            {
                retVal.Languages = storeDto.Languages.Select(x => new Language(x)).ToList();
            }

            if (!storeDto.Currencies.IsNullOrEmpty())
            {
                retVal.Currencies.AddRange(storeDto.Currencies.Select(x => new Currency(Language.InvariantLanguage, x)));
            }
            retVal.DefaultCurrency = retVal.Currencies.FirstOrDefault(x => x.Equals(storeDto.DefaultCurrency));

            if (!storeDto.DynamicProperties.IsNullOrEmpty())
            {
                retVal.DynamicProperties = storeDto.DynamicProperties.Select(x => x.ToWebModel()).ToList();
                retVal.ThemeName = retVal.DynamicProperties.GetDynamicPropertyValue("DefaultThemeName");
            }
            if(!storeDto.DynamicProperties.IsNullOrEmpty())
            {
                retVal.Settings = storeDto.Settings.Select(x => x.ToWebModel()).ToList();
            }
            retVal.TrustedGroups = storeDto.TrustedGroups;
            retVal.StoreState = EnumUtility.SafeParse(storeDto.StoreState, StoreStatus.Open);

            return retVal;
        }
 public string ToAppAbsolute(string virtualPath, Store store, Language language)
 {
     var appRelativePath = ToAppRelative(virtualPath, store, language);
     var result = appRelativePath.StartsWith("~")
         ? VirtualPathUtility.ToAbsolute(appRelativePath)
         : appRelativePath;
     return result;
 }
        public IEnumerable<ContentItem> LoadStoreStaticContent(Store store)
        {
            var retVal = new List<ContentItem>();
            var baseStoreContentPath = "/" + store.Id;
            var searchPattern = "*.*";

            if (_contentBlobProvider.PathExists(baseStoreContentPath))
            {
                var config = _liquidEngine.GetSettings();

                //Search files by requested search pattern
                var contentBlobs = _contentBlobProvider.Search(baseStoreContentPath, searchPattern, true)
                                             .Where(x => _extensions.Any(y => x.EndsWith(y)))
                                             .Select(x => x.Replace("\\\\", "\\"));

                //each content file  has a name pattern {name}.{language?}.{ext}
                var localizedBlobs = contentBlobs.Select(x => new LocalizedBlobInfo(x));

                foreach (var localizedBlob in localizedBlobs.OrderBy(x => x.Name))
                {
                    var blobRelativePath = "/" + localizedBlob.Path.TrimStart('/');
                    var contentItem = _contentItemFactory(blobRelativePath);
                    if (contentItem != null)
                    {
                        if (contentItem.Name == null)
                        {
                            contentItem.Name = localizedBlob.Name;
                        }
                        contentItem.Language = localizedBlob.Language;
                        contentItem.FileName = Path.GetFileName(blobRelativePath);
                        contentItem.StoragePath = "/" + blobRelativePath.Replace(baseStoreContentPath + "/", string.Empty).TrimStart('/');

                        LoadAndRenderContentItem(blobRelativePath, contentItem);

                        retVal.Add(contentItem);
                    }
                }
            }

            return retVal.ToArray();
        }
Esempio n. 10
0
        public static Shop ToShopifyModel(this StorefrontModel.Store store, StorefrontModel.WorkContext workContext)
        {
            Shop result = new Shop();

            result.InjectFrom <StorefrontModel.Common.NullableAndEnumValueInjecter>(store);
            result.CustomerAccountsEnabled  = true;
            result.CustomerAccountsOptional = true;
            result.Currency                = workContext.CurrentCurrency.Code;
            result.CollectionsCount        = "0";
            result.Description             = store.Description;
            result.Domain                  = store.Url;
            result.Email                   = store.Email;
            result.MoneyFormat             = "";
            result.MoneyWithCurrencyFormat = "";
            result.Url        = store.Url ?? "~/";
            result.Currencies = store.Currencies.Select(x => x.Code).ToArray();
            result.Languages  = store.Languages.Select(x => x.ToShopifyModel()).ToArray();
            result.Catalog    = store.Catalog;
            //result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("global", store.DynamicProperties) });

            return(result);
        }
Esempio n. 11
0
        /// <summary>
        /// Get app absolute storefront url with specified store and language
        /// </summary>
        /// <param name="input"></param>
        /// <param name="storeId"></param>
        /// <param name="languageCode"></param>
        /// <returns></returns>
        public static string AbsoluteUrl(string input, string storeId = null, string languageCode = null)
        {
            var themeAdaptor = (ShopifyLiquidThemeEngine)Template.FileSystem;

            storefrontModel.Store    store    = null;
            storefrontModel.Language language = null;
            if (!string.IsNullOrEmpty(storeId))
            {
                store = themeAdaptor.WorkContext.AllStores.FirstOrDefault(x => string.Equals(x.Id, storeId, StringComparison.InvariantCultureIgnoreCase));
            }
            store = store ?? themeAdaptor.WorkContext.CurrentStore;

            if (!string.IsNullOrEmpty(languageCode))
            {
                language = store.Languages.FirstOrDefault(x => string.Equals(x.CultureName, languageCode, StringComparison.InvariantCultureIgnoreCase));
            }
            language = language ?? themeAdaptor.WorkContext.CurrentLanguage;

            var retVal = themeAdaptor.UrlBuilder.ToAppAbsolute(input, store, language);

            return(retVal);
        }
        public static Category ToWebModel(this VirtoCommerceCatalogModuleWebModelCategory category, Language currentLanguage, Store store, VirtoCommerceCatalogModuleWebModelProduct[] products = null)
        {
            var retVal = new Category();
            retVal.InjectFrom<NullableAndEnumValueInjecter>(category);

            retVal.SeoInfo = category.SeoInfos.GetBestMatchedSeoInfo(store, currentLanguage).ToWebModel();
            retVal.Url = "~/" + category.Outlines.GetSeoPath(store, currentLanguage, "category/" + category.Id);

            if (category.Images != null)
            {
                retVal.Images = category.Images.Select(i => i.ToWebModel()).ToArray();
                retVal.PrimaryImage = retVal.Images.FirstOrDefault();
            }

            if (category.Properties != null)
            {
                retVal.Properties = category.Properties
                    .Where(x => string.Equals(x.Type, "Category", StringComparison.OrdinalIgnoreCase))
                    .Select(p => p.ToWebModel(currentLanguage))
                    .ToList();
            }

            return retVal;
        }
Esempio n. 13
0
 private ContentPage TryToFindContentPageWithUrl(string url, Store store, Language language)
 {
     if (store == null)
         return null;
     var cacheKey = String.Join(":", "AllStaticContentForLanguage", store.Id, language.CultureName);
     var retVal = _cacheManager.Get(cacheKey, "ContentRegion", () =>
     {
         return _contentService.LoadContentItemsByUrl("/", store, language, () => new ContentPage(), null,  1, int.MaxValue, renderContent: false).OfType<ContentPage>().ToArray();
     });
     url = url.TrimStart('/');
     return retVal.FirstOrDefault(x => string.Equals(x.Permalink, url, StringComparison.CurrentCultureIgnoreCase) || string.Equals(x.Url, url, StringComparison.InvariantCultureIgnoreCase));
 }
Esempio n. 14
0
        private Language GetLanguage(IOwinContext context, ICollection<Store> stores, Store store)
        {
            var languages = stores.SelectMany(s => s.Languages)
                .Union(stores.Select(s => s.DefaultLanguage))
                .Select(x => x.CultureName)
                .Distinct()
                .ToArray();

            //Get language from request url and remove it from from url need to prevent writing language in routing
            var languageCode = GetLanguageFromUrl(context, languages);

            //Get language from Cookies
            if (string.IsNullOrEmpty(languageCode))
            {
                languageCode = context.Request.Cookies[StorefrontConstants.LanguageCookie];
            }
            var retVal = store.DefaultLanguage;
            //Get store default language if language not in the supported by stores list
            if (!string.IsNullOrEmpty(languageCode))
            {
                var language = new Language(languageCode);
                retVal = store.Languages.Contains(language) ? language : retVal;
            }
            return retVal;
        }
Esempio n. 15
0
        private static Currency GetCurrency(IOwinContext context, Store store)
        {
            //Get currency from request url
            var currencyCode = context.Request.Query.Get("currency");
            //Next try get from Cookies
            if (string.IsNullOrEmpty(currencyCode))
            {
                currencyCode = context.Request.Cookies[StorefrontConstants.CurrencyCookie];
            }

            var retVal = store.DefaultCurrency;
            //Get store default currency if currency not in the supported by stores list
            if (!string.IsNullOrEmpty(currencyCode))
            {
                retVal = store.Currencies.FirstOrDefault(x => x.Equals(currencyCode)) ?? retVal;
            }
            return retVal;
        }
Esempio n. 16
0
        private void ValidateUserStoreLogin(IOwinContext context, CustomerInfo customer, Store currentStore)
        {

            if (customer.IsRegisteredUser && !customer.AllowedStores.IsNullOrEmpty()
                && !customer.AllowedStores.Any(x => string.Equals(x, currentStore.Id, StringComparison.InvariantCultureIgnoreCase)))
            {
                context.Authentication.SignOut();
                context.Authentication.User = new GenericPrincipal(new GenericIdentity(string.Empty), null);
            }
        }
        public string ToAppRelative(string virtualPath, Store store, Language language)
        {
            var result = virtualPath;

            // Don't process absolute URL
            Uri absoluteUri;
            if (!Uri.TryCreate(virtualPath, UriKind.Absolute, out absoluteUri))
            {
                var builder = new StringBuilder("~");

                if (store != null)
                {
                    // If store has public or secure URL, use them
                    if (!string.IsNullOrEmpty(store.Url) || !string.IsNullOrEmpty(store.SecureUrl))
                    {
                        string baseAddress = null;

                        // If current request is secure, use secure URL
                        if (_workContext.RequestUrl != null && !string.IsNullOrEmpty(store.SecureUrl) &&
                            _workContext.RequestUrl.ToString()
                                .StartsWith(store.SecureUrl, StringComparison.InvariantCultureIgnoreCase))
                        {
                            baseAddress = store.SecureUrl;
                        }

                        if (baseAddress == null)
                        {
                            baseAddress = !string.IsNullOrEmpty(store.Url) ? store.Url : store.SecureUrl;
                        }

                        builder.Clear();
                        builder.Append(baseAddress.TrimEnd('/'));
                    }
                    else
                    {
                        // Do not add storeId to URL if there is only one store
                        if (_workContext.AllStores.Length > 1)
                        {
                            // If specified store does not exist, use current store
                            store = _workContext.AllStores.Contains(store) ? store : _workContext.CurrentStore;
                            if (!virtualPath.Contains("/" + store.Id + "/"))
                            {
                                builder.Append("/");
                                builder.Append(store.Id);
                            }
                        }
                    }

                    // Do not add language to URL if store has only one language
                    if (language != null && store.Languages.Count > 1)
                    {
                        language = store.Languages.Contains(language) ? language : store.DefaultLanguage;
                        if (!virtualPath.Contains("/" + language.CultureName + "/"))
                        {
                            builder.Append("/");
                            builder.Append(language.CultureName);
                        }
                    }
                }

                builder.Append("/");
                builder.Append(virtualPath.TrimStart('~', '/'));
                result = builder.ToString();
            }

            return result;
        }
        protected virtual Currency GetCurrency(IOwinContext context, Store store)
        {
            //Get currency from request url
            var currencyCode = context.Request.Query.Get("currency");
            //Next try get from Cookies
            if (string.IsNullOrEmpty(currencyCode))
            {
                currencyCode = context.Request.Cookies[StorefrontConstants.CurrencyCookie];
            }

            var retVal = store.DefaultCurrency;
            //Get store default currency if currency not in the supported by stores list
            if (!string.IsNullOrEmpty(currencyCode))
            {
                var currency = new Currency(EnumUtility.SafeParse(currencyCode, store.DefaultCurrency.CurrencyCode));
                retVal = store.Currencies.Contains(currency) ? currency : retVal;
            }
            return retVal;
        }
 public string ToAppAbsolute(string virtualPath, Store store, Language language)
 {
     var retVal = VirtualPathUtility.ToAbsolute(ToAppRelative(virtualPath, store, language));
     return retVal;
 }
Esempio n. 20
0
 private ContentPage TryToFindContentPageWithUrl(string url, Store store, Language language)
 {
     if (store == null)
         return null;
     var cacheKey = String.Join(":", "TryToFindContentPageWithUrl", url, store.Id, language.CultureName);
     var retVal = _cacheManager.Get(cacheKey, "ContentRegion", () =>
     {
         var allPages = _contentService.LoadContentItemsByUrl("/", store, language, x => new ContentPage(x, language), 1, int.MaxValue);
         return allPages.FirstOrDefault(x => url.EndsWith(x.Url)) as ContentPage;
     });
     return retVal;
 }