1 package com.ibatis.jpetstore.domain; 2 3 import java.io.Serializable ; 4 import java.math.BigDecimal ; 5 6 7 public class LineItem implements Serializable { 8 9 10 11 private int orderId; 12 private int lineNumber; 13 private int quantity; 14 private String itemId; 15 private BigDecimal unitPrice; 16 private Item item; 17 private BigDecimal total; 18 19 20 21 public LineItem() { 22 } 23 24 public LineItem(int lineNumber, CartItem cartItem) { 25 this.lineNumber = lineNumber; 26 this.quantity = cartItem.getQuantity(); 27 this.itemId = cartItem.getItem().getItemId(); 28 this.unitPrice = cartItem.getItem().getListPrice(); 29 this.item = cartItem.getItem(); 30 } 31 32 33 34 public int getOrderId() { 35 return orderId; 36 } 37 38 public void setOrderId(int orderId) { 39 this.orderId = orderId; 40 } 41 42 public int getLineNumber() { 43 return lineNumber; 44 } 45 46 public void setLineNumber(int lineNumber) { 47 this.lineNumber = lineNumber; 48 } 49 50 public String getItemId() { 51 return itemId; 52 } 53 54 public void setItemId(String itemId) { 55 this.itemId = itemId; 56 } 57 58 public BigDecimal getUnitPrice() { 59 return unitPrice; 60 } 61 62 public void setUnitPrice(BigDecimal unitprice) { 63 this.unitPrice = unitprice; 64 } 65 66 public BigDecimal getTotal() { 67 return total; 68 } 69 70 public Item getItem() { 71 return item; 72 } 73 74 public void setItem(Item item) { 75 this.item = item; 76 calculateTotal(); 77 } 78 79 public int getQuantity() { 80 return quantity; 81 } 82 83 public void setQuantity(int quantity) { 84 this.quantity = quantity; 85 calculateTotal(); 86 } 87 88 89 90 private void calculateTotal() { 91 if (item != null && item.getListPrice() != null) { 92 total = item.getListPrice().multiply(new BigDecimal (quantity)); 93 } else { 94 total = null; 95 } 96 } 97 98 99 } 100 | Popular Tags |