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