1 4 package com.openedit.store.shipping; 5 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 import java.util.Map ; 9 10 import org.openedit.money.Money; 11 12 import com.openedit.store.Cart; 13 import com.openedit.store.CartItem; 14 import com.openedit.store.HandlingCharge; 15 import com.openedit.store.ShippingMethod; 16 17 21 public abstract class BaseShippingMethod implements ShippingMethod 22 { 23 protected String fieldId = ""; 24 protected String fieldDescription = ""; 25 protected Map fieldHandlingCharges; 26 27 protected Money fieldCost = Money.ZERO; 28 protected double fieldPercentageCost = 0.0; 29 30 protected Money fieldLowerThreshold = Money.ZERO; 32 protected Money fieldUpperThreshold = null; 33 34 protected boolean fieldHidden; 35 36 public Money getCost() 37 { 38 return fieldCost; 39 } 40 41 public void setCost(Money inCost) { 42 fieldCost = inCost; 43 } 44 public Money getLowerThreshold() 45 { 46 return fieldLowerThreshold; 47 } 48 public void setLowerThreshold(Money inLowerThreshold) 49 { 50 fieldLowerThreshold = inLowerThreshold; 51 } 52 public Money getUpperThreshold() 53 { 54 return fieldUpperThreshold; 55 } 56 public void setUpperThreshold(Money inUpperThreshold) 57 { 58 fieldUpperThreshold = inUpperThreshold; 59 } 60 61 public double getPercentageCost() 62 { 63 return fieldPercentageCost; 64 } 65 66 public void setPercentageCost(double inPercentageCost) 67 { 68 fieldPercentageCost = inPercentageCost; 69 } 70 71 72 73 public String getDescription() { 74 return fieldDescription; 75 } 76 public void setDescription(String inDescription) { 77 fieldDescription = inDescription; 78 } 79 public String getId() { 80 return fieldId; 81 } 82 public void setId(String inId) { 83 fieldId = inId; 84 } 85 public Map getHandlingCharges() 86 { 87 if ( fieldHandlingCharges == null ) 88 { 89 fieldHandlingCharges = new HashMap (); 90 } 91 return fieldHandlingCharges; 92 } 93 94 public void setHandlingCharges(Map inHandlingCharges) 95 { 96 fieldHandlingCharges = inHandlingCharges; 97 } 98 99 public HandlingCharge getHandlingCharge(String inLevel) 100 { 101 return (HandlingCharge)getHandlingCharges().get(inLevel); 102 } 103 104 public void addHandlingCharge(HandlingCharge inHandlingCharge) 105 { 106 getHandlingCharges().put(inHandlingCharge.getLevel(), inHandlingCharge); 107 } 108 public Money getHandlingCharge(Cart inCart) 109 { 110 Money totalPrice = Money.ZERO; 111 if( !inCart.isEmpty() ) 112 { 113 for ( Iterator it = inCart.getItemIterator(); it.hasNext(); ) 115 { 116 CartItem item = (CartItem)it.next(); 117 String handlingChargeLevel = item.getProduct().getHandlingChargeLevel(); 118 if ( handlingChargeLevel != null ) 119 { 120 HandlingCharge handlingCharge = getHandlingCharge( handlingChargeLevel ); 121 if ( handlingCharge != null ) 122 { 123 Money handlingCost = handlingCharge.getCost(); 124 handlingCost = handlingCost.multiply( item.getQuantity() ); 125 totalPrice = totalPrice.add( handlingCost ); 126 } 127 } 128 } 129 } 130 return totalPrice; 131 } 132 133 public boolean isHidden() 134 { 135 return fieldHidden; 136 } 137 138 public void setHidden(boolean inHidden) 139 { 140 fieldHidden = inHidden; 141 } 142 143 } 144 | Popular Tags |