Advertisement
Guest User

cartMb

a guest
Dec 18th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1.   public void addToBasket (model_D.Product product)
  2.     {
  3.       if(quantity >0)
  4.       {
  5.         if(basket.containsKey(product.getReference()))
  6.         {
  7.               int quantityUpdate = basket.get(product.getReference()).getQuantity();
  8.               quantityUpdate++;
  9.               basket.get(product.getReference()).setQuantity((short)quantityUpdate);
  10.               double priceUpdate = basket.get(product.getReference()).getPrice().doubleValue();
  11.               priceUpdate += basket.get(product.getReference()).getProductRef().getPrice().doubleValue();
  12.               BigDecimal price = new BigDecimal(priceUpdate);
  13.               basket.get(product.getReference()).setPrice(price.setScale(2, BigDecimal.ROUND_CEILING));
  14.               totalPrice = this.calculePrice();
  15.  
  16.          }
  17.         else
  18.         {
  19.          Double p = product.getPrice().doubleValue() * quantity;
  20.          BigDecimal price = new BigDecimal(p);
  21.          model_D.Line line = new model_D.Line();
  22.  
  23.          line.setProductRef(product);
  24.          line.setQuantity((short)quantity);
  25.          line.setPrice(price.setScale(2, BigDecimal.ROUND_CEILING));
  26.          basket.put(product.getReference(), line);
  27.              totalPrice = this.calculePrice();
  28.           }
  29.          quantity = 1;
  30.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement