public ActionResult Configure() { var model = new USPSModel(); model.UseSandbox = _uspsSettings.UseSandbox; model.Username = _uspsSettings.Username; model.Password = _uspsSettings.Password; model.AdditionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge; model.ZipPostalCodeFrom = _uspsSettings.ZipPostalCodeFrom; var services = new USPSServices(); // Load Domestic service names string carrierServicesOfferedDomestic = _uspsSettings.CarrierServicesOfferedDomestic; foreach (string service in services.DomesticServices) { model.AvailableCarrierServicesDomestic.Add(service); } if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic)) { foreach (string service in services.DomesticServices) { string serviceId = USPSServices.GetServiceIdDomestic(service); if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOfferedDomestic)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs if (carrierServicesOfferedDomestic.Contains(String.Format("[{0}]", serviceId))) { model.CarrierServicesOfferedDomestic.Add(service); } } } } // Load Internation service names string carrierServicesOfferedInternational = _uspsSettings.CarrierServicesOfferedInternational; foreach (string service in services.InternationalServices) { model.AvailableCarrierServicesInternational.Add(service); } if (!String.IsNullOrEmpty(carrierServicesOfferedInternational)) { foreach (string service in services.InternationalServices) { string serviceId = USPSServices.GetServiceIdInternational(service); if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOfferedInternational)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs if (carrierServicesOfferedInternational.Contains(String.Format("[{0}]", serviceId))) { model.CarrierServicesOfferedInternational.Add(service); } } } } return(View(model)); }
public ActionResult Configure(USPSShippingModel model) { if (!ModelState.IsValid) { return(Configure()); } //save settings _uspsSettings.Url = model.Url; _uspsSettings.Username = model.Username; _uspsSettings.Password = model.Password; _uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge; // Save selected Domestic services var carrierServicesOfferedDomestic = new StringBuilder(); int carrierServicesDomesticSelectedCount = 0; if (model.CheckedCarrierServicesDomestic != null) { foreach (var cs in model.CheckedCarrierServicesDomestic) { carrierServicesDomesticSelectedCount++; string serviceId = USPSServices.GetServiceIdDomestic(cs); //unselect any other services if NONE is selected if (serviceId.Equals("NONE")) { carrierServicesOfferedDomestic.Clear(); carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); break; } if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected if (carrierServicesDomesticSelectedCount == 0) { _uspsSettings.CarrierServicesOfferedDomestic = "[1]:[3]:[4]:"; } else { _uspsSettings.CarrierServicesOfferedDomestic = carrierServicesOfferedDomestic.ToString(); } // Save selected International services var carrierServicesOfferedInternational = new StringBuilder(); int carrierServicesInternationalSelectedCount = 0; if (model.CheckedCarrierServicesInternational != null) { foreach (var cs in model.CheckedCarrierServicesInternational) { carrierServicesInternationalSelectedCount++; string serviceId = USPSServices.GetServiceIdInternational(cs); // unselect other services if NONE is selected if (serviceId.Equals("NONE")) { carrierServicesOfferedInternational.Clear(); carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); break; } if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected if (carrierServicesInternationalSelectedCount == 0) { _uspsSettings.CarrierServicesOfferedInternational = "[2]:[15]:[1]:"; } else { _uspsSettings.CarrierServicesOfferedInternational = carrierServicesOfferedInternational.ToString(); } _settingService.SaveSetting(_uspsSettings); return(Configure()); }
public IActionResult Configure() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var model = new USPSShippingModel(); model.Url = _uspsSettings.Url; model.Username = _uspsSettings.Username; model.Password = _uspsSettings.Password; model.AdditionalHandlingCharge = _uspsSettings.AdditionalHandlingCharge; // Load Domestic service names string carrierServicesOfferedDomestic = _uspsSettings.CarrierServicesOfferedDomestic; foreach (string service in USPSServices.DomesticServices) { model.AvailableCarrierServicesDomestic.Add(service); } if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic)) { foreach (string service in USPSServices.DomesticServices) { string serviceId = USPSServices.GetServiceIdDomestic(service); if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs if (carrierServicesOfferedDomestic.Contains($"[{serviceId}]")) { model.CarrierServicesOfferedDomestic.Add(service); } } } } // Load Internation service names string carrierServicesOfferedInternational = _uspsSettings.CarrierServicesOfferedInternational; foreach (string service in USPSServices.InternationalServices) { model.AvailableCarrierServicesInternational.Add(service); } if (!String.IsNullOrEmpty(carrierServicesOfferedInternational)) { foreach (string service in USPSServices.InternationalServices) { string serviceId = USPSServices.GetServiceIdInternational(service); if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs if (carrierServicesOfferedInternational.Contains($"[{serviceId}]")) { model.CarrierServicesOfferedInternational.Add(service); } } } } return(View("~/Plugins/Shipping.USPS/Views/Configure.cshtml", model)); }
private void BindData() { txtURL.Text = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.USPS.URL"); txtUsername.Text = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.USPS.Username"); txtPassword.Text = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.USPS.Password"); txtAdditionalHandlingCharge.Value = this.SettingManager.GetSettingValueDecimalNative("ShippingRateComputationMethod.USPS.AdditionalHandlingCharge"); txtShippedFromZipPostalCode.Text = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.USPS.DefaultShippedFromZipPostalCode"); string carrierServicesOfferedDomestic = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.USPS.CarrierServicesOfferedDomestic", string.Empty); var services = new USPSServices(); // Load Domestic service names if (carrierServicesOfferedDomestic.Length == 0) { foreach (string service in services.DomesticServices) { this.cblCarrierServicesOfferedDomestic.Items.Add(service); } } else { foreach (string service in services.DomesticServices) { ListItem cblItem = new ListItem(service); string serviceId = USPSServices.GetServiceIdDomestic(service); if (serviceId.Equals("NONE", StringComparison.InvariantCultureIgnoreCase)) { cblItem.Attributes["style"] = "font-weight:bold"; } if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOfferedDomestic)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs serviceId = String.Format("[{0}]", serviceId); if (carrierServicesOfferedDomestic.Contains(serviceId) == true) { cblItem.Selected = true; } } this.cblCarrierServicesOfferedDomestic.Items.Add(cblItem); } } string carrierServicesOfferedInternational = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.USPS.CarrierServicesOfferedInternational", string.Empty); // Load International service names if (carrierServicesOfferedInternational.Length == 0) { foreach (string service in services.InternationalServices) { this.cblCarrierServicesOfferedInternational.Items.Add(service); } } else { foreach (string service in services.InternationalServices) { ListItem cblItem = new ListItem(service); string serviceId = USPSServices.GetServiceIdInternational(service); if (serviceId.Equals("NONE", StringComparison.InvariantCultureIgnoreCase)) { cblItem.Attributes["style"] = "font-weight:bold"; } if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOfferedInternational)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs serviceId = String.Format("[{0}]", serviceId); if (carrierServicesOfferedInternational.Contains(serviceId) == true) { cblItem.Selected = true; } } this.cblCarrierServicesOfferedInternational.Items.Add(cblItem); } } }
public void Save() { this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.URL", txtURL.Text); this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.Username", txtUsername.Text); this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.Password", txtPassword.Text); this.SettingManager.SetParamNative("ShippingRateComputationMethod.USPS.AdditionalHandlingCharge", txtAdditionalHandlingCharge.Value); this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.DefaultShippedFromZipPostalCode", txtShippedFromZipPostalCode.Text); // Save selected Domestic services var carrierServicesOfferedDomestic = new StringBuilder(); int carrierServicesDomesticSelectedCount = 0; foreach (ListItem li in cblCarrierServicesOfferedDomestic.Items) { if (li.Selected == true) { carrierServicesDomesticSelectedCount++; string serviceId = USPSServices.GetServiceIdDomestic(li.Text); // unselect any other services if NONE is selected if (serviceId.Equals("NONE")) { carrierServicesOfferedDomestic.Clear(); carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); break; } if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected (Priority, Express, and Parcel Post) if (carrierServicesDomesticSelectedCount == 0) { this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.CarrierServicesOfferedDomestic", "[1]:[3]:[4]:"); } else { this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.CarrierServicesOfferedDomestic", carrierServicesOfferedDomestic.ToString()); } // Save selected International services var carrierServicesOfferedInternational = new StringBuilder(); int carrierServicesInternationalSelectedCount = 0; foreach (ListItem li in cblCarrierServicesOfferedInternational.Items) { if (li.Selected == true) { carrierServicesInternationalSelectedCount++; string serviceId = USPSServices.GetServiceIdInternational(li.Text); // unselect other services if NONE is selected if (serviceId.Equals("NONE")) { carrierServicesOfferedInternational.Clear(); carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); break; } if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected (Priority Mail International, First-Class Mail International Package, and Express Mail International) if (carrierServicesInternationalSelectedCount == 0) { this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.CarrierServicesOfferedInternational", "[2]:[15]:[1]:"); } else { this.SettingManager.SetParam("ShippingRateComputationMethod.USPS.CarrierServicesOfferedInternational", carrierServicesOfferedInternational.ToString()); } }
public ActionResult Configure(USPSModel model) { if (!ModelState.IsValid) { return(Configure()); } _uspsSettings.UseSandbox = model.UseSandbox; _uspsSettings.Username = model.Username.TrimSafe(); _uspsSettings.Password = model.Password.TrimSafe(); _uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge; _uspsSettings.ZipPostalCodeFrom = model.ZipPostalCodeFrom; // Save selected Domestic services. var carrierServicesOfferedDomestic = new StringBuilder(); int carrierServicesDomesticSelectedCount = 0; if (model.CheckedCarrierServicesDomestic != null) { foreach (var cs in model.CheckedCarrierServicesDomestic) { carrierServicesDomesticSelectedCount++; string serviceId = USPSServices.GetServiceIdDomestic(cs); //unselect any other services if NONE is selected if (serviceId.Equals("NONE")) { carrierServicesOfferedDomestic.Clear(); carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); break; } if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected (Priority, Express, and Parcel Post) if (carrierServicesDomesticSelectedCount == 0) { _uspsSettings.CarrierServicesOfferedDomestic = "[1]:[3]:[4]:"; } else { _uspsSettings.CarrierServicesOfferedDomestic = carrierServicesOfferedDomestic.ToString(); } // Save selected International services var carrierServicesOfferedInternational = new StringBuilder(); int carrierServicesInternationalSelectedCount = 0; if (model.CheckedCarrierServicesInternational != null) { foreach (var cs in model.CheckedCarrierServicesInternational) { carrierServicesInternationalSelectedCount++; string serviceId = USPSServices.GetServiceIdInternational(cs); // unselect other services if NONE is selected if (serviceId.Equals("NONE")) { carrierServicesOfferedInternational.Clear(); carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); break; } if (!String.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected (Priority Mail International, First-Class Mail International Package, and Express Mail International) if (carrierServicesInternationalSelectedCount == 0) { _uspsSettings.CarrierServicesOfferedInternational = "[2]:[15]:[1]:"; } else { _uspsSettings.CarrierServicesOfferedInternational = carrierServicesOfferedInternational.ToString(); } _settingService.SaveSetting(_uspsSettings); return(RedirectToConfiguration("SmartStore.USPS")); }
public IActionResult Configure(USPSShippingModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(Configure()); } //save settings _uspsSettings.Url = model.Url; _uspsSettings.Username = model.Username; _uspsSettings.Password = model.Password; _uspsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge; // Save selected Domestic services var carrierServicesOfferedDomestic = new StringBuilder(); var carrierServicesDomesticSelectedCount = 0; if (model.CheckedCarrierServicesDomestic != null) { foreach (var cs in model.CheckedCarrierServicesDomestic) { carrierServicesDomesticSelectedCount++; var serviceId = USPSServices.GetServiceIdDomestic(cs); //unselect any other services if NONE is selected if (!string.IsNullOrEmpty(serviceId) && serviceId.Equals("NONE")) { carrierServicesOfferedDomestic.Clear(); carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); break; } if (!string.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedDomestic.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected if (carrierServicesDomesticSelectedCount == 0) { _uspsSettings.CarrierServicesOfferedDomestic = "[1]:[3]:[4]:"; } else { _uspsSettings.CarrierServicesOfferedDomestic = carrierServicesOfferedDomestic.ToString(); } // Save selected International services var carrierServicesOfferedInternational = new StringBuilder(); var carrierServicesInternationalSelectedCount = 0; if (model.CheckedCarrierServicesInternational != null) { foreach (var cs in model.CheckedCarrierServicesInternational) { carrierServicesInternationalSelectedCount++; var serviceId = USPSServices.GetServiceIdInternational(cs); // unselect other services if NONE is selected if (!string.IsNullOrEmpty(serviceId) && serviceId.Equals("NONE")) { carrierServicesOfferedInternational.Clear(); carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); break; } if (!string.IsNullOrEmpty(serviceId)) { // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs carrierServicesOfferedInternational.AppendFormat("[{0}]:", serviceId); } } } // Add default options if no services were selected if (carrierServicesInternationalSelectedCount == 0) { _uspsSettings.CarrierServicesOfferedInternational = "[2]:[15]:[1]:"; } else { _uspsSettings.CarrierServicesOfferedInternational = carrierServicesOfferedInternational.ToString(); } _settingService.SaveSetting(_uspsSettings); _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved")); return(Configure()); }