public ActionResult ProductExtendedFields(int productId) { var model = new ProductExtendedFieldsModel(); var product = _productService.GetProductById(productId); if (product != null) { model.Heading = product.GetAttribute <string>("Heading"); model.MyCheck = product.GetAttribute <bool>("MyCheck"); } return(View(model)); }
public ActionResult Configure() { //load settings for a chosen store scope var storeScope = GetActiveStoreScopeConfiguration(_storeService, _workContext); var GBSShippingSettings = _settingService.LoadSetting <GBSShippingSetting>(storeScope); var model = new ProductExtendedFieldsModel { LoginId = GBSShippingSettings.LoginId, Password = GBSShippingSettings.Password, GBSShippingWebServiceAddress = GBSShippingSettings.GBSShippingWebServiceAddress, GBSStoreNamePrepend = GBSShippingSettings.GBSStoreNamePrepend, UseFlatRate = GBSShippingSettings.UseFlatRate, FlatRateAmount = GBSShippingSettings.FlatRateAmount, ActiveStoreScopeConfiguration = storeScope, TableName = _localizationService.GetLocaleStringResourceByName("Plugins.Shipping.GBS.Product.Table.Name").ResourceValue.ToString(), ShippingOptionDesError = _localizationService.GetLocaleStringResourceByName("Plugins.Shipping.GBS.Product.ShippingOption.Description.Error").ResourceValue.ToString(), ShippingOptionDesName = _localizationService.GetLocaleStringResourceByName("Plugins.Shipping.GBS.Product.ShippingOption.Description.Name").ResourceValue.ToString(), ShippingOptionDesSuccess = _localizationService.GetLocaleStringResourceByName("Plugins.Shipping.GBS.Product.ShippingOption.Description.Success").ResourceValue.ToString(), ShippingCategoryA = _localizationService.GetLocaleStringResourceByName("Plugins.Shipping.GBS.Product.ShippingCategoryA").ResourceValue.ToString(), ShippingCategoryB = _localizationService.GetLocaleStringResourceByName("Plugins.Shipping.GBS.Product.ShippingCategoryB").ResourceValue.ToString() }; var product = _productService.GetProductById(1); if (product != null) { var genericAttributeService = EngineContext.Current.Resolve <IGenericAttributeService>(); genericAttributeService.SaveAttribute(product, "TableName", model.TableName); } if (storeScope > 0) { model.LoginId_OverrideForStore = _settingService.SettingExists(GBSShippingSettings, x => x.LoginId, storeScope); model.Password_OverrideForStore = _settingService.SettingExists(GBSShippingSettings, x => x.Password, storeScope); model.GBSShippingWebServiceAddress_OverrideForStore = _settingService.SettingExists(GBSShippingSettings, x => x.GBSShippingWebServiceAddress, storeScope); model.GBSStoreNamePrepend_OverrideForStore = _settingService.SettingExists(GBSShippingSettings, x => x.GBSStoreNamePrepend, storeScope); model.UseFlatRate_OverrideForStore = _settingService.SettingExists(GBSShippingSettings, x => x.UseFlatRate, storeScope); model.FlatRateAmount_OverrideForStore = _settingService.SettingExists(GBSShippingSettings, x => x.FlatRateAmount, storeScope); } return(View("~/Plugins/Shipping.GBS/Views/ExtendedFields/Configure.cshtml", model)); }
public ActionResult Configure(ProductExtendedFieldsModel model) { if (!ModelState.IsValid) { return(Configure()); } //load settings for a chosen store scope var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var GBSShippingSetting = _settingService.LoadSetting <GBSShippingSetting>(storeScope); // Get language ID var languageId = _workContext.WorkingLanguage.Id; // Save String Resources Builder("Plugins.Shipping.GBS.Product.ShippingOption.Description.Error", languageId, model.ShippingOptionDesError); Builder("Plugins.Shipping.GBS.Product.ShippingOption.Description.Success", languageId, model.ShippingOptionDesSuccess); Builder("Plugins.Shipping.GBS.Product.ShippingOption.Description.Name", languageId, model.ShippingOptionDesName); Builder("Plugins.Shipping.GBS.Product.Table.Name", languageId, model.TableName); Builder("Plugins.Shipping.GBS.Product.ShippingCategoryA", languageId, model.ShippingCategoryA); Builder("Plugins.Shipping.GBS.Product.ShippingCategoryB", languageId, model.ShippingCategoryB); //save settings GBSShippingSetting.LoginId = model.LoginId; GBSShippingSetting.Password = model.Password; GBSShippingSetting.GBSShippingWebServiceAddress = model.GBSShippingWebServiceAddress; GBSShippingSetting.GBSStoreNamePrepend = model.GBSStoreNamePrepend; GBSShippingSetting.UseFlatRate = model.UseFlatRate; GBSShippingSetting.FlatRateAmount = model.FlatRateAmount; ///* We do not clear cache after each setting update. // * This behavior can increase performance because cached settings will not be cleared // * and loaded from database after each update */ if (model.LoginId_OverrideForStore || storeScope == 0) { _settingService.SaveSetting(GBSShippingSetting, x => x.LoginId, storeScope, false); } else if (storeScope > 0) { _settingService.DeleteSetting(GBSShippingSetting, x => x.LoginId, storeScope); } if (model.Password_OverrideForStore || storeScope == 0) { _settingService.SaveSetting(GBSShippingSetting, x => x.Password, storeScope, false); } else if (storeScope > 0) { _settingService.DeleteSetting(GBSShippingSetting, x => x.Password, storeScope); } if (model.GBSShippingWebServiceAddress_OverrideForStore || storeScope == 0) { _settingService.SaveSetting(GBSShippingSetting, x => x.GBSShippingWebServiceAddress, storeScope, false); } else if (storeScope > 0) { _settingService.DeleteSetting(GBSShippingSetting, x => x.GBSShippingWebServiceAddress, storeScope); } if (model.GBSStoreNamePrepend_OverrideForStore || storeScope == 0) { _settingService.SaveSetting(GBSShippingSetting, x => x.GBSStoreNamePrepend, storeScope, false); } else if (storeScope > 0) { _settingService.DeleteSetting(GBSShippingSetting, x => x.GBSStoreNamePrepend, storeScope); } if (model.UseFlatRate_OverrideForStore || storeScope == 0) { _settingService.SaveSetting(GBSShippingSetting, x => x.UseFlatRate, storeScope, false); } else if (storeScope > 0) { _settingService.DeleteSetting(GBSShippingSetting, x => x.UseFlatRate, storeScope); } if (model.FlatRateAmount_OverrideForStore || storeScope == 0) { _settingService.SaveSetting(GBSShippingSetting, x => x.FlatRateAmount, storeScope, false); } else if (storeScope > 0) { _settingService.DeleteSetting(GBSShippingSetting, x => x.FlatRateAmount, storeScope); } //now clear settings cache _settingService.ClearCache(); SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved")); return(Configure()); }