Exemplo n.º 1
0
        public void UpdateSettings(object settings, FormCollection form, int storeId, ISettingService settingService, ILocalizedModelLocal localized = null)
        {
            var settingName = settings.GetType().Name;
            var properties  = FastProperty.GetProperties(localized == null ? settings.GetType() : localized.GetType()).Values;

            using (settingService.BeginScope())
            {
                foreach (var prop in properties)
                {
                    var name = prop.Name;
                    var key  = settingName + "." + name;

                    if (storeId == 0 || IsOverrideChecked(key, form))
                    {
                        dynamic value = prop.GetValue(localized == null ? settings : localized);
                        settingService.SetSetting(key, value == null ? "" : value, storeId, false);
                    }
                    else if (storeId > 0)
                    {
                        settingService.DeleteSetting(key, storeId);
                    }
                }
            }
        }
        public ActionResult Configure(ConfigurationModel model, FormCollection form)
        {
            ModelState.Clear();

            //load settings for a chosen store scope
            var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext);
            var googleAnalyticsSettings = _settingService.LoadSetting <GoogleAnalyticsSettings>(storeScope);

            googleAnalyticsSettings.GoogleId              = model.GoogleId;
            googleAnalyticsSettings.TrackingScript        = model.TrackingScript;
            googleAnalyticsSettings.EcommerceScript       = model.EcommerceScript;
            googleAnalyticsSettings.EcommerceDetailScript = model.EcommerceDetailScript;
            googleAnalyticsSettings.WidgetZone            = model.ZoneId;

            using (_settingService.BeginScope())
            {
                _settingService.SaveSetting(googleAnalyticsSettings, x => x.WidgetZone, 0, false);

                var storeDependingSettingHelper = new StoreDependingSettingHelper(ViewData);
                storeDependingSettingHelper.UpdateSettings(googleAnalyticsSettings, form, storeScope, _settingService);
            }

            return(Configure());
        }