001: /*
002: * Created on May 26, 2004
003: */
004: package org.openedit.store.shipping;
005:
006: import java.util.HashMap;
007: import java.util.Iterator;
008: import java.util.Map;
009:
010: import org.openedit.money.Money;
011: import org.openedit.store.Cart;
012: import org.openedit.store.CartItem;
013: import org.openedit.store.HandlingCharge;
014: import org.openedit.store.ShippingMethod;
015:
016: /**
017: * @author cburkey
018: *
019: */
020: public abstract class BaseShippingMethod implements ShippingMethod {
021: protected String fieldId = "";
022: protected String fieldDescription = "";
023: protected Map fieldHandlingCharges;
024:
025: protected Money fieldCost = Money.ZERO;
026: protected double fieldPercentageCost = 0.0;
027:
028: // thresholds that indicate when this shipping method can be used
029: protected Money fieldLowerThreshold = Money.ZERO;
030: protected Money fieldUpperThreshold = null;
031:
032: protected boolean fieldHidden;
033:
034: public Money getCost() {
035: return fieldCost;
036: }
037:
038: public void setCost(Money inCost) {
039: fieldCost = inCost;
040: }
041:
042: public Money getLowerThreshold() {
043: return fieldLowerThreshold;
044: }
045:
046: public void setLowerThreshold(Money inLowerThreshold) {
047: fieldLowerThreshold = inLowerThreshold;
048: }
049:
050: public Money getUpperThreshold() {
051: return fieldUpperThreshold;
052: }
053:
054: public void setUpperThreshold(Money inUpperThreshold) {
055: fieldUpperThreshold = inUpperThreshold;
056: }
057:
058: public double getPercentageCost() {
059: return fieldPercentageCost;
060: }
061:
062: public void setPercentageCost(double inPercentageCost) {
063: fieldPercentageCost = inPercentageCost;
064: }
065:
066: public String getDescription() {
067: return fieldDescription;
068: }
069:
070: public void setDescription(String inDescription) {
071: fieldDescription = inDescription;
072: }
073:
074: public String getId() {
075: return fieldId;
076: }
077:
078: public void setId(String inId) {
079: fieldId = inId;
080: }
081:
082: public Map getHandlingCharges() {
083: if (fieldHandlingCharges == null) {
084: fieldHandlingCharges = new HashMap();
085: }
086: return fieldHandlingCharges;
087: }
088:
089: public void setHandlingCharges(Map inHandlingCharges) {
090: fieldHandlingCharges = inHandlingCharges;
091: }
092:
093: public HandlingCharge getHandlingCharge(String inLevel) {
094: return (HandlingCharge) getHandlingCharges().get(inLevel);
095: }
096:
097: public void addHandlingCharge(HandlingCharge inHandlingCharge) {
098: getHandlingCharges().put(inHandlingCharge.getLevel(),
099: inHandlingCharge);
100: }
101:
102: public Money getHandlingCharge(Cart inCart) {
103: Money totalPrice = Money.ZERO;
104: if (!inCart.isEmpty()) {
105: // add in any per-item handling charges
106: for (Iterator it = inCart.getItemIterator(); it.hasNext();) {
107: CartItem item = (CartItem) it.next();
108: String handlingChargeLevel = item.getProduct()
109: .getHandlingChargeLevel();
110: if (handlingChargeLevel != null) {
111: HandlingCharge handlingCharge = getHandlingCharge(handlingChargeLevel);
112: if (handlingCharge != null) {
113: Money handlingCost = handlingCharge.getCost();
114: handlingCost = handlingCost.multiply(item
115: .getQuantity());
116: totalPrice = totalPrice.add(handlingCost);
117: }
118: }
119: }
120: }
121: return totalPrice;
122: }
123:
124: public boolean isHidden() {
125: return fieldHidden;
126: }
127:
128: public void setHidden(boolean inHidden) {
129: fieldHidden = inHidden;
130: }
131:
132: }
|