The errors
"The length of the destination state or province exceeds the limit of 2 characters." and
"The length of the origin state or province exceeds the limit of 2 characters." are caused when the state code is not two characters in either the customer selected state/province (from the Nop_StateProvince table) or the FedEx configuration "Shipping origin. State code" setting. The following changes shall allow you to use FedEx to ship to/from the United Kingdom. Note, the following line numbers refer to 1.90.
Edit file:
Shipping\Nop.Shipping.FedEx\FedExComputationMethod.csChange line 126 (in
SetDestination() method) from:
if (ShipmentPackage.ShippingAddress.StateProvince != null)
to:
if (ShipmentPackage.ShippingAddress.StateProvince != null && IncludeStateProvidenceCode(ShipmentPackage.ShippingAddress.Country.TwoLetterIsoCode))
Change method
SetOrigin() from:
private void SetOrigin(RateRequest request)
{
request.RequestedShipment.Shipper = new Party();
request.RequestedShipment.Shipper.Address = new Address();
request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.Street") };
request.RequestedShipment.Shipper.Address.City = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.City");
request.RequestedShipment.Shipper.Address.StateOrProvinceCode = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.StateOrProvinceCode");
request.RequestedShipment.Shipper.Address.PostalCode = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.PostalCode");
request.RequestedShipment.Shipper.Address.CountryCode = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.CountryCode");
}
to:
private void SetOrigin(RateRequest request)
{
request.RequestedShipment.Shipper = new Party();
request.RequestedShipment.Shipper.Address = new Address();
request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.Street") };
request.RequestedShipment.Shipper.Address.City = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.City");
string countryCode = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.CountryCode");
if (IncludeStateProvidenceCode(countryCode))
{
request.RequestedShipment.Shipper.Address.StateOrProvinceCode = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.StateOrProvinceCode");
}
request.RequestedShipment.Shipper.Address.PostalCode = IoC.Resolve<ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.ShippingOrigin.PostalCode");
request.RequestedShipment.Shipper.Address.CountryCode = countryCode;
}
Add the following method:
private bool IncludeStateProvidenceCode(string countryCode)
{
return (countryCode.Equals("US", StringComparison.InvariantCultureIgnoreCase) ||
countryCode.Equals("CA", StringComparison.InvariantCultureIgnoreCase));
}
These changes will cause the rate request to include the state code only if it is required (when the country is US or CA).
---
To ensure the store owner only sets two characters for the state code in the FedEx configuration, edit file
Administration\Shipping\FedExConfigure\ConfigureShipping.ascx.csChange line 101 from:
this.SettingManager.SetParam("ShippingRateComputationMethod.FedEx.ShippingOrigin.StateOrProvinceCode", txtShippingOriginStateOrProvinceCode.Text);
to:
string stateCode = CommonHelper.EnsureMaximumLength(txtShippingOriginStateOrProvinceCode.Text, 2);
this.SettingManager.SetParam("ShippingRateComputationMethod.FedEx.ShippingOrigin.StateOrProvinceCode", stateCode);
Edit file:
Administration\Shipping\FedExConfigure\ConfigureShipping.ascxChange line 102 from:
Shipping origin. State code:
to
Shipping origin. State code (2 characters):
Recompile the solution and copy the updated NopCommerceStore.dll and Nop.Shipping.FedEx.dll assemblies to the bin folder on your server and copy ConfigureShipping.ascx to the Administration\Shipping\FedExConfigure\ folder on your server.
.