1 4 package com.openedit.store; 5 6 import java.util.Date ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 import org.openedit.money.Money; 11 12 import com.openedit.store.customer.Customer; 13 import com.openedit.store.orders.SubmittedOrder; 14 15 21 public class Order implements Comparable 22 { 23 public final static String ACCEPTED = "accepted"; 24 public final static String AUTHORIZED = "authorized"; 25 public final static String CAPTURED = "captured"; 26 public final static String COMPLETED = "completed"; 27 public final static String REJECTED = "rejected"; 28 29 protected String fieldId; 30 protected Customer fieldCustomer; 31 protected List fieldItems; 32 protected ShippingMethod fieldShippingMethod; 33 protected Money fieldTotalShipping; 34 protected Money fieldTax; 35 protected Money fieldSubTotal; 36 protected Money fieldTotalPrice; 37 38 protected PaymentMethod fieldPaymentMethod; 39 protected Date fieldDate; 40 protected OrderState fieldOrderState; 41 42 public Money getTotalShipping() 43 { 44 return fieldTotalShipping; 45 } 46 public void setTotalShipping(Money inTotalShipping) 47 { 48 fieldTotalShipping = inTotalShipping; 49 } 50 public ShippingMethod getShippingMethod() 51 { 52 return fieldShippingMethod; 53 } 54 public void setShippingMethod(ShippingMethod inShippingMethod) 55 { 56 fieldShippingMethod = inShippingMethod; 57 } 58 public Money getSubTotal() 59 { 60 return fieldSubTotal; 61 } 62 public void setSubTotal(Money inSubtotal) 63 { 64 fieldSubTotal = inSubtotal; 65 } 66 public Money getTax() 67 { 68 return fieldTax; 69 } 70 public void setTax(Money inTax) 71 { 72 fieldTax = inTax; 73 } 74 75 80 public Order() 81 { 82 fieldDate = new Date (); 83 } 84 85 91 public Order( String inId, Date inDate ) 92 { 93 fieldId = inId; 94 fieldDate = inDate; 95 } 96 101 public Date getDate() 102 { 103 return fieldDate; 104 } 105 106 111 public void setDate( Date inDate ) 112 { 113 fieldDate = inDate; 114 } 115 116 121 public String getId() 122 { 123 return fieldId; 124 } 125 public String getOrderNumber() 126 { 127 return getId(); 128 } 129 130 136 public void setId( String inId ) 137 { 138 fieldId = inId; 139 } 140 141 147 public PaymentMethod getPaymentMethod() 148 { 149 if ( fieldPaymentMethod == null ) 150 { 151 fieldPaymentMethod = new CreditPaymentMethod(); 152 } 153 return fieldPaymentMethod; 154 } 155 156 161 public void setPaymentMethod( PaymentMethod inPaymentMethod ) 162 { 163 fieldPaymentMethod = inPaymentMethod; 164 } 165 166 public String toString() 167 { 168 return "Order " + getId() + " on " + getDate() + ":\n" + getPaymentMethod(); 169 } 170 public OrderState getOrderState() { 172 return fieldOrderState; 173 } 174 public void setOrderState(OrderState inOrderState) 175 { 176 fieldOrderState = inOrderState; 177 } 178 public Customer getCustomer() 179 { 180 return fieldCustomer; 181 } 182 public void setCustomer(Customer inCustomer) 183 { 184 fieldCustomer = inCustomer; 185 } 186 public List getItems() 187 { 188 return fieldItems; 189 } 190 public void setItems(List inItems) 191 { 192 fieldItems = inItems; 193 } 194 public Money getTotalPrice() 195 { 196 return fieldTotalPrice; 197 } 198 public void setTotalPrice(Money inTotalPrice) 199 { 200 fieldTotalPrice = inTotalPrice; 201 } 202 203 public int compareTo(Object inOrder) 204 { 205 SubmittedOrder order = (SubmittedOrder)inOrder; 206 return order.getOrderNumber().compareTo(getOrderNumber()); 207 } 208 public int getNumItems() 209 { 210 int numItems = 0; 211 for (Iterator it = getItems().iterator(); it.hasNext();) 212 { 213 CartItem item = (CartItem)it.next(); 214 numItems += item.getQuantity(); 215 } 216 return numItems; 217 } 218 219 220 } | Popular Tags |