From: Roland Haeder Date: Mon, 14 Sep 2015 09:29:26 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=adfc78391d33e4f7d6879a5130d23f44f682980f;p=pizzaservice-war.git Continued: - added total price to basket and index - now item prices are right-origiented - added method calculateTotalPrice() to basket controller - added method getItemAmount() to basket controller - now amount and submit button/link to basket are left-floated, prices are right-floated Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java index 9adcfea5..2fbd7726 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java @@ -150,6 +150,24 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl return totalPrice; } + @Override + public Float calculateTotalPrice () { + // Init total price + Float totalPrice = 0.0f; + + // Iterate over all items + for (final AddableBasketItem item : this.allItems()) { + // Is the item a product? + if (item.isProductType()) { + // Calculate single price and add it + totalPrice += this.calculateItemPrice(item); + } + } + + // Return final sum + return totalPrice; + } + @Override public Long getAmount () { return this.amount; @@ -170,6 +188,25 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl this.currentItem = currentItem; } + @Override + public Long getItemAmount (final Product product) { + // Initial value is zero + Long itemAmount = 0L; + + // Iterate over all + for (final AddableBasketItem item : this.allItems()) { + // Is this product instance and same? + if ((item.isProductType()) && (item.getProduct().equals(product))) { + // Found it + itemAmount = item.getAmount(); + break; + } + } + + // Return it + return itemAmount; + } + @Override public AddableBasketItem getLast () { // Deligate to basket instance diff --git a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java index 2f6c212e..8d28a946 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java +++ b/src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java @@ -104,6 +104,13 @@ public interface BasketWebController extends Serializable { */ public Float calculateItemPrice (final AddableBasketItem item); + /** + * Calculates total sum (no tax added) for all items + * + * @return Total price of all items + */ + public Float calculateTotalPrice (); + /** * Getter for last entry * @@ -124,4 +131,14 @@ public interface BasketWebController extends Serializable { * @return A list of all added items */ public List allItems (); + + /** + * Some getter for item amount of given product. This method requires a full + * iteration over all items in the basket to look for proper product + * instance. + * + * @param product Product instance + * @return Item amount of given product + */ + public Long getItemAmount (final Product product); } diff --git a/web/basket.xhtml b/web/basket.xhtml index ffe36a04..845e9be6 100644 --- a/web/basket.xhtml +++ b/web/basket.xhtml @@ -29,11 +29,13 @@ Einzelpreis: - - - - - +
+ + + + + +
@@ -54,12 +56,21 @@ Zwischensumme: - - - +
+ + + +
+
+ Gesamtsumme: + + + +
+ diff --git a/web/index.xhtml b/web/index.xhtml index 4c3d08db..f682c0ea 100644 --- a/web/index.xhtml +++ b/web/index.xhtml @@ -36,51 +36,65 @@
-
- - - - - - - - - - - - -
- #{basketController.amount} -
- - - -
-
-
+
+
+ + + + + + + + + + + + +
+ Anzahl: + #{basketController.getItemAmount(product)} +
+ + -
- Einzelpreis: - - - +
+ +
-
- Zwischensumme: - - - - +
+
+ Einzelpreis: + + + +
+ +
+ Zwischensumme: + + + + +
+ +
+ +
+ Gesamtsumme: + + + +
diff --git a/web/resources/css/cssLayout.css b/web/resources/css/cssLayout.css index ed37fb5a..321cf646 100644 --- a/web/resources/css/cssLayout.css +++ b/web/resources/css/cssLayout.css @@ -154,6 +154,6 @@ ul.footer_nav li.footer_copyright { width: 100px; } -.price { +.item_price, .item_total_price { text-align: right; }