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