public double getActualPrice(int amountinBasket) { double actualPrice = price; if (discount != null && !discount.getIsPartOfComplex()) { actualPrice = price * (1 - discount.getPercentage()); } if (sameProductDiscount != null && !sameProductDiscount.getIsPartOfComplex()) { if (sameProductDiscount.getMinNumOfProducts() <= amountinBasket) { actualPrice = price * (1 - sameProductDiscount.getPercentage()); } } if (sameProductDiscount != null && sameProductDiscount.getIsPartOfComplex() && sameProductDiscount.getComplexCondition()) { if (sameProductDiscount.getMinNumOfProducts() <= amountinBasket) { actualPrice = price * (1 - sameProductDiscount.getPercentage()); } } if (discount != null && discount.getIsPartOfComplex() && discount.getComplexCondition()) { actualPrice = price * (1 - discount.getPercentage()); } return(actualPrice); }
public double getActualTotalPrice() { productsActualPrice = new Dictionary <Product, double>(); fillActualPriceDic(); double sum = 0; LinkedList <DiscountComponent> discounts = store.getDiscounts(); foreach (DiscountComponent dis in discounts) { if (dis is DiscountComposite) { if (dis.checkCondition(productList, productsActualPrice) && dis.checkDate()) { dis.setComplexCondition(true, productList, productsActualPrice); } else { if (!dis.checkDate()) { // discount is invalid - date has passed store.removeDiscount(dis.getId()); } dis.setComplexCondition(false, productList, productsActualPrice); } } } foreach (KeyValuePair <Product, int> entry in productList) { Product p = entry.Key; double actualPrice = p.getActualPrice(entry.Value); sum += (entry.Value * actualPrice); } foreach (DiscountComponent dis in discounts) { if (dis is ReliantDiscount) { ReliantDiscount r = (ReliantDiscount)dis; if (!r.getIsPartOfComplex()) { if (r.isTotalAmountDiscount() && sum >= r.getTotalAmount()) { sum = sum * (1 - r.getPercentage()); } } } } foreach (DiscountComponent dis in discounts) { if (dis is VisibleDiscount) { VisibleDiscount v = (VisibleDiscount)dis; if (!v.getIsPartOfComplex() && v.isStoreVisibleDiscount()) { if (v.isStoreVisibleDiscount()) { sum = sum * (1 - v.getPercentage()); } } } } return(sum); }