コード例 #1
0
        protected LanguageSelectorModel PrepareLanguageSelectorModel()
        {
            var availableLanguages = _cacheManager.Get(string.Format(ModelCacheEventConsumer.AVAILABLE_LANGUAGES_MODEL_KEY, _storeContext.CurrentStore.Id), () =>
            {
                var result = _languageService
                             .GetAllLanguages(storeId: _storeContext.CurrentStore.Id)
                             .Select(x => new LanguageModel()
                {
                    Id   = x.Id,
                    Name = x.Name,
                    // codehint: sm-add
                    NativeName        = GetLanguageNativeName(x.LanguageCulture) ?? x.Name,
                    ISOCode           = x.LanguageCulture,
                    SeoCode           = x.UniqueSeoCode,
                    FlagImageFileName = x.FlagImageFileName
                })
                             .ToList();
                return(result);
            });

            var workingLanguage = _workContext.WorkingLanguage;

            var model = new LanguageSelectorModel()
            {
                CurrentLanguageId  = workingLanguage.Id,
                AvailableLanguages = availableLanguages,
                UseImages          = _localizationSettings.UseImagesForLanguageSelection
            };

            string defaultSeoCode = _workContext.GetDefaultLanguageSeoCode();

            foreach (var lang in model.AvailableLanguages)
            {
                var helper = new LocalizedUrlHelper(HttpContext.Request, true);

                if (_localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
                {
                    if (lang.SeoCode == defaultSeoCode && (int)(_localizationSettings.DefaultLanguageRedirectBehaviour) > 0)
                    {
                        helper.StripSeoCode();
                    }
                    else
                    {
                        helper.PrependSeoCode(lang.SeoCode, true);
                    }
                }

                model.ReturnUrls[lang.SeoCode] = HttpUtility.UrlEncode(helper.GetAbsolutePath());
            }

            return(model);
        }
コード例 #2
0
        private ContentSliderSettingsModel PrepareContentSliderSettingsModel(ContentSliderSettingsModel modelIn = null)
        {
            int rowIndex = 0;
            var model    = _contentSliderSettings.ToModel();

            model.AvailableSites.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var s in _siteService.GetAllSites())
            {
                model.AvailableSites.Add(new SelectListItem()
                {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            foreach (var slide in model.Slides)
            {
                slide.SlideIndex = rowIndex++;

                var language = _languageService.GetLanguageByCulture(slide.LanguageCulture);
                if (language != null)
                {
                    slide.LanguageName = language.Name;
                }
                else
                {
                    var seoCode = _workContext.GetDefaultLanguageSeoCode();
                    slide.LanguageName = _languageService.GetLanguageBySeoCode(seoCode).Name;
                }
            }

            // note order: first SlideIndex then search filter.
            if (modelIn != null && modelIn.SearchSiteId > 0)
            {
                model.Slides = model.Slides
                               .Where(x => x.LimitedToSites && x.SelectedSiteIds != null && x.SelectedSiteIds.Contains(modelIn.SearchSiteId))
                               .ToList();
            }

            return(model);
        }