1 25 package org.ofbiz.order.shoppingcart.shipping; 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Map ; 31 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.entity.GenericDelegator; 34 import org.ofbiz.entity.GenericValue; 35 import org.ofbiz.order.shoppingcart.ShoppingCart; 36 import org.ofbiz.product.store.ProductStoreWorker; 37 import org.ofbiz.service.LocalDispatcher; 38 39 45 public class ShippingEstimateWrapper { 46 47 public static final String module = ShippingEstimateWrapper.class.getName(); 48 49 protected GenericDelegator delegator = null; 50 protected LocalDispatcher dispatcher = null; 51 52 protected Map shippingEstimates = null; 53 protected List shippingMethods = null; 54 55 protected GenericValue shippingAddress = null; 56 protected Map shippableItemFeatures = null; 57 protected List shippableItemSizes = null; 58 protected List shippableItemInfo = null; 59 protected String productStoreId = null; 60 protected double shippableQuantity = 0; 61 protected double shippableWeight = 0; 62 protected double shippableTotal = 0; 63 64 public static ShippingEstimateWrapper getWrapper(LocalDispatcher dispatcher, ShoppingCart cart, int shipGroup) { 65 return new ShippingEstimateWrapper(dispatcher, cart, shipGroup); 66 } 67 68 public ShippingEstimateWrapper(LocalDispatcher dispatcher, ShoppingCart cart, int shipGroup) { 69 this.dispatcher = dispatcher; 70 this.delegator = cart.getDelegator(); 71 72 this.shippableItemFeatures = cart.getFeatureIdQtyMap(shipGroup); 73 this.shippableItemSizes = cart.getShippableSizes(shipGroup); 74 this.shippableItemInfo = cart.getShippableItemInfo(shipGroup); 75 this.shippableQuantity = cart.getShippableQuantity(shipGroup); 76 this.shippableWeight = cart.getShippableWeight(shipGroup); 77 this.shippableTotal = cart.getShippableTotal(shipGroup); 78 this.shippingAddress = cart.getShippingAddress(shipGroup); 79 this.productStoreId = cart.getProductStoreId(); 80 81 this.loadShippingMethods(); 82 this.loadEstimates(); 83 } 84 85 protected void loadShippingMethods() { 86 try { 87 this.shippingMethods = ProductStoreWorker.getAvailableStoreShippingMethods(delegator, productStoreId, 88 shippingAddress, shippableItemSizes, shippableItemFeatures, shippableWeight, shippableTotal); 89 } catch (Throwable t) { 90 Debug.logError(t, module); 91 } 92 } 93 94 protected void loadEstimates() { 95 this.shippingEstimates = new HashMap (); 96 if (shippingMethods != null) { 97 Iterator i = shippingMethods.iterator(); 98 while (i.hasNext()) { 99 GenericValue shipMethod = (GenericValue) i.next(); 100 String shippingMethodTypeId = shipMethod.getString("shipmentMethodTypeId"); 101 String carrierRoleTypeId = shipMethod.getString("roleTypeId"); 102 String carrierPartyId = shipMethod.getString("partyId"); 103 String shippingCmId = shippingAddress != null ? shippingAddress.getString("contactMechId") : null; 104 105 Map estimateMap = ShippingEvents.getShipGroupEstimate(dispatcher, delegator, "SALES_ORDER", 106 shippingMethodTypeId, carrierPartyId, carrierRoleTypeId, shippingCmId, productStoreId, 107 shippableItemInfo, shippableWeight, shippableQuantity, shippableTotal); 108 109 Double shippingTotal = (Double ) estimateMap.get("shippingTotal"); 110 shippingEstimates.put(shipMethod, shippingTotal); 111 } 112 } 113 } 114 115 public List getShippingMethods() { 116 return shippingMethods; 117 } 118 119 public Map getAllEstimates() { 120 return shippingEstimates; 121 } 122 123 public Double getShippingEstimate(GenericValue storeCarrierShipMethod) { 124 return (Double ) shippingEstimates.get(storeCarrierShipMethod); 125 } 126 127 } 128 | Popular Tags |