From adfc78391d33e4f7d6879a5130d23f44f682980f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 14 Sep 2015 11:29:26 +0200 Subject: [PATCH] =?utf8?q?Continued:=20-=20added=20total=20price=20to=20ba?= =?utf8?q?sket=20and=20index=20-=20now=20item=20prices=20are=20right-origi?= =?utf8?q?ented=20-=20added=20method=20calculateTotalPrice()=20to=20basket?= =?utf8?q?=20controller=20-=20added=20method=20getItemAmount()=20to=20bask?= =?utf8?q?et=20controller=20-=20now=20amount=20and=20submit=20button/link?= =?utf8?q?=20to=20basket=20are=20left-floated,=20prices=20are=20right-floa?= =?utf8?q?ted=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../beans/basket/BasketWebBean.java | 37 ++++++++ .../beans/basket/BasketWebController.java | 17 ++++ web/basket.xhtml | 27 ++++-- web/index.xhtml | 88 +++++++++++-------- web/resources/css/cssLayout.css | 2 +- 5 files changed, 125 insertions(+), 46 deletions(-) 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; } -- 2.39.5