public override ShipRateQuote GetShipRateQuote(Warehouse origin, CommerceBuilder.Users.Address destination, BasketItemCollection contents, string serviceCode) { //VERIFY WE HAVE A DESTINATION COUNTRY if (string.IsNullOrEmpty(destination.CountryCode)) { return(null); } //VERIFY THAT ORIGIN COUNTRY IS AU if (string.IsNullOrEmpty(origin.CountryCode) || !origin.CountryCode.Equals("AU")) { return(null); } if (destination.CountryCode.Equals("AU")) { //if destination is also AU only domestic services are applicable if (!IsDomesticService(serviceCode)) { return(null); } } else { //only international services are available if (IsDomesticService(serviceCode)) { return(null); } } PackageList plist = PreparePackages(origin, contents); if (plist == null || plist.Count == 0) { return(null); } ProviderShipRateQuote providerQuote = null; ProviderShipRateQuote tempQuote; foreach (Package item in plist) { tempQuote = GetProviderQuote(origin, destination, item, serviceCode); if (providerQuote == null) { providerQuote = tempQuote; } else { providerQuote.AddPackageQoute(tempQuote); } } if (providerQuote != null && providerQuote.PackageCount < plist.Count) { return(null); } return(providerQuote); }
private ProviderShipRateQuote ParseProviderResponse(string providerResponse, Address destination, string serviceCode) { ProviderShipRateQuote quote = new ProviderShipRateQuote(); if (string.IsNullOrEmpty(providerResponse)) { return(null); } StringReader sr = new StringReader(providerResponse); string chargeLine = sr.ReadLine(); string days = sr.ReadLine(); string errmsg = sr.ReadLine(); if (!string.IsNullOrEmpty(errmsg) && errmsg.EndsWith("OK")) { int index; if (!string.IsNullOrEmpty(chargeLine)) { index = chargeLine.IndexOf("charge="); quote.Rate = AlwaysConvert.ToDecimal(chargeLine.Substring(index + 7)); quote.PackageCount = 1; quote.ServiceCode = serviceCode; quote.ServiceName = GetServiceName(serviceCode); } } return(quote); }
private Dictionary <string, ProviderShipRateQuote> ParseProviderRateReponseIntl(XmlDocument providerResponse, Package[] packageList) { //CREATE TEMPORARY STORAGE FOR PARSING THE QUOTED SERVICES Dictionary <string, ProviderShipRateQuote> availableServices = new Dictionary <string, ProviderShipRateQuote>(); ProviderShipRateQuote serviceQuote; //LOOP EACH PACKAGE IN THE RESPONSE XmlNodeList packageNodeList = providerResponse.DocumentElement.SelectNodes("Package"); foreach (XmlNode packageNode in packageNodeList) { XmlNodeList serviceNodeList = packageNode.SelectNodes("Service"); foreach (XmlNode serviceNode in serviceNodeList) { string serviceName = XmlUtility.GetElementValue(serviceNode, "SvcDescription", string.Empty); LSDecimal postage = AlwaysConvert.ToDecimal(XmlUtility.GetElementValue(serviceNode, "Postage", string.Empty)); if (postage > 0) { //GET THE INSTANCE OF SERVICEQUOTE TO BE UPDATED if (availableServices.ContainsKey(serviceName)) { serviceQuote = availableServices[serviceName]; } else { //CREATE A NEW INSTANCE OF ProviderShipRateQuote serviceQuote = new ProviderShipRateQuote(); serviceQuote.ServiceCode = serviceName; availableServices.Add(serviceName, serviceQuote); } //GET THE PACKAGE ID FROM THE RATE int packageId = AlwaysConvert.ToInt(XmlUtility.GetAttributeValue(packageNode, "ID", string.Empty), -1); if (packageId != -1) { //FIND THE PACKAGE IN THE LIST Package package = packageList[packageId]; serviceQuote.Rate += (postage * package.Multiplier); serviceQuote.PackageCount += 1; } } } } //MOVE THROUGH LIST AND FIND SERVICES THAT ARE NOT AVAILABLE //FOR ALL PACKAGES IN THE SHIPMENT List <string> removeServices = new List <string>(); foreach (string serviceName in availableServices.Keys) { serviceQuote = availableServices[serviceName]; if (serviceQuote.PackageCount < packageList.Length) { removeServices.Add(serviceName); } } //REMOVE ANY SERVICES THAT WERE IDENTIFIED foreach (string serviceName in removeServices) { availableServices.Remove(serviceName); } return(availableServices); }
public override ShipRateQuote GetShipRateQuote(Warehouse origin, CommerceBuilder.Users.Address destination, BasketItemCollection contents, string serviceCode) { //GET THE SHIP QUOTE FOR THE GIVEN SERVICE //GET THE RATE FOR ALL SERVICES Dictionary <String, ProviderShipRateQuote> allProviderQuotes = GetAllProviderShipRateQuotes(origin, destination, contents); if (allProviderQuotes != null && allProviderQuotes.ContainsKey(serviceCode)) { ProviderShipRateQuote providerQuote = allProviderQuotes[serviceCode]; ShipRateQuote quote = new ShipRateQuote(); quote.Rate = providerQuote.Rate; return(quote); } return(null); }
private List <ProviderShipRateQuote> ParseProviderResponse(XmlDocument providerResponse, Address destination) { List <ProviderShipRateQuote> providerQuotes = new List <ProviderShipRateQuote>(); XmlElement respDocElement = providerResponse.DocumentElement; XmlNodeList errorList = respDocElement.GetElementsByTagName("error"); if (errorList.Count > 0) { string errorCode = XmlUtility.GetElementValue(respDocElement, "error/statusCode", string.Empty); string errorMessage = XmlUtility.GetElementValue(respDocElement, "error/statusMessage", "Unknown Error."); //IF AN ERROR IS THROWN HERE, SHIPPING RATES WILL NEVER BE CACHED //SO THE PROCESS WILL CONTINUE TO REQUEST AGAINST CP SERVER FOR EACH SHIPPING METHOD //INSTEAD THE ERROR IS LOGGED AND WE SHOULD RETURN AN EMPTY RATE LIST Logger.Error("Error retrieving CanadaPost rates; Code = " + errorCode + "; Message = " + errorMessage); } else { XmlElement nodEntry = null; string tempServiceCode = string.Empty; LSDecimal tempRate; ProviderShipRateQuote quote; XmlNodeList nlsPackages = respDocElement.GetElementsByTagName("product"); foreach (XmlNode nodeItem in nlsPackages) { nodEntry = (XmlElement)nodeItem; tempServiceCode = nodEntry.GetAttribute("id"); tempRate = AlwaysConvert.ToDecimal(XmlUtility.GetElementValue(nodEntry, "rate"), 0); if (tempRate > 0) { quote = new ProviderShipRateQuote(); quote.ServiceCode = tempServiceCode; quote.ServiceName = GetServiceName(tempServiceCode); quote.Rate = tempRate; quote.PackageCount = 1; providerQuotes.Add(quote); } } nodEntry = null; nlsPackages = null; } return(providerQuotes); }
private Dictionary <string, ProviderShipRateQuote> ParseRates(RateReply reply) { Dictionary <string, ProviderShipRateQuote> quotes = new Dictionary <string, ProviderShipRateQuote>(); for (int i = 0; i < reply.RateReplyDetails.Length; i++) { RateReplyDetail rdetail = reply.RateReplyDetails[i]; RatedShipmentDetail rsdetail = GetRatedShipmentDetail(rdetail.RatedShipmentDetails); if (rsdetail != null) { ProviderShipRateQuote psrq = new ProviderShipRateQuote(); psrq.ServiceCode = rdetail.ServiceType.ToString(); //psrq.Name = GetServiceName(psrq.ServiceCode); psrq.ServiceName = GetServiceName(psrq.ServiceCode); psrq.Rate = rsdetail.ShipmentRateDetail.TotalNetCharge.Amount; quotes.Add(psrq.ServiceCode, psrq); } } return(quotes); }
private List <ProviderShipRateQuote> ParseProviderResponse(XmlDocument providerResponse, Address destination, ref bool isHolidayIssue) { XmlNodeList nlsShipments; string serviceCode; LSDecimal curRate; ProviderShipRateQuote pquote; List <ProviderShipRateQuote> pquotes = new List <ProviderShipRateQuote>(); nlsShipments = providerResponse.DocumentElement.SelectNodes("IntlShipment"); foreach (XmlNode nodeShipment in nlsShipments) { serviceCode = XmlUtility.GetElementValue(nodeShipment, "TransactionTrace", string.Empty); if (string.IsNullOrEmpty(serviceCode)) { serviceCode = XmlUtility.GetElementValue(nodeShipment, "ShipmentDetail/Service/Code", string.Empty); } if (string.IsNullOrEmpty(serviceCode)) { continue; } curRate = AlwaysConvert.ToDecimal(XmlUtility.GetElementValue(nodeShipment, "ShipmentDetail/RateEstimate/TotalChargeEstimate", "0")); if (curRate == 0) { continue; } pquote = new ProviderShipRateQuote(); pquote.Rate = curRate; pquote.PackageCount = 1; pquote.ServiceCode = serviceCode; pquote.ServiceName = GetServiceName(serviceCode); pquotes.Add(pquote); } return(pquotes); }
private List <ProviderShipRateQuote> ParseProviderResponse(XmlDocument providerResponse, Address destination, Package package) { List <ProviderShipRateQuote> providerQuotes = new List <ProviderShipRateQuote>(); string softError = ""; //check for error node XmlElement nodError = XmlUtility.GetElement(providerResponse, "Error", false); if (nodError == null) { //check doc element too nodError = XmlUtility.GetElement(providerResponse.DocumentElement, "Error", false); } if (nodError != null) { //error in rate request string errorCode = XmlUtility.GetElementValue(nodError, "Code", string.Empty); string errorMessage = XmlUtility.GetElementValue(nodError, "Message", "Unknown Error."); throw new ShipProviderException(errorCode + " : " + errorMessage); } else { //check for soft errors XmlElement nodSoftError = XmlUtility.GetElement(providerResponse, "SoftError", false); if (nodSoftError != null) { //soft errors/warnings in rate request softError = XmlUtility.GetElementValue(nodSoftError, "Type"); softError = softError + " : " + XmlUtility.GetElementValue(nodSoftError, "Code"); softError = softError + " : " + XmlUtility.GetElementValue(nodSoftError, "Message"); } //look for services XmlNodeList nlsEntries = providerResponse.DocumentElement.GetElementsByTagName("Entry"); XmlElement nodEntry = null; bool hasGroundHomeDelivery = false; bool hasFedExGround = false; String tempServiceCode; ProviderShipRateQuote quote; foreach (XmlNode nodeItem in nlsEntries) { nodEntry = (XmlElement)nodeItem; tempServiceCode = XmlUtility.GetElementValue(nodEntry, "Service", ""); if (string.IsNullOrEmpty(tempServiceCode)) { continue; } if (tempServiceCode.Equals("GROUNDHOMEDELIVERY")) { hasGroundHomeDelivery = true; } if (tempServiceCode.Equals("FEDEXGROUND")) { hasFedExGround = true; } quote = new ProviderShipRateQuote(); quote.ServiceCode = tempServiceCode; quote.ServiceName = GetServiceName(tempServiceCode); quote.Rate = package.Multiplier * AlwaysConvert.ToDecimal(XmlUtility.GetElementValue(nodEntry, "EstimatedCharges/DiscountedCharges/NetCharge", "0"), 0); quote.PackageCount = 1; if (softError.Length > 0) { quote.AddWarning(softError); } providerQuotes.Add(quote); } //bug 6786 //if a rate for GROUNDHOMEDELIVERY is returned, and it's a US residence, ignore FEDEXGROUND //if a rate for FEDEXGROUND is returned, and it's a US business, ignore GROUNDHOMEDELIVERY if (destination.CountryCode.Equals("US", StringComparison.InvariantCultureIgnoreCase) && hasGroundHomeDelivery && hasFedExGround) { for (int i = providerQuotes.Count - 1; i >= 0; i--) { quote = providerQuotes[i]; if ((destination.Residence && quote.ServiceCode.Equals("FEDEXGROUND")) || (!destination.Residence && quote.ServiceCode.Equals("GROUNDHOMEDELIVERY"))) { providerQuotes.RemoveAt(i); break; } } } nodEntry = null; nlsEntries = null; } return(providerQuotes); }