diff --git a/src/main/java/io/shodo/BasketInformations.java b/src/main/java/io/shodo/BasketInformations.java index 7224ba9..8283d40 100644 --- a/src/main/java/io/shodo/BasketInformations.java +++ b/src/main/java/io/shodo/BasketInformations.java @@ -11,8 +11,15 @@ public class BasketInformations { // The product of the basket static HashMap map = new HashMap(); - public void addProductToBasket(String product, Integer price) { + // The fact that the basket has promo code + private static boolean codeDePromotion = false; + + public void addProductToBasket(String product, Integer price, boolean isPromoCode) { + if (isPromoCode) { + codeDePromotion = true; + } else { map.put(product, price); + } } public Long getBasketPrice(boolean inCents) { @@ -20,11 +27,15 @@ public Long getBasketPrice(boolean inCents) { for (String s : map.keySet()) { v += map.get(s); } + if (codeDePromotion) { + v -= 100; + } return inCents ? v * 100 : Long.valueOf(v); } public void resetBasket() { buyBasket(); + codeDePromotion = false; } public void buyBasket() {