Exemple #1
0
        public ActionResult Configure(UPSShippingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _upsSettings.Url       = model.Url;
            _upsSettings.AccessKey = model.AccessKey;
            _upsSettings.Username  = model.Username;
            _upsSettings.Password  = model.Password;
            _upsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge;
            _upsSettings.InsurePackage            = model.InsurePackage;
            _upsSettings.CustomerClassification   = (UPSCustomerClassification)Enum.Parse(typeof(UPSCustomerClassification), model.CustomerClassification);
            _upsSettings.PickupType           = (UPSPickupType)Enum.Parse(typeof(UPSPickupType), model.PickupType);
            _upsSettings.PackagingType        = (UPSPackagingType)Enum.Parse(typeof(UPSPackagingType), model.PackagingType);
            _upsSettings.PackingPackageVolume = model.PackingPackageVolume;
            _upsSettings.PackingType          = (PackingType)model.PackingType;
            _upsSettings.PassDimensions       = model.PassDimensions;
            _upsSettings.Tracing = model.Tracing;


            // Save selected services
            var carrierServicesOfferedDomestic       = new StringBuilder();
            int carrierServicesDomesticSelectedCount = 0;

            if (model.CheckedCarrierServices != null)
            {
                foreach (var cs in model.CheckedCarrierServices)
                {
                    carrierServicesDomesticSelectedCount++;
                    string serviceId = UPSServices.GetServiceId(cs);
                    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)
            {
                _upsSettings.CarrierServicesOffered = "[03]:[12]:[11]:[08]:";
            }
            else
            {
                _upsSettings.CarrierServicesOffered = carrierServicesOfferedDomestic.ToString();
            }

            _settingService.SaveSetting(_upsSettings);

            SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            return(Configure());
        }
        public ActionResult Configure(UPSModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _upsSettings.Url       = model.Url;
            _upsSettings.AccessKey = model.AccessKey;
            _upsSettings.Username  = model.Username;
            _upsSettings.Password  = model.Password;
            _upsSettings.AdditionalHandlingCharge = model.AdditionalHandlingCharge;
            _upsSettings.InsurePackage            = model.InsurePackage;
            _upsSettings.CustomerClassification   = (UPSCustomerClassification)Enum.Parse(typeof(UPSCustomerClassification), model.CustomerClassification);
            _upsSettings.PickupType    = (UPSPickupType)Enum.Parse(typeof(UPSPickupType), model.PickupType);
            _upsSettings.PackagingType = (UPSPackagingType)Enum.Parse(typeof(UPSPackagingType), model.PackagingType);
            _upsSettings.DefaultShippedFromCountryId     = model.DefaultShippedFromCountryId;
            _upsSettings.DefaultShippedFromZipPostalCode = model.DefaultShippedFromZipPostalCode;


            // Save selected services
            var carrierServicesOfferedDomestic       = new StringBuilder();
            int carrierServicesDomesticSelectedCount = 0;

            if (model.CheckedCarrierServices != null)
            {
                foreach (var cs in model.CheckedCarrierServices)
                {
                    carrierServicesDomesticSelectedCount++;
                    string serviceId = UPSServices.GetServiceId(cs);
                    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 Mail International, First-Class Mail International Package, and Express Mail International)
            if (carrierServicesDomesticSelectedCount == 0)
            {
                _upsSettings.CarrierServicesOffered = "[03]:[12]:[11]:[08]:";
            }
            else
            {
                _upsSettings.CarrierServicesOffered = carrierServicesOfferedDomestic.ToString();
            }

            _settingService.SaveSetting(_upsSettings);

            return(Configure());
        }
        public void Save()
        {
            UPSCustomerClassification customerClassification = (UPSCustomerClassification)Enum.Parse(typeof(UPSCustomerClassification), ddlUPSCustomerClassification.SelectedItem.Value);
            UPSPickupType             pickupType             = (UPSPickupType)Enum.Parse(typeof(UPSPickupType), ddlUPSPickupType.SelectedItem.Value);
            UPSPackagingType          packagingType          = (UPSPackagingType)Enum.Parse(typeof(UPSPackagingType), ddlUPSPackagingType.SelectedItem.Value);

            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.URL", txtURL.Text);
            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.AccessKey", txtAccessKey.Text);
            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.Username", txtUsername.Text);
            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.Password", txtPassword.Text);
            this.SettingManager.SetParamNative("ShippingRateComputationMethod.UPS.AdditionalHandlingCharge", txtAdditionalHandlingCharge.Value);
            int defaultShippedFromCountryId = int.Parse(this.ddlShippedFromCountry.SelectedItem.Value);

            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.DefaultShippedFromCountryId", defaultShippedFromCountryId.ToString());
            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.DefaultShippedFromZipPostalCode", txtShippedFromZipPostalCode.Text);

            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.CustomerClassification", customerClassification.ToString());
            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.PickupType", pickupType.ToString());
            this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.PackagingType", packagingType.ToString());


            var carrierServicesOffered = new StringBuilder();
            int carrierServicesCount   = 0;

            foreach (ListItem li in cblCarrierServicesOffered.Items)
            {
                if (li.Selected == true)
                {
                    string serviceId = UPSServices.GetServiceId(li.Text);
                    if (!String.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        carrierServicesOffered.AppendFormat("[{0}]:", serviceId);
                    }
                    carrierServicesCount++;
                }
            }
            // Add default options if no services were selected (Ground, 3 Day Select, Standard, and Worldwide Expedited)
            if (carrierServicesCount == 0)
            {
                this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.CarrierServicesOffered", "[03]:[12]:[11]:[08]:");
            }
            else
            {
                this.SettingManager.SetParam("ShippingRateComputationMethod.UPS.CarrierServicesOffered", carrierServicesOffered.ToString());
            }
        }
Exemple #4
0
        public ActionResult Configure()
        {
            var model = new UPSShippingModel();

            model.Url       = _upsSettings.Url;
            model.AccessKey = _upsSettings.AccessKey;
            model.Username  = _upsSettings.Username;
            model.Password  = _upsSettings.Password;
            model.AdditionalHandlingCharge = _upsSettings.AdditionalHandlingCharge;
            model.InsurePackage            = _upsSettings.InsurePackage;

            foreach (UPSCustomerClassification customerClassification in Enum.GetValues(typeof(UPSCustomerClassification)))
            {
                model.AvailableCustomerClassifications.Add(new SelectListItem()
                {
                    Text     = CommonHelper.ConvertEnum(customerClassification.ToString()),
                    Value    = customerClassification.ToString(),
                    Selected = customerClassification == _upsSettings.CustomerClassification
                });
            }
            foreach (UPSPickupType pickupType in Enum.GetValues(typeof(UPSPickupType)))
            {
                model.AvailablePickupTypes.Add(new SelectListItem()
                {
                    Text     = CommonHelper.ConvertEnum(pickupType.ToString()),
                    Value    = pickupType.ToString(),
                    Selected = pickupType == _upsSettings.PickupType
                });
            }
            foreach (UPSPackagingType packagingType in Enum.GetValues(typeof(UPSPackagingType)))
            {
                model.AvailablePackagingTypes.Add(new SelectListItem()
                {
                    Text     = CommonHelper.ConvertEnum(packagingType.ToString()),
                    Value    = packagingType.ToString(),
                    Selected = packagingType == _upsSettings.PackagingType
                });
            }

            var services = new UPSServices();
            // Load Domestic service names
            string carrierServicesOfferedDomestic = _upsSettings.CarrierServicesOffered;

            foreach (string service in services.Services)
            {
                model.AvailableCarrierServices.Add(service);
            }

            if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic))
            {
                foreach (string service in services.Services)
                {
                    string serviceId = UPSServices.GetServiceId(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.CarrierServicesOffered.Add(service);
                        }
                    }
                }
            }

            return(View("Nop.Plugin.Shipping.UPS.Views.ShippingUPS.Configure", model));
        }
        private void BindData()
        {
            txtURL.Text       = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.URL");
            txtAccessKey.Text = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.AccessKey");
            txtUsername.Text  = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.Username");
            txtPassword.Text  = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.Password");
            txtAdditionalHandlingCharge.Value = this.SettingManager.GetSettingValueDecimalNative("ShippingRateComputationMethod.UPS.AdditionalHandlingCharge");

            int defaultShippedFromCountryId = this.SettingManager.GetSettingValueInteger("ShippingRateComputationMethod.UPS.DefaultShippedFromCountryId");

            CommonHelper.SelectListItem(ddlShippedFromCountry, defaultShippedFromCountryId);
            txtShippedFromZipPostalCode.Text = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.DefaultShippedFromZipPostalCode");


            string customerClassificationStr = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.CustomerClassification");

            if (!String.IsNullOrEmpty(customerClassificationStr))
            {
                UPSCustomerClassification customerClassification = (UPSCustomerClassification)Enum.Parse(typeof(UPSCustomerClassification), customerClassificationStr);
                CommonHelper.SelectListItem(ddlUPSCustomerClassification, customerClassification.ToString());
            }

            string pickupTypeStr = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.PickupType");

            if (!String.IsNullOrEmpty(pickupTypeStr))
            {
                UPSPickupType pickupType = (UPSPickupType)Enum.Parse(typeof(UPSPickupType), pickupTypeStr);
                CommonHelper.SelectListItem(ddlUPSPickupType, pickupType.ToString());
            }

            string packagingTypeStr = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.PackagingType");

            if (!String.IsNullOrEmpty(packagingTypeStr))
            {
                UPSPackagingType packagingType = (UPSPackagingType)Enum.Parse(typeof(UPSPackagingType), packagingTypeStr);
                CommonHelper.SelectListItem(ddlUPSPackagingType, packagingType.ToString());
            }

            string carrierServicesOffered = this.SettingManager.GetSettingValue("ShippingRateComputationMethod.UPS.CarrierServicesOffered", string.Empty);
            var    services = new UPSServices();

            // Load all service names
            if (carrierServicesOffered.Length == 0)
            {
                foreach (string service in services.Services)
                {
                    this.cblCarrierServicesOffered.Items.Add(service);
                }
            }
            else
            {
                // Load and select previously selected services
                foreach (string service in services.Services)
                {
                    ListItem cblItem   = new ListItem(service);
                    string   serviceId = UPSServices.GetServiceId(service);

                    if (!String.IsNullOrEmpty(serviceId) && !String.IsNullOrEmpty(carrierServicesOffered))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        serviceId = String.Format("[{0}]", serviceId);
                        if (carrierServicesOffered.Contains(serviceId) == true)
                        {
                            cblItem.Selected = true;
                        }
                    }
                    this.cblCarrierServicesOffered.Items.Add(cblItem);
                }
            }
        }
Exemple #6
0
        public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return(AccessDeniedView());
            }

            var model = new UPSShippingModel
            {
                Url                      = _upsSettings.Url,
                AccountNumber            = _upsSettings.AccountNumber,
                AccessKey                = _upsSettings.AccessKey,
                Username                 = _upsSettings.Username,
                Password                 = _upsSettings.Password,
                AdditionalHandlingCharge = _upsSettings.AdditionalHandlingCharge,
                InsurePackage            = _upsSettings.InsurePackage,
                PackingPackageVolume     = _upsSettings.PackingPackageVolume,
                PackingType              = (int)_upsSettings.PackingType,
                PackingTypeValues        = _upsSettings.PackingType.ToSelectList(),
                PassDimensions           = _upsSettings.PassDimensions
            };

            foreach (UPSCustomerClassification customerClassification in Enum.GetValues(typeof(UPSCustomerClassification)))
            {
                model.AvailableCustomerClassifications.Add(new SelectListItem
                {
                    Text     = CommonHelper.ConvertEnum(customerClassification.ToString()),
                    Value    = customerClassification.ToString(),
                    Selected = customerClassification == _upsSettings.CustomerClassification
                });
            }
            foreach (UPSPickupType pickupType in Enum.GetValues(typeof(UPSPickupType)))
            {
                model.AvailablePickupTypes.Add(new SelectListItem
                {
                    Text     = CommonHelper.ConvertEnum(pickupType.ToString()),
                    Value    = pickupType.ToString(),
                    Selected = pickupType == _upsSettings.PickupType
                });
            }
            foreach (UPSPackagingType packagingType in Enum.GetValues(typeof(UPSPackagingType)))
            {
                model.AvailablePackagingTypes.Add(new SelectListItem
                {
                    Text     = CommonHelper.ConvertEnum(packagingType.ToString()),
                    Value    = packagingType.ToString(),
                    Selected = packagingType == _upsSettings.PackagingType
                });
            }

            // Load Domestic service names
            var carrierServicesOfferedDomestic = _upsSettings.CarrierServicesOffered;

            foreach (var service in UPSServices.Services)
            {
                model.AvailableCarrierServices.Add(service);
            }

            if (!string.IsNullOrEmpty(carrierServicesOfferedDomestic))
            {
                foreach (var service in UPSServices.Services)
                {
                    var serviceId = UPSServices.GetServiceId(service);
                    if (!string.IsNullOrEmpty(serviceId))
                    {
                        // Add delimiters [] so that single digit IDs aren't found in multi-digit IDs
                        if (carrierServicesOfferedDomestic.Contains($"[{serviceId}]"))
                        {
                            model.CarrierServicesOffered.Add(service);
                        }
                    }
                }
            }

            return(View("~/Plugins/Shipping.UPS/Views/Configure.cshtml", model));
        }
        public ActionResult Configure()
        {
            var model = new UPSModel();

            model.Url       = _upsSettings.Url;
            model.AccessKey = _upsSettings.AccessKey;
            model.Username  = _upsSettings.Username;
            model.Password  = _upsSettings.Password;
            model.AdditionalHandlingCharge = _upsSettings.AdditionalHandlingCharge;
            model.InsurePackage            = _upsSettings.InsurePackage;

            foreach (UPSCustomerClassification customerClassification in Enum.GetValues(typeof(UPSCustomerClassification)))
            {
                model.AvailableCustomerClassifications.Add(new SelectListItem()
                {
                    Text     = Inflector.Titleize(customerClassification.ToString()),
                    Value    = customerClassification.ToString(),
                    Selected = customerClassification == _upsSettings.CustomerClassification
                });
            }
            foreach (UPSPickupType pickupType in Enum.GetValues(typeof(UPSPickupType)))
            {
                model.AvailablePickupTypes.Add(new SelectListItem()
                {
                    Text     = Inflector.Titleize(pickupType.ToString()),
                    Value    = pickupType.ToString(),
                    Selected = pickupType == _upsSettings.PickupType
                });
            }
            foreach (UPSPackagingType packagingType in Enum.GetValues(typeof(UPSPackagingType)))
            {
                model.AvailablePackagingTypes.Add(new SelectListItem()
                {
                    Text     = Inflector.Titleize(packagingType.ToString()),
                    Value    = packagingType.ToString(),
                    Selected = packagingType == _upsSettings.PackagingType
                });
            }

            foreach (var country in _countryService.GetAllCountries(true))
            {
                model.AvailableCountries.Add(new SelectListItem()
                {
                    Text     = country.Name.ToString(),
                    Value    = country.Id.ToString(),
                    Selected = country.Id == _upsSettings.DefaultShippedFromCountryId
                });
            }
            model.DefaultShippedFromCountryId     = _upsSettings.DefaultShippedFromCountryId;
            model.DefaultShippedFromZipPostalCode = _upsSettings.DefaultShippedFromZipPostalCode;

            var services = new UPSServices();
            // Load Domestic service names
            string carrierServicesOfferedDomestic = _upsSettings.CarrierServicesOffered;

            foreach (string service in services.Services)
            {
                model.AvailableCarrierServices.Add(service);
            }

            if (!String.IsNullOrEmpty(carrierServicesOfferedDomestic))
            {
                foreach (string service in services.Services)
                {
                    string serviceId = UPSServices.GetServiceId(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.CarrierServicesOffered.Add(service);
                        }
                    }
                }
            }

            return(View(model));
        }