|
UPS Shipping Calculation Fix-
If you have access to the source code, do the following then recompile and replace your old Nop.Shipping.Ups with the now working one:
using UPSComputationMethod.cs
add
using NopSolutions.NopCommerce.BusinessLogic.Orders;
and replace the CreateRequest function with this
private string CreateRequest(string AccessKey, string Username, string Password, ShipmentPackage ShipmentPackage, UPSCustomerClassification customerClassification, UPSPickupType pickupType, UPSPackagingType packagingType) { var usedMeasureWeight = IoC.Resolve<IMeasureService>().GetMeasureWeightBySystemKeyword(MEASUREWEIGHTSYSTEMKEYWORD); if (usedMeasureWeight == null) throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure weight", MEASUREWEIGHTSYSTEMKEYWORD));
var usedMeasureDimension = IoC.Resolve<IMeasureService>().GetMeasureDimensionBySystemKeyword(MEASUREDIMENSIONSYSTEMKEYWORD); if (usedMeasureDimension == null) throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure dimension", MEASUREDIMENSIONSYSTEMKEYWORD));
string zipPostalCodeFrom = ShipmentPackage.ZipPostalCodeFrom; string zipPostalCodeTo = ShipmentPackage.ShippingAddress.ZipPostalCode; string countryCodeFrom = ShipmentPackage.CountryFrom.TwoLetterIsoCode; string countryCodeTo = ShipmentPackage.ShippingAddress.Country.TwoLetterIsoCode;
var sb = new StringBuilder(); sb.Append("<?xml version='1.0'?>"); sb.Append("<AccessRequest xml:lang='en-US'>"); sb.AppendFormat("<AccessLicenseNumber>{0}</AccessLicenseNumber>", AccessKey); sb.AppendFormat("<UserId>{0}</UserId>", Username); sb.AppendFormat("<Password>{0}</Password>", Password); sb.Append("</AccessRequest>"); sb.Append("<?xml version='1.0'?>"); sb.Append("<RatingServiceSelectionRequest xml:lang='en-US'>"); sb.Append("<Request>"); sb.Append("<TransactionReference>"); sb.Append("<CustomerContext>Bare Bones Rate Request</CustomerContext>"); sb.Append("<XpciVersion>1.0001</XpciVersion>"); sb.Append("</TransactionReference>"); sb.Append("<RequestAction>Rate</RequestAction>"); sb.Append("<RequestOption>Shop</RequestOption>"); sb.Append("</Request>"); if (String.Equals(countryCodeFrom, "US", StringComparison.InvariantCultureIgnoreCase) == true) { sb.Append("<PickupType>"); sb.AppendFormat("<Code>{0}</Code>", GetPickupTypeCode(pickupType)); sb.Append("</PickupType>"); sb.Append("<CustomerClassification>"); sb.AppendFormat("<Code>{0}</Code>", GetCustomerClassificationCode(customerClassification)); sb.Append("</CustomerClassification>"); } sb.Append("<Shipment>"); sb.Append("<Shipper>"); sb.Append("<Address>"); sb.AppendFormat("<PostalCode>{0}</PostalCode>", zipPostalCodeFrom); sb.AppendFormat("<CountryCode>{0}</CountryCode>", countryCodeFrom); sb.Append("</Address>"); sb.Append("</Shipper>"); sb.Append("<ShipTo>"); sb.Append("<Address>"); sb.Append("<ResidentialAddressIndicator/>"); sb.AppendFormat("<PostalCode>{0}</PostalCode>", zipPostalCodeTo); sb.AppendFormat("<CountryCode>{0}</CountryCode>", countryCodeTo); sb.Append("</Address>"); sb.Append("</ShipTo>"); sb.Append("<ShipFrom>"); sb.Append("<Address>"); sb.AppendFormat("<PostalCode>{0}</PostalCode>", zipPostalCodeFrom); sb.AppendFormat("<CountryCode>{0}</CountryCode>", countryCodeFrom); sb.Append("</Address>"); sb.Append("</ShipFrom>"); sb.Append("<Service>"); sb.Append("<Code>03</Code>"); sb.Append("</Service>");
decimal dWidth = 0; decimal dHeight = 0; decimal dWeight = 0; decimal dLength = 0; foreach (ShoppingCartItem scPack in ShipmentPackage.Items) { dWidth = scPack.ProductVariant.Width; dHeight = scPack.ProductVariant.Height; dWeight = scPack.ProductVariant.Weight; dLength = scPack.ProductVariant.Length; int length = Convert.ToInt32(Math.Ceiling(IoC.Resolve<IMeasureService>().ConvertDimension(dLength, IoC.Resolve<IMeasureService>().BaseDimensionIn, usedMeasureDimension))); int height = Convert.ToInt32(Math.Ceiling(IoC.Resolve<IMeasureService>().ConvertDimension(dHeight, IoC.Resolve<IMeasureService>().BaseDimensionIn, usedMeasureDimension))); int width = Convert.ToInt32(Math.Ceiling(IoC.Resolve<IMeasureService>().ConvertDimension(dWidth, IoC.Resolve<IMeasureService>().BaseDimensionIn, usedMeasureDimension))); int weight = Convert.ToInt32(Math.Ceiling(IoC.Resolve<IMeasureService>().ConvertWeight(dWeight, IoC.Resolve<IMeasureService>().BaseWeightIn, usedMeasureWeight))); if (length < 1) length = 1; if (height < 1) height = 1; if (width < 1) width = 1; if (weight < 1) weight = 1; int i = scPack.Quantity; while (i>0) { sb.Append("<Package>"); sb.Append("<PackagingType>"); sb.AppendFormat("<Code>{0}</Code>", GetPackagingTypeCode(packagingType)); sb.Append("</PackagingType>"); sb.Append("<Dimensions>"); if (IsPackageTooLarge(length, height, width)) { sb.AppendFormat("<Length>{0}</Length>", 33); sb.AppendFormat("<Width>{0}</Width>", 33); sb.AppendFormat("<Height>{0}</Height>", 33); } else { sb.AppendFormat("<Length>{0}</Length>", dLength.ToString("N2")); sb.AppendFormat("<Width>{0}</Width>", dWidth.ToString("N2")); sb.AppendFormat("<Height>{0}</Height>", dHeight.ToString("N2")); } sb.Append("</Dimensions>"); sb.Append("<PackageWeight>"); if (IsPackageTooHeavy(weight)) { sb.AppendFormat("<Weight>{0}</Weight>", MAXPACKAGEWEIGHT); } else { sb.AppendFormat("<Weight>{0}</Weight>", dWeight.ToString("N2")); } sb.Append("</PackageWeight>"); sb.Append("</Package>"); i--; } } sb.Append("</Shipment>"); sb.Append("</RatingServiceSelectionRequest>"); string requestString = sb.ToString(); return requestString; }
|