Exemplo n.º 1
0
 private int getAmountForItem(String name, int orderQuantity) {
   int itemTotal = 0;
   ProductPrice productPrice = priceRuleDao.findPriceFor(name);
   if (productPrice == null) {
     throw new ProductUndefinedException();
   }
   if (productPrice.getSpecialPriceQty() > 0) {
     int amountAtSpecialPrice =
         (orderQuantity / productPrice.getSpecialPriceQty()) * productPrice.getSpecialPrice();
     int amountAtRegularPrice =
         (orderQuantity % productPrice.getSpecialPriceQty()) * productPrice.getPrice();
     itemTotal = amountAtSpecialPrice + amountAtRegularPrice;
   } else {
     itemTotal = orderQuantity * productPrice.getPrice();
   }
   return itemTotal;
 }
Exemplo n.º 2
0
 /**
  * @param product item/product name
  * @param price item/product price
  * @param specialPriceQuantity Quantity at special price applicable - if zero, then not applicable
  * @param specialPrice Special price overrides the per unit price
  */
 @Override
 public void addPriceRule(String product, int price, int specialPriceQuantity, int specialPrice) {
   priceRuleDao.addProductPrice(product, price, specialPriceQuantity, specialPrice);
 }