1 package com.ibatis.jpetstore.domain; 2 3 import java.io.Serializable ; 4 import java.math.BigDecimal ; 5 6 7 public class CartItem implements Serializable { 8 9 10 11 private Item item; 12 private int quantity; 13 private boolean inStock; 14 private BigDecimal total; 15 16 17 18 public boolean isInStock() { 19 return inStock; 20 } 21 22 public void setInStock(boolean inStock) { 23 this.inStock = inStock; 24 } 25 26 public BigDecimal getTotal() { 27 return total; 28 } 29 30 public Item getItem() { 31 return item; 32 } 33 34 public void setItem(Item item) { 35 this.item = item; 36 calculateTotal(); 37 } 38 39 public int getQuantity() { 40 return quantity; 41 } 42 43 public void setQuantity(int quantity) { 44 this.quantity = quantity; 45 calculateTotal(); 46 } 47 48 49 50 public void incrementQuantity() { 51 quantity++; 52 calculateTotal(); 53 } 54 55 56 57 private void calculateTotal() { 58 if (item != null && item.getListPrice() != null) { 59 total = item.getListPrice().multiply(new BigDecimal (quantity)); 60 } else { 61 total = null; 62 } 63 } 64 65 } 66 | Popular Tags |