Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/io/shodo/BasketInformations.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,31 @@ public class BasketInformations {
// The product of the basket
static HashMap<String, Integer> map = new HashMap<String, Integer>();

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) {
Integer v = 0;
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() {
Expand Down