Author: sichen
Date: Mon Mar 5 09:50:49 2007 New Revision: 514748 URL: http://svn.apache.org/viewvc?view=rev&rev=514748 Log: Passing a list of package weights to UPS rate inquire services will override the splitting of packages and calculation of package weights via shippableItemInfo Modified: ofbiz/trunk/applications/product/servicedef/services_shipment_ups.xml ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java Modified: ofbiz/trunk/applications/product/servicedef/services_shipment_ups.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_shipment_ups.xml?view=diff&rev=514748&r1=514747&r2=514748 ============================================================================== --- ofbiz/trunk/applications/product/servicedef/services_shipment_ups.xml (original) +++ ofbiz/trunk/applications/product/servicedef/services_shipment_ups.xml Mon Mar 5 09:50:49 2007 @@ -31,6 +31,8 @@ will return a Map of serviceCode -> rate</description> <implements service="calcShipmentEstimateInterface"/> <attribute name="upsRateInquireMode" type="String" mode="IN" optional="true"/> + <!-- Passing in a list of package weights will override the splitting of packages and calculation of package weights by item --> + <attribute name="packageWeights" type="List" mode="IN" optional="true"/> <attribute name="upsRateCodeMap" type="Map" mode="OUT" optional="false"/> </service> @@ -68,6 +70,8 @@ <attribute name="carrierPartyId" type="String" mode="IN" optional="false"/> <attribute name="carrierRoleTypeId" type="String" mode="IN" optional="false"/> <attribute name="productStoreId" type="String" mode="IN" optional="false"/> + <!-- Passing in a list of package weights will override the splitting of packages and calculation of package weights by item --> + <attribute name="packageWeights" type="List" mode="IN" optional="true"/> <attribute name="shippableItemInfo" type="List" mode="IN" optional="false"/> <attribute name="shippableWeight" type="Double" mode="IN" optional="false"/> <attribute name="shippableQuantity" type="Double" mode="IN" optional="false"/> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java?view=diff&rev=514748&r1=514747&r2=514748 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/ups/UpsServices.java Mon Mar 5 09:50:49 2007 @@ -1348,6 +1348,7 @@ String shipmentMethodTypeId = (String) context.get("shipmentMethodTypeId"); String shippingContactMechId = (String) context.get("shippingContactMechId"); + List packageWeights = (List) context.get("packageWeights"); List shippableItemInfo = (List) context.get("shippableItemInfo"); Double shippableTotal = (Double) context.get("shippableTotal"); Double shippableQuantity = (Double) context.get("shippableQuantity"); @@ -1481,7 +1482,16 @@ maxWeight = 99; } - splitEstimatePackages(rateRequestDoc, shipmentElement, shippableItemInfo, maxWeight); + // Passing in a list of package weights overrides the calculation of same via shippableItemInfo + if (UtilValidate.isEmpty(packageWeights)) { + splitEstimatePackages(rateRequestDoc, shipmentElement, shippableItemInfo, maxWeight); + } else { + Iterator i = packageWeights.iterator(); + while (i.hasNext()) { + Double packageWeight = (Double) i.next(); + addPackageElement(rateRequestDoc, shipmentElement, packageWeight.doubleValue()); + } + } // service options UtilXml.addChildElement(shipmentElement, "ShipmentServiceOptions", rateRequestDoc); @@ -1547,18 +1557,20 @@ Iterator i = packages.iterator(); while (i.hasNext()) { Map packageMap = (Map) i.next(); - double packageWeight = calcPackageWeight(packageMap, shippableItemInfo, 0); - - // package info - Element packageElement = UtilXml.addChildElement(shipmentElement, "Package", requestDoc); - Element packagingTypeElement = UtilXml.addChildElement(packageElement, "PackagingType", requestDoc); - UtilXml.addChildElementValue(packagingTypeElement, "Code", "00", requestDoc); - UtilXml.addChildElementValue(packagingTypeElement, "Description", "Unknown PackagingType", requestDoc); - UtilXml.addChildElementValue(packageElement, "Description", "Package Description", requestDoc); - Element packageWeightElement = UtilXml.addChildElement(packageElement, "PackageWeight", requestDoc); - UtilXml.addChildElementValue(packageWeightElement, "Weight", Double.toString(packageWeight), requestDoc); + double packageWeight = calcPackageWeight(packageMap, shippableItemInfo, 0); + addPackageElement(requestDoc, shipmentElement, packageWeight); } } + + private static void addPackageElement(Document requestDoc, Element shipmentElement, double packageWeight) { + Element packageElement = UtilXml.addChildElement(shipmentElement, "Package", requestDoc); + Element packagingTypeElement = UtilXml.addChildElement(packageElement, "PackagingType", requestDoc); + UtilXml.addChildElementValue(packagingTypeElement, "Code", "00", requestDoc); + UtilXml.addChildElementValue(packagingTypeElement, "Description", "Unknown PackagingType", requestDoc); + UtilXml.addChildElementValue(packageElement, "Description", "Package Description", requestDoc); + Element packageWeightElement = UtilXml.addChildElement(packageElement, "PackageWeight", requestDoc); + UtilXml.addChildElementValue(packageWeightElement, "Weight", Double.toString(packageWeight), requestDoc); + } private static List getPackageSplit(List shippableItemInfo, double maxWeight) { // create the package list w/ the first pacakge @@ -1844,6 +1856,7 @@ // String shippingContactMechId = (String) context.get("shippingContactMechId"); String shippingPostalCode = (String) context.get("shippingPostalCode"); String shippingCountryCode = (String) context.get("shippingCountryCode"); + List packageWeights = (List) context.get("packageWeights"); List shippableItemInfo = (List) context.get("shippableItemInfo"); Double shippableTotal = (Double) context.get("shippableTotal"); Double shippableQuantity = (Double) context.get("shippableQuantity"); @@ -1985,7 +1998,16 @@ maxWeight = 99; } - splitEstimatePackages(rateRequestDoc, shipmentElement, shippableItemInfo, maxWeight); + // Passing in a list of package weights overrides the calculation of same via shippableItemInfo + if (UtilValidate.isEmpty(packageWeights)) { + splitEstimatePackages(rateRequestDoc, shipmentElement, shippableItemInfo, maxWeight); + } else { + Iterator i = packageWeights.iterator(); + while (i.hasNext()) { + Double packageWeight = (Double) i.next(); + addPackageElement(rateRequestDoc, shipmentElement, packageWeight.doubleValue()); + } + } // service options UtilXml.addChildElement(shipmentElement, "ShipmentServiceOptions", rateRequestDoc); |
Free forum by Nabble | Edit this page |