01: package com.odal.petstore.domain;
02:
03: import java.io.Serializable;
04: import java.math.BigDecimal;
05:
06: /**
07: * @author Gennady Krizhevsky
08: */
09: public class CartItem implements Serializable {
10:
11: private Item item;
12: private int quantity;
13: private boolean inStock;
14: private BigDecimal total;
15:
16: public boolean isInStock() {
17: return inStock;
18: }
19:
20: public void setInStock(boolean inStock) {
21: this .inStock = inStock;
22: }
23:
24: public BigDecimal getTotal() {
25: return total;
26: }
27:
28: public Item getItem() {
29: return item;
30: }
31:
32: public void setItem(Item item) {
33: this .item = item;
34: calculateTotal();
35: }
36:
37: public int getQuantity() {
38: return quantity;
39: }
40:
41: public void setQuantity(int quantity) {
42: this .quantity = quantity;
43: calculateTotal();
44: }
45:
46: public void incrementQuantity() {
47: quantity++;
48: calculateTotal();
49: }
50:
51: private void calculateTotal() {
52: if (item != null && item.getListPrice() != null) {
53: total = item.getListPrice().multiply(
54: new BigDecimal(quantity));
55: } else {
56: total = null;
57: }
58: }
59:
60: }
|