本文整理汇总了C#中Nop.Services.Shipping.GetShippingOptionRequest.GetTotalLength方法的典型用法代码示例。如果您正苦于以下问题:C# GetShippingOptionRequest.GetTotalLength方法的具体用法?C# GetShippingOptionRequest.GetTotalLength怎么用?C# GetShippingOptionRequest.GetTotalLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nop.Services.Shipping.GetShippingOptionRequest
的用法示例。
在下文中一共展示了GetShippingOptionRequest.GetTotalLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRequest
private string CreateRequest(string username, string password, GetShippingOptionRequest getShippingOptionRequest)
{
var usedMeasureWeight = _measureService.GetMeasureWeightBySystemKeyword(MEASUREWEIGHTSYSTEMKEYWORD);
if (usedMeasureWeight == null)
throw new NopException(string.Format("USPS shipping service. Could not load \"{0}\" measure weight", MEASUREWEIGHTSYSTEMKEYWORD));
var baseusedMeasureWeight = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId);
if (baseusedMeasureWeight == null)
throw new NopException("Primary weight can't be loaded");
var usedMeasureDimension = _measureService.GetMeasureDimensionBySystemKeyword(MEASUREDIMENSIONSYSTEMKEYWORD);
if (usedMeasureDimension == null)
throw new NopException(string.Format("USPS shipping service. Could not load \"{0}\" measure dimension", MEASUREDIMENSIONSYSTEMKEYWORD));
var baseusedMeasureDimension = _measureService.GetMeasureDimensionById(_measureSettings.BaseDimensionId);
if (usedMeasureDimension == null)
throw new NopException("Primary dimension can't be loaded");
int length = Convert.ToInt32(Math.Ceiling(getShippingOptionRequest.GetTotalLength() / baseusedMeasureDimension.Ratio * usedMeasureDimension.Ratio));
int height = Convert.ToInt32(Math.Ceiling(getShippingOptionRequest.GetTotalHeight() / baseusedMeasureDimension.Ratio * usedMeasureDimension.Ratio));
int width = Convert.ToInt32(Math.Ceiling(getShippingOptionRequest.GetTotalWidth() / baseusedMeasureDimension.Ratio * usedMeasureDimension.Ratio));
int weight = Convert.ToInt32(Math.Ceiling(_shippingService.GetShoppingCartTotalWeight(getShippingOptionRequest.Items) / baseusedMeasureWeight.Ratio * usedMeasureWeight.Ratio));
if (length < 1)
length = 1;
if (height < 1)
height = 1;
if (width < 1)
width = 1;
if (weight < 1)
weight = 1;
string zipPostalCodeFrom = getShippingOptionRequest.ZipPostalCodeFrom;
string zipPostalCodeTo = getShippingOptionRequest.ShippingAddress.ZipPostalCode;
//valid values for testing. http://testing.shippingapis.com/ShippingAPITest.dll
//Zip to = "20008"; Zip from ="10022"; weight = 2;
int pounds = Convert.ToInt32(weight / 16);
int ounces = Convert.ToInt32(weight - (pounds * 16.0M));
int girth = height + height + width + width;
//Get shopping cart sub-total. V2 International rates require the package value to be declared.
decimal subTotal = decimal.Zero;
foreach (var shoppingCartItem in getShippingOptionRequest.Items)
{
if (!shoppingCartItem.IsShipEnabled)
continue;
subTotal += _priceCalculationService.GetSubTotal(shoppingCartItem, true);
}
string requestString = string.Empty;
bool isDomestic = IsDomesticRequest(getShippingOptionRequest);
if (isDomestic)
{
#region domestic request
zipPostalCodeFrom = CommonHelper.EnsureMaximumLength(CommonHelper.EnsureNumericOnly(zipPostalCodeFrom), 5);
zipPostalCodeTo = CommonHelper.EnsureMaximumLength(CommonHelper.EnsureNumericOnly(zipPostalCodeTo), 5);
var sb = new StringBuilder();
sb.AppendFormat("<RateV4Request USERID=\"{0}\" PASSWORD=\"{1}\">", username, password);
sb.Append("<Revision>2</Revision>");
var xmlStrings = new USPSStrings(); // Create new instance with string array
if ((!IsPackageTooHeavy(pounds)) && (!IsPackageTooLarge(length, height, width)))
{
var packageSize = GetPackageSize(length, height, width);
// RJH get all XML strings not commented out for USPSStrings.
// RJH V3 USPS Service must be Express, Express SH, Express Commercial, Express SH Commercial, First Class, Priority, Priority Commercial, Parcel, Library, BPM, Media, ALL or ONLINE;
// AC - Updated to V4 API and made minor improvements to allow First Class Packages (package only - not envelopes).
foreach (string element in xmlStrings.Elements) // Loop over elements with property
{
if ((element == "First Class") && (weight >= 14))
{
// AC - At the time of coding there aren't any First Class shipping options for packages over 13 ounces.
}
else
{
sb.Append("<Package ID=\"0\">");
sb.AppendFormat("<Service>{0}</Service>", element);
if (element == "First Class")
sb.Append("<FirstClassMailType>PARCEL</FirstClassMailType>");
sb.AppendFormat("<ZipOrigination>{0}</ZipOrigination>", zipPostalCodeFrom);
sb.AppendFormat("<ZipDestination>{0}</ZipDestination>", zipPostalCodeTo);
sb.AppendFormat("<Pounds>{0}</Pounds>", pounds);
sb.AppendFormat("<Ounces>{0}</Ounces>", ounces);
sb.Append("<Container/>");
sb.AppendFormat("<Size>{0}</Size>", packageSize);
sb.AppendFormat("<Width>{0}</Width>", width);
sb.AppendFormat("<Length>{0}</Length>", length);
sb.AppendFormat("<Height>{0}</Height>", height);
sb.AppendFormat("<Girth>{0}</Girth>", girth);
sb.Append("<Machinable>FALSE</Machinable>");
sb.Append("</Package>");
//.........这里部分代码省略.........
示例2: GetLength
private int GetLength(GetShippingOptionRequest getShippingOptionRequest)
{
int value = Convert.ToInt32(Math.Ceiling(this._measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalLength(), this.GatewayMeasureDimension)));
return (value < MIN_LENGTH ? MIN_LENGTH : value);
}
示例3: SetIndividualPackageLineItems
private void SetIndividualPackageLineItems(RateRequest request, GetShippingOptionRequest getShippingOptionRequest, decimal orderSubTotal, string currencyCode)
{
// Rate request setup - Total Dimensions of Shopping Cart Items determines number of packages
var usedMeasureWeight = GetUsedMeasureWeight();
var usedMeasureDimension = GetUsedMeasureDimension();
int length = ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalLength(), usedMeasureDimension);
int height = ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalHeight(), usedMeasureDimension);
int width = ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalWidth(), usedMeasureDimension);
int weight = ConvertFromPrimaryMeasureWeight(_shippingService.GetShoppingCartTotalWeight(getShippingOptionRequest.Items), usedMeasureWeight);
if (length < 1)
length = 1;
if (height < 1)
height = 1;
if (width < 1)
width = 1;
if (weight < 1)
weight = 1;
if ((!IsPackageTooHeavy(weight)) && (!IsPackageTooLarge(length, height, width)))
{
request.RequestedShipment.PackageCount = "1";
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1];
request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
request.RequestedShipment.RequestedPackageLineItems[0].Weight = new RateServiceWebReference.Weight(); // package weight
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = RateServiceWebReference.WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = weight;
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new RateServiceWebReference.Dimensions(); // package dimensions
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = _fedexSettings.PassDimensions ? length.ToString() : "0";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = _fedexSettings.PassDimensions ? width.ToString() : "0";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = _fedexSettings.PassDimensions ? height.ToString() : "0";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = RateServiceWebReference.LinearUnits.IN;
request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money(); // insured value
request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = orderSubTotal;
request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = currencyCode;
}
else
{
int totalPackages = 1;
int totalPackagesDims = 1;
int totalPackagesWeights = 1;
if (IsPackageTooHeavy(weight))
{
totalPackagesWeights = Convert.ToInt32(Math.Ceiling((decimal)weight / (decimal)MAXPACKAGEWEIGHT));
}
if (IsPackageTooLarge(length, height, width))
{
totalPackagesDims = Convert.ToInt32(Math.Ceiling((decimal)TotalPackageSize(length, height, width) / (decimal)108));
}
totalPackages = totalPackagesDims > totalPackagesWeights ? totalPackagesDims : totalPackagesWeights;
if (totalPackages == 0)
totalPackages = 1;
int weight2 = weight / totalPackages;
int height2 = height / totalPackages;
int width2 = width / totalPackages;
int length2 = length / totalPackages;
if (weight2 < 1)
weight2 = 1;
if (height2 < 1)
height2 = 1;
if (width2 < 1)
width2 = 1;
if (length2 < 1)
length2 = 1;
decimal orderSubTotal2 = orderSubTotal / totalPackages;
request.RequestedShipment.PackageCount = totalPackages.ToString();
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[totalPackages];
for (int i = 0; i < totalPackages; i++)
{
request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[i].SequenceNumber = (i + 1).ToString(); // package sequence number
request.RequestedShipment.RequestedPackageLineItems[i].Weight = new RateServiceWebReference.Weight(); // package weight
request.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = RateServiceWebReference.WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = (decimal)weight2;
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions = new RateServiceWebReference.Dimensions(); // package dimensions
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = _fedexSettings.PassDimensions ? length2.ToString() : "0";
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width = _fedexSettings.PassDimensions ? width2.ToString() : "0";
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = _fedexSettings.PassDimensions ? height2.ToString() : "0";
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units = RateServiceWebReference.LinearUnits.IN;
request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue = new Money(); // insured value
request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Amount = orderSubTotal2;
request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Currency = currencyCode;
}
}
}
示例4: SetIndividualPackageLineItems
private void SetIndividualPackageLineItems(RateRequest request, GetShippingOptionRequest getShippingOptionRequest, decimal orderSubTotal)
{
// ------------------------------------------
// Passing individual pieces rate request
// ------------------------------------------
var usedMeasureWeight = _measureService.GetMeasureWeightBySystemKeyword(MEASUREWEIGHTSYSTEMKEYWORD);
if (usedMeasureWeight == null)
throw new NopException(string.Format("FedEx shipping service. Could not load \"{0}\" measure weight", MEASUREWEIGHTSYSTEMKEYWORD));
var usedMeasureDimension = _measureService.GetMeasureDimensionBySystemKeyword(MEASUREDIMENSIONSYSTEMKEYWORD);
if (usedMeasureDimension == null)
throw new NopException(string.Format("FedEx shipping service. Could not load \"{0}\" measure dimension", MEASUREDIMENSIONSYSTEMKEYWORD));
int length = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalLength(), usedMeasureDimension)));
int height = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalHeight(), usedMeasureDimension)));
int width = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalWidth(), usedMeasureDimension)));
int weight = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureWeight(_shippingService.GetShoppingCartTotalWeight(getShippingOptionRequest.Items), usedMeasureWeight)));
if (length < 1)
length = 1;
if (height < 1)
height = 1;
if (width < 1)
width = 1;
if (weight < 1)
weight = 1;
if ((!IsPackageTooHeavy(weight)) && (!IsPackageTooLarge(length, height, width)))
{
request.RequestedShipment.PackageCount = "1";
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1];
request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight(); // package weight
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = weight;
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions(); // package dimensions
//it's better to don't pass dims now
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "0";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "0";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "0";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money(); // insured value
request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = orderSubTotal;
request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
}
else
{
int totalPackages = 1;
int totalPackagesDims = 1;
int totalPackagesWeights = 1;
if (IsPackageTooHeavy(weight))
{
totalPackagesWeights = Convert.ToInt32(Math.Ceiling((decimal)weight / (decimal)MAXPACKAGEWEIGHT));
}
if (IsPackageTooLarge(length, height, width))
{
totalPackagesDims = Convert.ToInt32(Math.Ceiling((decimal)TotalPackageSize(length, height, width) / (decimal)108));
}
totalPackages = totalPackagesDims > totalPackagesWeights ? totalPackagesDims : totalPackagesWeights;
if (totalPackages == 0)
totalPackages = 1;
int weight2 = weight / totalPackages;
int height2 = height / totalPackages;
int width2 = width / totalPackages;
int length2 = length / totalPackages;
if (weight2 < 1)
weight2 = 1;
if (height2 < 1)
height2 = 1;
if (width2 < 1)
width2 = 1;
if (length2 < 1)
length2 = 1;
decimal orderSubTotal2 = orderSubTotal / totalPackages;
request.RequestedShipment.PackageCount = totalPackages.ToString();
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[totalPackages];
for (int i = 0; i < totalPackages; i++)
{
request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[i].SequenceNumber = (i + 1).ToString(); // package sequence number
request.RequestedShipment.RequestedPackageLineItems[i].Weight = new Weight(); // package weight
request.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = (decimal)weight2;
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions = new Dimensions(); // package dimensions
//it's better to don't pass dims now
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = "0";
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width = "0";
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = "0";
request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units = LinearUnits.IN;
request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue = new Money(); // insured value
request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Amount = orderSubTotal2;
//.........这里部分代码省略.........
示例5: CreateRequest
private string CreateRequest(string accessKey, string username, string password,
GetShippingOptionRequest getShippingOptionRequest, UPSCustomerClassification customerClassification,
UPSPickupType pickupType, UPSPackagingType packagingType)
{
var usedMeasureWeight = _measureService.GetMeasureWeightBySystemKeyword(MEASUREWEIGHTSYSTEMKEYWORD);
if (usedMeasureWeight == null)
throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure weight", MEASUREWEIGHTSYSTEMKEYWORD));
var usedMeasureDimension = _measureService.GetMeasureDimensionBySystemKeyword(MEASUREDIMENSIONSYSTEMKEYWORD);
if (usedMeasureDimension == null)
throw new NopException(string.Format("UPS shipping service. Could not load \"{0}\" measure dimension", MEASUREDIMENSIONSYSTEMKEYWORD));
int length = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalLength(), usedMeasureDimension)));
int height = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalHeight(), usedMeasureDimension)));
int width = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalWidth(), usedMeasureDimension)));
int weight = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureWeight(_shippingService.GetShoppingCartTotalWeight(getShippingOptionRequest.Items), usedMeasureWeight)));
if (length < 1)
length = 1;
if (height < 1)
height = 1;
if (width < 1)
width = 1;
if (weight < 1)
weight = 1;
string zipPostalCodeFrom = getShippingOptionRequest.ZipPostalCodeFrom;
string zipPostalCodeTo = getShippingOptionRequest.ShippingAddress.ZipPostalCode;
string countryCodeFrom = getShippingOptionRequest.CountryFrom.TwoLetterIsoCode;
string countryCodeTo = getShippingOptionRequest.ShippingAddress.Country.TwoLetterIsoCode;
decimal orderSubTotalDiscountAmount = decimal.Zero;
Discount orderSubTotalAppliedDiscount = null;
decimal subTotalWithoutDiscountBase = decimal.Zero;
decimal subTotalWithDiscountBase = decimal.Zero;
_orderTotalCalculationService.GetShoppingCartSubTotal(getShippingOptionRequest.Items,
out orderSubTotalDiscountAmount, out orderSubTotalAppliedDiscount,
out subTotalWithoutDiscountBase, out subTotalWithDiscountBase);
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>");
if ((!IsPackageTooHeavy(weight)) && (!IsPackageTooLarge(length, height, width)))
{
sb.Append("<Package>");
sb.Append("<PackagingType>");
sb.AppendFormat("<Code>{0}</Code>", GetPackagingTypeCode(packagingType));
sb.Append("</PackagingType>");
sb.Append("<Dimensions>");
sb.AppendFormat("<Length>{0}</Length>", length);
sb.AppendFormat("<Width>{0}</Width>", width);
sb.AppendFormat("<Height>{0}</Height>", height);
sb.Append("</Dimensions>");
sb.Append("<PackageWeight>");
//.........这里部分代码省略.........
示例6: ProcessShipping
private cResultado ProcessShipping(GetShippingOptionRequest getShippingOptionRequest, GetShippingOptionResponse getShippingOptionResponse)
{
var usedMeasureWeight = _measureService.GetMeasureWeightBySystemKeyword(MEASURE_WEIGHT_SYSTEM_KEYWORD);
if (usedMeasureWeight == null)
{
string e = string.Format("Plugin.Shipping.Correios: Could not load \"{0}\" measure weight", MEASURE_WEIGHT_SYSTEM_KEYWORD);
_logger.Fatal(e);
throw new NopException(e);
}
var usedMeasureDimension = _measureService.GetMeasureDimensionBySystemKeyword(MEASURE_DIMENSION_SYSTEM_KEYWORD);
if (usedMeasureDimension == null)
{
string e = string.Format("Plugin.Shipping.Correios: Could not load \"{0}\" measure dimension", MEASURE_DIMENSION_SYSTEM_KEYWORD);
_logger.Fatal(e);
throw new NopException(e);
}
//Na versão 2.2 o getShippingOptionRequest.ZipPostalCodeFrom retorna string.Empty, possui um TODO...
string cepOrigem = null;
if (this._shippingSettings.ShippingOriginAddressId > 0)
{
var addr = this._addressService.GetAddressById(this._shippingSettings.ShippingOriginAddressId);
if (addr != null && !String.IsNullOrEmpty(addr.ZipPostalCode) && addr.ZipPostalCode.Length >= 8 && addr.ZipPostalCode.Length <= 9)
{
cepOrigem = addr.ZipPostalCode;
}
}
if (cepOrigem == null)
{
_logger.Fatal("Plugin.Shipping.Correios: CEP de Envio em branco ou inválido, configure nas opções de envio do NopCommerce.Em Administração > Configurações > Configurações de Envio. Formato: 00000000");
throw new NopException("Plugin.Shipping.Correios: CEP de Envio em branco ou inválido, configure nas opções de envio do NopCommerce.Em Administração > Configurações > Configurações de Envio. Formato: 00000000");
}
var correiosCalculation = new CorreiosBatchCalculation(this._logger)
{
CodigoEmpresa = _correiosSettings.CodigoEmpresa,
Senha = _correiosSettings.Senha,
CepOrigem = cepOrigem,
Servicos = _correiosSettings.CarrierServicesOffered,
AvisoRecebimento = _correiosSettings.IncluirAvisoRecebimento,
MaoPropria = _correiosSettings.IncluirMaoPropria,
CepDestino = getShippingOptionRequest.ShippingAddress.ZipPostalCode
};
decimal subtotalBase = decimal.Zero;
decimal orderSubTotalDiscountAmount = decimal.Zero;
Discount orderSubTotalAppliedDiscount = null;
decimal subTotalWithoutDiscountBase = decimal.Zero;
decimal subTotalWithDiscountBase = decimal.Zero;
_orderTotalCalculationService.GetShoppingCartSubTotal(getShippingOptionRequest.Items,
out orderSubTotalDiscountAmount, out orderSubTotalAppliedDiscount,
out subTotalWithoutDiscountBase, out subTotalWithDiscountBase);
subtotalBase = subTotalWithDiscountBase;
int length = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalLength(), usedMeasureDimension)) / 10);
int height = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalHeight(), usedMeasureDimension)) / 10);
int width = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureDimension(getShippingOptionRequest.GetTotalWidth(), usedMeasureDimension)) / 10);
int weight = Convert.ToInt32(Math.Ceiling(_measureService.ConvertFromPrimaryMeasureWeight(_shippingService.GetShoppingCartTotalWeight(getShippingOptionRequest.Items), usedMeasureWeight)));
if (length < 1)
length = 1;
if (height < 1)
height = 1;
if (width < 1)
width = 1;
if (weight < 1)
weight = 1;
//Altura não pode ser maior que o comprimento, para evitar erro, igualamos e a embalagem deve ser adaptada.
if (height > length)
{
length = height;
}
if (IsPackageTooSmall(length, height, width))
{
length = MIN_PACKAGE_LENGTH;
height = MIN_PACKAGE_HEIGHT;
width = MIN_PACKAGE_WIDTH;
}
if ((!IsPackageTooHeavy(weight)) && (!IsPackageTooLarge(length, height, width)))
{
Debug.WriteLine("Plugin.Shipping.Correios: Pacote unico");
correiosCalculation.Pacotes.Add(new CorreiosBatchCalculation.Pacote()
//.........这里部分代码省略.........